Skip to content
fn

lu_solve

→Tensor
lu_solve(LU: Tensor, pivots: Tensor, B: Tensor, left: bool = True, adjoint: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

Solve a linear system from a precomputed LU factorization.

Given the packed factorization PA=LUPA = LU returned by lu_factor, solves

A X = BA\,X \,=\, B

by applying the permutation and performing two triangular solves (forward + back substitution).

Parameters

Packed LU factor of shape (*, n, n) from lu_factor.
pivotsTensor
Pivot indices of shape (*, n) from lu_factor (1-based, LAPACK convention).
Right-hand side (*, n, k), broadcast against LU; a vector is refused.
left(bool, keyword - only)= True
If True (default), solve AX=BA X = B; False solves XA=BX A = B.
adjoint(bool, keyword - only)= False
If True, solve with AHA^H instead of AA. Default False.

Returns

Tensor

Solution XX: broadcast batch, then (n, k).

Notes

Backed by LAPACK getrs. Cost per solve is O(n2k)O(n^2 k) — much cheaper than a fresh solve (O(n3)O(n^3)) when the same AA 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.], [3.]])