solve_triangular(input: Tensor, B: Tensor, upper: bool, left: bool = True, unitriangular: bool = False)Implementing kernel
C++ engine symbols that back this Python API.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
inputTensor(*, n, n). Only
the relevant triangle is read; the other half is ignored.(*, n, k) ((*, k, n) if left=False); batch dims broadcast
with input. A vector is refused: b.unsqueeze(-1) gives it a column.upper(bool, keyword - only)True is upper-triangular; if False
lower-triangular.left(bool, keyword - only)= TrueTrue (default) solves ; if False
solves via transposition.unitriangular(bool, keyword - only)= FalseTrue the diagonal of is treated as all-ones
regardless of its stored values (LAPACK's "unit-diagonal"
mode).Returns
TensorSolution — the broadcast batch, then (n, k).
Raises
ShapeMismatchinput, or shapes that do not
fit or broadcast: a RuntimeError with the reference's message.Notes
A B of another dtype is read in input's, and the answer has it
too, as the reference does.
Backed by BLAS trsm on both devices. Triangular solves are the
workhorse used inside Cholesky, LU, and QR back-substitution paths.
A singular (an exact zero on the diagonal, with
unitriangular=False) is not refused: substitution divides by the
zero, so the solution holds , or NaN where it meets
, as the reference framework does.
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.], [3.]])