core/tensor/tensor library
Device-aware Tensor with a CPU (Float32List) or GPU (FFI handle)
backing, plus a Dart-side reverse-mode autograd tape.
Exactly one of _cpuData / _handle is populated at any time; the
device field records which. Operations dispatch by device — see
doc/device-placement.md for the policy and per-op decisions.
Autograd: tensors with requiresGrad = true participate in the
backward graph. Every differentiable op sets _backward on its
output; calling backward on a scalar output walks the graph in
reverse topological order and accumulates gradients into each
leaf's grad. Gradient math is expressed via the same ops as the
forward pass, so backward works on CPU and GPU without any extra
per-device code.
Classes
Enums
Extensions
- TensorAft on Tensor
- Attention-Free Transformer (AFT) — full variant.
- TensorAttention on Tensor
- Scaled dot-product attention (single head, 2D).
- TensorConcat on Tensor
-
Concatenate a list of 2D tensors along
axis. Supportsaxis = 0(rows) andaxis = 1(last-axis, columns). - TensorCrossEntropy on Tensor
- Fused softmax + negative-log-likelihood cross-entropy with integer class labels.
- TensorDropout on Tensor
- Inverted dropout.
- TensorEmbedding on Tensor
- Embedding table lookup.
- TensorIm2ColNHWC on Tensor
- im2col unfold for 8x8 NHWC-flat activations used by the LC0 conv tower.
- TensorLayerNorm on Tensor
- LayerNorm along the last axis of a 2D tensor.
- TensorMatMul on Tensor
- Matrix multiplication extension for Tensor.
- TensorOps on Tensor
- Basic tensor operations with autograd wiring.
- TensorRmsNorm on Tensor
- RMSNorm along the last axis of a 2D tensor.
- TensorScatterRows on Tensor
-
Row-wise scatter-add: place a
[K, D]subset of rows into an otherwise-zero[T, D]tensor at the positions given byindices(a[K]float32 tensor whose values are rounded to int). If the same index appears more than once inindicesthe contributions add (atomically on GPU). - TensorSoftmax on Tensor
-
Row-wise softmax along the last axis of a 2D
[R, C]tensor.
Properties
- debugBackwardHook ↔ void Function(int, Tensor)?
-
Debug hook fired after each backward closure. If non-null, called
with (stepIndex, tensor) after
tensor._backward()runs. Use to bisect which closure corrupted state.getter/setter pair