Tensor Views (API) #
Shape-preserving tensor views that show up across examples and subsystems.
These helpers are 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 bounded examples, it is often useful to treat an arbitrary source shape as a flattened feature
vector and keep only the first takeDim coordinates. Runnable examples use this when they need a
small fixed feature vector from a larger tensor.
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.