fn
qr
→Tensorqr(x: Tensor, mode: str = 'reduced')QR decomposition of a matrix.
Factorizes a matrix as
where has orthonormal columns () and is upper-triangular. Used for orthogonalizing a basis, solving least-squares (), and computing eigenvalues via QR iteration.
Parameters
xTensorInput matrix of shape
(*, m, n).mode(reduced, complete, r)= "reduced""reduced" (default): is (m, k) and
is (k, n) with .
"complete": is (m, m) and is
(m, n).
"r": return only (Q is an empty tensor).Returns
TensorOrthogonal factor.
Notes
Computed via Householder reflections (LAPACK geqrf). Cost is
for .
The diagonal of may carry arbitrary signs (LAPACK convention) — the factorization is unique only up to a diagonal sign matrix. Backward routes through a Cholesky of (sign-robust) and through the Stiefel-manifold tangent projection.
Examples
>>> import lucid
>>> from lucid.linalg import qr
>>> A = lucid.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
>>> Q, R = qr(A)
>>> Q.T @ Q
Tensor([[1.0000, 0.0000],
[0.0000, 1.0000]])