geauxeric
geauxeric
MModular
Created by geauxeric on 5/5/2024 in #questions
Return with move semantics
thanks! this works:
struct Value[dtype: DType]:
alias TensorD = Tensor[dtype]
var data: Self.TensorD

fn __init__(inout self):
self.data = Self.TensorD()

fn __moveinit__(inout self, owned existing: Self):
self.data = existing.data

fn foo(self) -> Self:
var v = Self()
return v^


fn main():
alias FValue = Value[DType.float16]
var v1 = FValue()
var v2 = FValue()
var v3 = v1.foo()
struct Value[dtype: DType]:
alias TensorD = Tensor[dtype]
var data: Self.TensorD

fn __init__(inout self):
self.data = Self.TensorD()

fn __moveinit__(inout self, owned existing: Self):
self.data = existing.data

fn foo(self) -> Self:
var v = Self()
return v^


fn main():
alias FValue = Value[DType.float16]
var v1 = FValue()
var v2 = FValue()
var v3 = v1.foo()
For now I kind of want to avoid using @value as I am still exploring the data model and not sure about their lifetimes.
3 replies