Solves a triangular system of linear equations. When left_side = TRUE,
returns x such that op(a) %*% x = b. When left_side = FALSE,
returns x such that x %*% op(a) = b. Here op is a or t(a)
depending on transpose_a.
Usage
nv_triangular_solve(
a,
b,
left_side = TRUE,
lower = TRUE,
unit_diagonal = FALSE,
transpose_a = FALSE
)Arguments
- a
(
arrayish)
Triangular coefficient matrix with at least 2 axes. The last two axes must be equal; any leading axes are batch axes. Can be any numeric data type:aandbare promoted to a common data type and that is then converted to the default float data type (seedefault_dtypes()) where it is not a float already, since the solve is a float one. An R value assumes the other operand's data type within its data type category, and settles on the default float when neither has one.- b
(
arrayish)
Right-hand side. Foraof shape(B..., n, n),bmay be either:full rank — shape
(B..., n, k)whenleft_side = TRUE, or(B..., k, n)whenleft_side = FALSE;one rank less, shape
(B..., n), meaning a single column (left_side = TRUE) or row (left_side = FALSE) per batch — it is reshaped internally and the reshape is undone on the result so the output rank matchesb.
b's batch axes (B...) must matcha's exactly. It is promoted together witha– seea.- left_side
(
logical(1))
IfTRUE(default), solveop(a) %*% x = b; ifFALSE, solvex %*% op(a) = b.- lower
(
logical(1))
Whetherais lower or upper triangular. Defaults toTRUE.- unit_diagonal
(
logical(1))
IfTRUE, the diagonal ofais treated as all ones (and the actual values on the diagonal are ignored). Defaults toFALSE.- transpose_a
(
logical(1))
IfTRUE, solve witht(a)in place ofa. Defaults toFALSE.
Value
(arrayish)
The solution x, with b's shape and the operands' common data type –
or the default float data type (see default_dtypes()) where that was
an integer one.
Details
As a convenience, b may have one fewer axis than a (a single
right-hand side per batch, shape (B..., n) for a of shape
(B..., n, n)). It is reshaped internally to a column (left_side = TRUE) or row (left_side = FALSE) and reshaped back on the way out.
Because we don't broadcast, this is not ambiguous (as it would be for NumPy).
Differentiation is only implemented for a single system: a gradient() of a
batched solve errors.