Open StenSipma opened 2 years ago
So, the .Coord()
method is meant to be read before use. The docs do mention that .Coord()
returns the next coordinate. This is because an Iterator
is a data structure that stores the state. So when you call Next
or Start
you are changing the state.
I know this is really not ideal. We would love some ideas on how to make this more user friendly. One idea that I had earlier in the design was to not only return the i
but also the coords. But it turns out for most activities you only need the index.
So, the .Coord() method is meant to be read before use. The docs do mention that .Coord() returns the next coordinate. This is because an Iterator is a data structure that stores the state. So when you call Next or Start you are changing the state.
Ah okay, that is interesting. I guess I must have missed this part of the documentation. Maybe it would be good to then change the example of how to use Iterator (example) to something that is intended?
I know this is really not ideal. We would love some ideas on how to make this more user friendly. One idea that I had earlier in the design was to not only return the i but also the coords. But it turns out for most activities you only need the index.
Perhaps an easy solution would be to add a method which converts the index i
to a coordinate instead? Then it would be more an opt-in feature and doesn't hurt those that do not need it. Of course, it is possible to compute this yourself using the Shape
but this would be a lot more convenient.
Having some fix for this would be incredibly useful!
Whilst working with the
tensor.Iterator
functionality I found some strange behavior, when using iterator in a for loop like follows:The same thing happens with 'scalar-like' tensors, like: [1] with shape (1, 1, 1):
Interestingly, when the tensor is a vector/scalar
View
of a tensor that is not a vector/scalar (i.e. obtained by slicing), the issue does not happen.What I found to work properly is to use the following for loop instead, but I don't think this is the intended way of iterating.