TorchLean API

NN.Examples.Factorization.Common

Factorization examples — shared helpers #

Small Float-valued helpers used by the matrix-factorization examples (Cholesky, QR). Each example reconstructs the original matrix from its factors and asserts (via #eval) that the maximum entrywise reconstruction error is below a tolerance, so the build fails if a factorization is wrong.

These run over Float (the executable 64-bit runtime scalar), which is the precision the factorizations target for Gaussian-process / kernel-method use.

Build an m × n Float matrix tensor from a row-major nested list. Missing entries are 0.

Instances For

    Maximum entrywise absolute difference between two m × n matrices.

    Instances For

      Read a vector tensor back out as a List Float (for display).

      Instances For

        Squared Frobenius distance $\sum_{i,j}(A_{ij}-B_{ij})^2$ between two m × n matrices.

        Instances For

          Shared tolerance for reconstruction-error assertions.

          Instances For
            def NN.Examples.Factorization.assertLt (name : String) (err : Float) (tolerance : Float := tol) :

            Compiled positive assertion: print name: OK (err) when $\mathrm{err}<\mathrm{tol}$, otherwise raise an IO error so the build/#eval fails. Running this through #eval evaluates with the compiler (fast), unlike #guard, which forces slow kernel reduction of the whole factorization.

            Instances For
              def NN.Examples.Factorization.assertGe (name : String) (err : Float) (threshold : Float := 0.5) :

              Compiled negative-control assertion: succeeds only when $\mathrm{err}\ge\mathrm{threshold}$, i.e. when a property that should not hold is correctly detected as violated. Gives the metric teeth — a reviewer can see the same maxMatErr/residual that reports 0 on a valid factorization reports a large value on an invalid one, so the positive checks are not vacuous.

              Instances For
                def NN.Examples.Factorization.assertReconFails (name : String) (err : Float) (tolerance : Float := tol) :

                Compiled negative-control assertion that a reconstruction fails: succeeds when the error is not below tol — including the NaN produced when a hypothesis is violated (e.g. Cholesky of a non-positive-definite matrix takes √(negative)). Documents that the success hypotheses (positive Cholesky pivots, positive R pivots / full column rank) are genuinely necessary.

                Instances For