Assigning slice of a tensor to a variable?
As best I can tell there is no direct way to assign a slice of a tensor to a new variable. I am looking for something Python-esque like
But even the official docs show
for
loops iterating over a Tensor to populate a new array. Is there a better way to achieve this? It becomes more of an issue with a larger Tensor where I want to assign multiple variables to different slices.4 Replies
We haven't implemented slicing in Mojo Tensors yet like you can with a String for example:
Could you raise a feature request for that?
https://github.com/modularml/mojo/issues/new/choose
Also we're talking about what we're going to do with
Tensor
at the moment, there are some performance issues just so you're aware.Will do, thanks
In the meantime how would you suggest getting slices for multiple variables? Something like
Yeah say if you wanted your original slice you could do:
ND slicing is hard, it was one of the things I could not get quite right when I was trying to make an ND-Array type from scratch unless I manually built overloads for the getting and setting dunder methods for the struct for each possible dim of the array. This is why numpy had (and maybe still has) a max number of dimensions.