TorchLean API

NN.Widgets.Core.Tensor

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:

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 #

Implementation notes #

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.
Instances
    @[implicit_reducible]

    Default element renderer for #tensor_view, using ToString.

    Join strings with a separator.

    Instances For

      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
            def NN.Widgets.tensorHtml {α : Type} [ToString α] {s : Spec.Shape} (t : Spec.Tensor α s) (maxRows maxCols : := 16) (maxElems : := 64) :

            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 #

              def NN.Widgets.anyTensorHtml {α : Type} [ToString α] (v : Runtime.AnyTensor α) (maxRows maxCols : := 16) (maxElems : := 64) :

              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:

                def NN.Widgets.TensorInternal.abs' {α : Type} [Context α] (x : α) :
                α
                Instances For
                  def NN.Widgets.TensorInternal.sqrt' {α : Type} [Context α] (x : α) :
                  α
                  Instances For

                    Render simple scalar summary statistics (min/max/mean/norms) for a tensor as HTML.

                    Instances For

                      Commands #