mojo
mojo copied to clipboard
[BUG] Tensor Usage in Tuple triggers Invalid Call to `get`.
Bug description
Tensor is a Register Passable Type, but the compiler complains when a tensor is specified in the tuple getter.
Steps to reproduce
If we check with a simple function, we can see that Tensor is a Register Passable type, but it fails when is used in the getter.
from tensor import Tensor
alias F32Tensor = Tensor[DType.float32]
fn reg_type_check[T: AnyRegType]():
print("Good!")
fn build_tuple() -> Tuple[F32Tensor, F32Tensor]:
return F32Tensor(), F32Tensor()
fn main():
reg_type_check[F32Tensor]()
var tensors = build_tuple()
var tensor_1 = tensors.get[0, F32Tensor]()
We can see that the compiler didn't complain on the usage when providing the type to reg_type_check function. But later on, it says:
/source/prog.mojo:16:45: error: invalid call to 'get': result cannot bind AnyRegType type to memory-only type 'Tensor[f32]'
var tensor_1 = tensors.get[0, F32Tensor]()
~~~~~~~~~~~~~~~~~~~~~~~~~^~
/source/prog.mojo:1:1: note: function declared here
from tensor import Tensor
^
mojo: error: failed to parse the provided Mojo
System information
I'm using Mojo Playground
Hi
I am currently reviewing this issue. I anticipate that @register_passable
would be written above the line where struct Tensor
is declared. I would like to attempt to resolve the issue by removing this tag, but I cannot find the code where Tensor
is defined within the project.
Where is the Tensor
defined? If it is in an external project, please share the information.
Thank you.
Hi @dayeondev , this is not a custom Implementation, this is from Mojo Standard Library
@sibarras I understand that the Tensor is treated as part of the stdlib according to the documentation at https://docs.modular.com/mojo/stdlib/tensor/tensor. However, it appears that the Tensor implementation is not under the stdlib path in this repository. If you could guide me to where the Tensor implementation can be found, it would be helpful in resolving this issue.
Hi @JoeLoser, could you please provide your insights on this comment?