fn
lu_solve
→Tensorlu_solve(LU: Tensor, pivots: Tensor, B: Tensor)Solve a linear system from a precomputed LU factorization.
Given the packed factorization returned by
lu_factor, solves
by applying the permutation and performing two triangular solves (forward + back substitution).
Parameters
LUTensorPacked LU factor of shape
(*, n, n) from lu_factor.pivotsTensorPivot indices of shape
(*, n) from lu_factor
(1-based, LAPACK convention).BTensorRight-hand side of shape
(*, n, k) (or (*, n)).Returns
TensorSolution , same shape as B.
Notes
Backed by LAPACK getrs. Cost per solve is —
much cheaper than a fresh solve () when the
same is reused.
Examples
>>> import lucid
>>> from lucid.linalg import lu_factor, lu_solve
>>> A = lucid.tensor([[3.0, 1.0], [1.0, 2.0]])
>>> LU, piv = lu_factor(A)
>>> b = lucid.tensor([[9.0], [8.0]])
>>> lu_solve(LU, piv, b)
Tensor([[2.0000],
[3.0000]])