TorchLean API

NN.API.Tensor.Views

Tensor Views (API) #

Shape-preserving tensor views that show up across examples and subsystems.

These helpers are model-agnostic:

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.

Instances For