A tensor’s stride describes how far to move through storage when an index increases by one along each dimension. Together with shape and storage offset, it determines how the tensor indexes its underlying data. section 3.9 section 3.9.1
Reading a two-dimensional stride
For points.stride() == (2, 1), moving to the next row skips two storage elements, while moving to the next column skips one. Element [i, j] is found at storage_offset + stride[0] * i + stride[1] * j. section 3.9.1
Stride makes several tensor behaviors easier to understand:
- Views, subtensors, and transposes can reuse existing storage by changing shape, offset, or stride instead of copying data. section 3.9.1 section 3.9.2
- Indexing a subtensor can change its offset and dimensionality while preserving the link to the original tensor. section 3.9.1
- A transposed tensor reverses the stride ordering: points uses (2, 1), while points_t uses (1, 2). section 3.9.2
- Noncontiguous tensors may need contiguous() before operations such as view; contiguous() creates rearranged storage with a new stride. section 3.9.4
Reshaping hourly data
A tensor shaped [17520, 17] with stride (17, 1) can be viewed as daily_bikes with shape [730, 24, 17] and stride (408, 17, 1). Transposing its hour and feature dimensions changes the stride to (408, 1, 17) without copying storage. section 4.4.2
Figure 3.5 Relationship between a tensor’s offset, size, and stride. Here, the tensor is a view of a larger storage, like one that might have been allocated when creating a larger tensor.
Use the storage diagram to connect shape, storage offset, and per-dimension stride in a tensor view. section 3.9







