TorchLean API

NN.Examples.Factorization.QR

QR Factorization #

Check whether Tensor.qr A reconstructs $A$ as $QR$ and gives orthonormal columns in $Q$. The checks use Float with an explicit tolerance. Reduced QR uses Q : Tensor Float [rows, min rows columns] and R : Tensor Float [min rows columns, columns].

Run scripts/lake.sh exe torchlean factorizations. The rank-deficient negative control still reconstructs the input, but fails orthonormality: reconstructing a matrix alone does not establish both QR properties. This file tests the implementation; it does not prove a real-arithmetic QR theorem.

Full-rank matrix used for the positive QR check.

Instances For
    def NN.Examples.Factorization.QR.reconstructionError {rows columns : ℕ} (matrix : TorchLean.Tensor Float [rows, columns]) (factors : TorchLean.Tensor.QRFactors Float rows columns) :

    Reconstruction error $\lVert A-QR\rVert_{\max}$ for any reduced factor shape.

    Instances For

      Orthonormality error $\lVert Q^\mathsf{T}Q-I\rVert_{\max}$.

      Instances For

        Wide Matrix #

        This case also places a dependent column before a later independent column. A reduced implementation that merely truncates the old square factors loses that later basis direction.

        Reduced QR of a wide matrix: Q is 2 x 2 and R is 2 x 3.

        Instances For

          Negative Control #

          The following square matrix has one dependent column. This implementation leaves a zero column in Q for the missing basis direction. Gram-Schmidt still reconstructs the matrix, but $Q^\mathsf{T}Q\ne I$ for the returned factors.

          A matrix whose second column is twice its first.

          Instances For

            QR of a rank-deficient matrix. Reconstruction survives; orthonormality does not, because the dependent column contributes a zero column to Q.

            Instances For

              Run square and wide full-rank checks plus the dependent-column negative control.

              Instances For