fn
solve_triangular
→Tensorsolve_triangular(A: Tensor, B: Tensor, upper: bool = True, left: bool = True, unitriangular: bool = False)Solve a triangular linear system by back/forward substitution.
Solves the system (or ) in which the coefficient matrix is triangular. For upper-triangular the system is solved by back-substitution starting from the last row; for lower-triangular by forward substitution from the first row. Either direction runs in time and is numerically stable when the diagonal of is well-conditioned.
Parameters
ATensorTriangular coefficient matrix of shape
(*, n, n). Only
the relevant triangle is read; the other half is ignored.BTensorRight-hand side of shape
(*, n, k) (or (*, n)).upper(bool, keyword - only)= TrueIf
True (default) is upper-triangular; if
False lower-triangular.left(bool, keyword - only)= TrueIf
True (default) solves ; if False
solves via transposition.unitriangular(bool, keyword - only)= FalseIf
True the diagonal of is treated as all-ones
regardless of its stored values (LAPACK's "unit-diagonal"
mode).Returns
TensorSolution shaped like .
Notes
Backed by LAPACK trsm. Triangular solves are the workhorse
used inside Cholesky, LU, and QR back-substitution paths.
Examples
>>> import lucid
>>> from lucid.linalg import solve_triangular
>>> A = lucid.tensor([[2.0, 1.0], [0.0, 3.0]]) # upper
>>> b = lucid.tensor([[5.0], [9.0]])
>>> solve_triangular(A, b, upper=True)
Tensor([[1.0000],
[3.0000]])