getStride

abstract fun getStride(): IntArray(source)

Returns the stride pattern for efficient memory access.

Strides define the number of elements to skip in memory when moving one position along each dimension. This information is crucial for:

  • Optimizing nested loop access patterns

  • Implementing efficient iteration algorithms

  • Cache-aware memory access strategies

  • Vectorization opportunity detection

Stride Calculation

For a view with shape d0, d1, d2, ..., the stride array contains:

  • stride0: elements to skip when incrementing dimension 0 by 1

  • stride1: elements to skip when incrementing dimension 1 by 1

  • stride2: elements to skip when incrementing dimension 2 by 1

  • ...

Memory Layout Considerations

Strides must account for the parent tensor's memory layout:

  • Row-major (C-style): rightmost dimension has stride 1

  • NCHW layout: strides typically C×H×W, H×W, W, 1

  • Slicing effects: non-unit steps multiply base strides

Return

array of stride values for each dimension, matching view dimensionality