fn

lu_factor

Tensor
lu_factor(A: Tensor)
source

LU factorization with partial pivoting (packed form).

Computes the packed LU factorization

PA=LU,P\,A \,=\, L\,U,

where PP is a row-permutation matrix, LL is unit-lower-triangular, and UU is upper-triangular. The result is returned in LAPACK's packed format suitable for repeated solves via lu_solve.

Parameters

ATensor
Square matrix of shape (*, n, n).

Returns

Tensor

Packed factorization of shape (*, n, n). UU occupies the diagonal and above; LL (without its unit diagonal) occupies the strict lower triangle.

Notes

Backed by LAPACK getrf. Cost is O(23n3)O(\tfrac{2}{3} n^3).

Use lu_factor + lu_solve instead of solve when the same coefficient matrix AA is reused with many right-hand sides — factorization is shared. For the explicit (P,L,U)(P, L, U) triple see lu.

Examples

>>> import lucid
>>> from lucid.linalg import lu_factor, lu_solve
>>> A = lucid.tensor([[2.0, 1.0], [4.0, 7.0]])
>>> LU, piv = lu_factor(A)
>>> b = lucid.tensor([[3.0], [13.0]])
>>> lu_solve(LU, piv, b)
Tensor([[0.8000],
        [1.4000]])