fn
lu_factor
→Tensorlu_factor(A: Tensor)LU factorization with partial pivoting (packed form).
Computes the packed LU factorization
where is a row-permutation matrix, is
unit-lower-triangular, and is upper-triangular. The
result is returned in LAPACK's packed format suitable for repeated
solves via lu_solve.
Parameters
ATensorSquare matrix of shape
(*, n, n).Returns
TensorPacked factorization of shape (*, n, n).
occupies the diagonal and above; (without its unit
diagonal) occupies the strict lower triangle.
Notes
Backed by LAPACK getrf. Cost is .
Use lu_factor + lu_solve instead of solve
when the same coefficient matrix is reused with many
right-hand sides — factorization is shared. For the explicit
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]])