Implementing kernel
C++ engine symbols that back this Python API.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
(*, m, n). Need not be square.Returns
TensorPacked factorization of shape (*, m, n).
occupies the diagonal and above; (without its unit
diagonal) occupies the strict lower triangle.
Notes
Backed by LAPACK getrf. Cost is for
a square input.
For a rectangular with
, is
unit-lower-trapezoidal and is
upper-trapezoidal. lu_solve still requires a square factor:
only a square system has a solution.
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.8], [1.4]])