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.Entrypoint.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.anyTensorHtml: same renderer for runtime shape-erased tensors.tensorStatsHtml: compact scalar summary (min/max/mean/norms).#tensor_view,#anytensor_view,#tensor_stats_view: command entry points.
Implementation notes #
- Table rendering for small tensors plus clipped previews for large ones balances readability/performance tradeoff in infoview.
- Element rendering is class-based (
TensorElemView) so backends can customize display without forking widget logic. - We cap recursion depth for higher-rank tensors to avoid overwhelming nested expansions.
References #
Tags #
tensor, visualization, stats, proofwidgets, inspection
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.
Render shape dimensions as a bracketed list string.
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
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 Runtime.AnyTensor (shape-erased runtime tensor) with the same UI as tensorHtml.
Instances For
Stats #
For small tensors, it is often helpful to quickly sanity-check numeric ranges without expanding every element. This widget computes simple scalar summaries (min/max/mean/norms).
Main command:
#tensor_stats_view t
Instances For
Render simple scalar summary statistics (min/max/mean/norms) for a tensor as HTML.