Tensor Views (API) #
Small, shape-preserving tensor views that show up across examples and subsystems.
These helpers are deliberately model-agnostic:
- they are not tied to a particular layer architecture, and
- they avoid pulling in large "example config" modules just to access a view.
Flattened Prefix View #
For quick experiments, it's often useful to treat an arbitrary source shape as a flattened
feature vector and keep only the first takeDim coordinates. This keeps runnable demos fast
without baking dataset-specific flattening logic into every example.
def
NN.API.tensor.flattenBatchPrefix
{α : Type}
[Inhabited α]
(batch takeDim : ℕ)
{source : Shape}
(hTake : takeDim ≤ Shape.size source)
(x : Spec.Tensor α (Spec.Shape.dim batch source))
:
Spec.Tensor α (Tensor.Shape.Mat batch takeDim)
Flatten each sample in a batch and keep the first takeDim entries.
The output is a typed matrix batch × takeDim.