docsapi referencedarkforest-core-tensor-tensor
API Referencecrate: darkforest-coresince v0.1.0-alpha

Tensor

The core multi-dimensional strided tensor representation in Dark Forest. Employs a 64-byte aligned lock-free storage backing with atomic mutation version counters.

Tensor

darkforest-core module: tensor since v0.1.0-alpha

Signature

rust
pub struct Tensor<T: Element, D: Device> { storage: Arc<Storage<T, D>>, offset: usize, shape: Shape, strides: Strides, version: AtomicU64 }

Overview

The core multi-dimensional strided tensor representation in Dark Forest. Employs a 64-byte aligned lock-free storage backing with atomic mutation version counters.

Invariants & Design Principles

  • Invariant: Storage is 64-byte aligned for AVX-512 and CUDA unified memory compatibility.
  • Invariant: Strides are signed isize integers allowing negative-stride zero-copy reverse slicing.
  • Invariant: Any in-place mutation increments the internal AtomicU64 version, automatically invalidating stale autograd views.
  • Invariant: Slicing, transposing, and reshaping never copy underlying buffer memory.

Usage Example

rust
let t = Tensor::<f32, Cpu>::zeros(&[2048, 2048]);
assert_eq!(t.shape().as_slice(), &[2048, 2048]);

Related Components