ModularM
Modular2y ago
3 replies
Mohamed Mabrouk

In-place replacement of struct fields

Hey all, I was wondering if someone has a away of changing the underlying data of a tensor in a struct at run time.
struct IOStream
var source: Tensor
fn __init__(inout self):
self.source = Tensor[DType.int8](100)

fn _resize(inout self):
  self.source = Tensor[DType.int8](50) # fails as self.source is static

Can you instead change the pointer of the underlying data of self.sourceto another pointer, doing in place change of the tensor? similar to rust's mem::replace
Edit1: Intrestingly the error does not appear with mojo run but when the binary is build with mojo build and then ./path/to/binary
Was this page helpful?