Have a question? Connect with the community at the TensorFlow Forum

# TriangularSolve

public final class TriangularSolve

Solves systems of linear equations with upper or lower triangular matrices by backsubstitution.

`matrix` is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions form square matrices. If `lower` is `True` then the strictly upper triangular part of each inner-most matrix is assumed to be zero and not accessed. If `lower` is False then the strictly lower triangular part of each inner-most matrix is assumed to be zero and not accessed. `rhs` is a tensor of shape `[..., M, N]`.

The output is a tensor of shape `[..., M, N]`. If `adjoint` is `True` then the innermost matrices in `output` satisfy matrix equations `matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]`. If `adjoint` is `False` then the strictly then the innermost matrices in `output` satisfy matrix equations `adjoint(matrix[..., i, k]) * output[..., k, j] = rhs[..., i, j]`.

Note, the batch shapes for the inputs only need to broadcast.

Example:

``````a = tf.constant([[3,  0,  0,  0],
[2,  1,  0,  0],
[1,  0,  1,  0],
[1,  1,  1,  1]], dtype=tf.float32)

b = tf.constant([[4],
[2],
[4],
[2]], dtype=tf.float32)

x = tf.linalg.triangular_solve(a, b, lower=True)
x
# <tf.Tensor: shape=(4, 1), dtype=float32, numpy=
# array([[ 1.3333334 ],
#        [-0.66666675],
#        [ 2.6666665 ],
#        [-1.3333331 ]], dtype=float32)>

# in python3 one can use `a@x`
tf.matmul(a, x)
# <tf.Tensor: shape=(4, 1), dtype=float32, numpy=
# array([[4.       ],
#        [2.       ],
#        [4.       ],
#        [1.9999999]], dtype=float32)>
``````

### Nested Classes

 class TriangularSolve.Options Optional attributes for ``` TriangularSolve ```

### Constants

 String OP_NAME The name of this op, as known by TensorFlow core engine

### Public Methods

 static TriangularSolve.Options (Boolean adjoint) Output () Returns the symbolic handle of the tensor. static TriangularSolve ( Scope scope, Operand matrix, Operand rhs, Options... options) Factory method to create a class wrapping a new TriangularSolve operation. static TriangularSolve.Options (Boolean lower) Output () Shape is `[..., M, K]`.

## Constants

#### public static final String OP_NAME

The name of this op, as known by TensorFlow core engine

Constant Value: "MatrixTriangularSolve"

## Public Methods

#### public static TriangularSolve.Options adjoint (Boolean adjoint)

##### Parameters
 adjoint Boolean indicating whether to solve with `matrix` or its (block-wise) adjoint.

#### public Output <T> asOutput ()

Returns the symbolic handle of the tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.

#### public static TriangularSolve <T> create ( Scope scope, Operand <T> matrix, Operand <T> rhs, Options... options)

Factory method to create a class wrapping a new TriangularSolve operation.

##### Parameters
 scope current scope Shape is `[..., M, M]`. Shape is `[..., M, K]`. carries optional attributes values
##### Returns
• a new instance of TriangularSolve

#### public static TriangularSolve.Options lower (Boolean lower)

##### Parameters
 lower Boolean indicating whether the innermost matrices in `matrix` are lower or upper triangular.

#### public Output <T> output ()

Shape is `[..., M, K]`.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]