Tensor #
Tensor inspection widgets for the Lean infoview.
This module defines a #tensor_view t command that displays a small tensor as a rich HTML panel in
the infoview. It is designed for:
- examples,
- inspecting runtime output,
- teaching/exposition in the manual.
It is not intended to be used inside proofs, and it is kept out of TorchLean’s default build
surface (you must explicitly import NN.Widgets or a concrete widget module such as
NN.Widgets.Core.Tensor).
Implementation note:
We build on ProofWidgets’ #html command (which ships with mathlib’s dependency set) rather than
introducing any custom JavaScript or external build step.
Main definitions #
tensorHtml: shape-aware renderer for typed tensors.packedTensorHtml: the same renderer for shape-erased tensors.tensorStatsHtml: compact scalar summary (min/max/mean/norms).#tensor_view,#anytensor_view,#tensor_stats_view: command entry points.
Element renderer for #tensor_view.
The tensor widget is used across the library, so we keep element rendering customizable:
- the default instance uses
ToString, - specialized instances can add tooltips (e.g. float32 bits), units, or compact formatting.
- render : α → ProofWidgets.Html
Instances
Default element renderer for #tensor_view, using ToString.
Read only the requested prefix, without converting the full backing buffer.
Instances For
Render a 1D tensor as a clipped single-row table.
Instances For
Render a 2D tensor as a clipped grid table.
Instances For
First maxElems entries of a tensor in row-major order, with a marker when there are more.
Truncating matters here: a widget that tried to print a full tensor would hang the editor on anything of realistic size.
Instances For
Render a tensor as HTML.
For small vectors/matrices, we render an actual table; otherwise we show a compact pretty string plus a flat preview.
Instances For
Runtime Wrappers #
Render a Spec.SomeTensor with the same UI as tensorHtml.
Instances For
Stats #
For small tensors, it is often helpful to inspect numeric ranges without expanding every element. This widget computes simple scalar summaries (min/max/mean/norms).
Main command:
#tensor_stats_view t
Numeric summary panel: shape, size, extrema, mean, and the three usual norms.
Instances For
Render simple scalar summary statistics (min/max/mean/norms) for a tensor as HTML.