docscore conceptsconcept-tensors-and-strides
Core Concepts

Concepts: Tensors & Strides

In-depth explanation of strided multi-dimensional arrays, signed strides, and memory layouts.

Concepts: Tensors & Strides

In-depth explanation of strided multi-dimensional arrays, signed strides, and memory layouts.

Strided Memory Model

A tensor in Dark Forest consists of:

  1. An underlying flat buffer in memory (Storage<T, D>).
  2. An integer byte offset.
  3. A shape vector [d_0, d_1, ..., d_(n-1)].
  4. A strides vector [s_0, s_1, ..., s_(n-1)].

The memory address for element index (i_0, i_1, ..., i_(n-1)) is computed as:

text
address = offset + sum(i_k * stride_k for k in 0..n-1)