3 ms·
> as_strided is trickier to explain. It allows users to reinterpet input tensors by specifying custom sizes, strides and offsets for the dimensions of the outpu
by Noumenon72 5y ago
> as_strided is trickier to explain. It allows users to reinterpet input tensors by specifying custom sizes, strides and offsets for the dimensions of the output.
This doesn't work as an explanation without defining what a "stride" is. You can't explain addition just by showing some examples of "before addition" and "after addition".
Here's what I found at https://ipython-books.github.io/46-using-stride-tricks-with-numpy/ https://ipython-books.github.io/46-using-stride-tricks-with-...:
> Strides describe, in any dimension, how many bytes we need to jump over in the data buffer to go from one item to the next.
So the stride in a 1-D array of float64 is 8 because you need to go 8 bytes forward to go from one item to the next. Change it to 32 and you have a way to access every fourth item without defining a new array.
- brrrrrm 5y agothanks for adding this context! One caveat is that the PyTorch strides used in the post are defined by elements rather than byte-wise.