Skip to content
fn

solve_triangular_op

→TensorImplPtr
int solve_triangular_op(const int & a, const int & b, bool upper, bool unitriangular)

Python wrappers

Public Python APIs implemented by this engine symbol.

Solve AX=BA X = B for XX where AA is triangular.

Performs a single substitution sweep through AA; no factorisation is required. AA and BB must share the same dtype and device. The batch axes of AA and BB broadcast; the backend then runs BLAS once per aligned slice.

Math

Solves

AX=B⟺X=A−1B, A X = B \quad\Longleftrightarrow\quad X = A^{-1} B,

without ever forming A−1A^{-1}. When unitriangular is set, AA is regarded as A~\widetilde{A} with A~ii=1\widetilde{A}_{ii} = 1 for all ii. The corresponding reverse-mode rule is

∂B∂L=A−⊤∂X∂L,∂A∂L=− ∂B∂L X⊤, \frac{\partial B}{\partial L} = A^{-\top} \frac{\partial X}{\partial L}, \qquad \frac{\partial A}{\partial L} = -\,\frac{\partial B}{\partial L}\,X^\top,

implemented by [[SolveTriangularBackward]].

Shape

  • a : (*, N, N).
  • b : (*, N, K), or (N,) (vector RHS).
  • return: the broadcast batch followed by (N, K), or by (N,) for a vector RHS.

See Also

  • solve_op — full LU-based dense solve; use when AA is not known to be triangular.
  • cholesky_op / ldl_factor_op — produce the triangular factors this op back-substitutes through.

Parameters

aTensorImplPtr
Triangular coefficient matrix of shape (..., N, N) with dtype F32 or F64. Only the half indicated by upper is read.
bTensorImplPtr
Right-hand side of shape (..., N, K) (or (..., N) for a single RHS), same dtype and device as a.
upperbool= None
If true (default), a is interpreted as upper-triangular and back-substitution is used. If false, a is lower-triangular and forward-substitution is used.
unitriangularbool= None
If true, the diagonal of a is treated as all-ones regardless of its stored values. Useful for the unit-lower factor produced by LDL⊤^\top and for Householder products. Default is false.

Returns

TensorImplPtr

Solution XX with the dtype of b (shape below).

Raises

ShapeMismatch
If b breaks the right-hand-side contract above — before any backend call.
LucidError
If a is not square, if a and b have mismatched dtype or device, or if either tensor has a non-float dtype.
the solution holds
$\pm\infty$ / NaN where substitution divided by a zero pivot.