Executable program operations for verification and compiler-facing examples.
Most model code should use nn.* and Trainer.*. Use Ops.* when writing an explicit
TorchLean executable program directly, for example before compiling a hand-built fragment to
NN.IR.Graph.
Total number of scalar elements (a.k.a. “numel”).
Instances For
Vector shape n.
Instances For
Matrix shape rows × cols.
Instances For
Image shape C × H × W (channel-first).
Instances For
Batched image shape N × C × H × W (PyTorch default for images).
Instances For
Batched image shape N × C × H × W (PyTorch default for images).
Instances For
Number of scalar features in a CHW image shape.
Instances For
Convert a runtime list of dimensions like [2, 3, 4] into a nested Shape.
Why this exists:
- In the spec layer we usually carry the shape in the type (great for safety).
- In “API land” we often start from lists (CLI args, JSON, compact examples, …).
shapeOfDims is the bridge between those representations.
Instances For
Convert to a list of dimensions (outermost first).
Instances For
Shape-indexed tensor datatype for the spec layer.
This is a functional representation:
- a scalar tensor is just an
α, - an
n-dimensional tensor is a functionFin n → Tensor α s.
The spec layer does not commit to a concrete memory layout.
Instances For
Create a 1-D tensor from a Lean List.
Notes:
- The shape is computed from
xs.length, so the type remembers the length. - This is total and does not perform any runtime checks.
PyTorch analogy: torch.tensor(xs) producing a 1D tensor.
Instances For
Build a vector tensor from a list.
PyTorch analogy: torch.tensor(xs) producing a 1D tensor.
Instances For
Build a matrix tensor from a list of rows (strict validation).
This is the "safe by default" constructor used by the user-facing API layer. It refuses empty input and refuses ragged rows, because that usually indicates a bug at the call site (e.g. an accidental missing column in imported weights).
PyTorch analogy: torch.tensor(xss) will also error if xss is ragged.
Instances For
N-D tensor from a runtime dims list and a flat xs, with a runtime length check.
This is the “dynamic / user-friendly” version: it fails with a descriptive message if the number
of provided scalars doesn’t match the implied numel.
Instances For
1-D tensor from Float literals, cast into the executable IEEE-754 FP32 backend.
Instances For
Fill a tensor of shape s with a constant value.
PyTorch analogy: torch.full(shape, value).
Instances For
Map a scalar function across a tensor, changing the element type.
PyTorch analogy: torch.Tensor.to(dtype=...) is implemented as a scalar cast map under the hood.
We keep this explicit at the spec layer because it is a common building block.
Instances For
Extract the i-th entry from a vector tensor.
Instances For
Print a tensor with a dtype tag, or throw an IO.userError if the dtype refuses to print.
Instances For
Extract the scalar value from a scalar tensor.
Instances For
Repeat one tensor across a fixed batch axis.
Use this for classifier demos whose checked model consumes a whole batch, while the example wants to inspect one ordinary input.
Instances For
Convert a runtime tensor back to a Float tensor inside IO.
This is the public bridge used by trainer prediction handles: examples can train under executable
IEEE32 or other runtime scalar backends, but still receive ordinary Float tensors for inspection,
printing, and follow-up scripting.
Instances For
Host-side scalar ReLU for task definitions and synthetic targets.
Instances For
Public Namespaces #
These namespaces are the user-facing spelling for model construction, tensor utilities, training, runtime selection, and verification-adjacent examples. The definitions below forward to the checked implementation; the semantics are not copied or forked.