tf.raw_ops.MatrixTriangularSolve
Stay organized with collections
Save and categorize content based on your preferences.
Solves systems of linear equations with upper or lower triangular matrices by backsubstitution.
tf.raw_ops.MatrixTriangularSolve(
matrix, rhs, lower=True, adjoint=False, name=None
)
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)>
Args |
matrix
|
A Tensor . Must be one of the following types: bfloat16 , float64 , float32 , half , complex64 , complex128 .
Shape is [..., M, M] .
|
rhs
|
A Tensor . Must have the same type as matrix .
Shape is [..., M, K] .
|
lower
|
An optional bool . Defaults to True .
Boolean indicating whether the innermost matrices in matrix are
lower or upper triangular.
|
adjoint
|
An optional bool . Defaults to False .
Boolean indicating whether to solve with matrix or its (block-wise)
adjoint.
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor . Has the same type as matrix .
|
Equivalent to scipy.linalg.solve_triangular
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.raw_ops.MatrixTriangularSolve\n\n\u003cbr /\u003e\n\nSolves systems of linear equations with upper or lower triangular matrices by backsubstitution.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.MatrixTriangularSolve`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/MatrixTriangularSolve)\n\n\u003cbr /\u003e\n\n tf.raw_ops.MatrixTriangularSolve(\n matrix, rhs, lower=True, adjoint=False, name=None\n )\n\n`matrix` is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions form\nsquare matrices. If `lower` is `True` then the strictly upper triangular part\nof each inner-most matrix is assumed to be zero and not accessed.\nIf `lower` is False then the strictly lower triangular part of each inner-most\nmatrix is assumed to be zero and not accessed.\n`rhs` is a tensor of shape `[..., M, N]`.\n\nThe output is a tensor of shape `[..., M, N]`. If `adjoint` is\n`True` then the innermost matrices in `output` satisfy matrix equations\n`matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]`.\nIf `adjoint` is `False` then the strictly then the innermost matrices in\n`output` satisfy matrix equations\n`adjoint(matrix[..., i, k]) * output[..., k, j] = rhs[..., i, j]`.\n\nNote, the batch shapes for the inputs only need to broadcast.\n\n#### Example:\n\n\n a = tf.constant([[3, 0, 0, 0],\n [2, 1, 0, 0],\n [1, 0, 1, 0],\n [1, 1, 1, 1]], dtype=tf.float32)\n\n b = tf.constant([[4],\n [2],\n [4],\n [2]], dtype=tf.float32)\n\n x = tf.linalg.triangular_solve(a, b, lower=True)\n x\n # \u003ctf.Tensor: shape=(4, 1), dtype=float32, numpy=\n # array([[ 1.3333334 ],\n # [-0.66666675],\n # [ 2.6666665 ],\n # [-1.3333331 ]], dtype=float32)\u003e\n\n # in python3 one can use `a@x`\n tf.matmul(a, x)\n # \u003ctf.Tensor: shape=(4, 1), dtype=float32, numpy=\n # array([[4. ],\n # [2. ],\n # [4. ],\n # [1.9999999]], dtype=float32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| `matrix` | A `Tensor`. Must be one of the following types: `bfloat16`, `float64`, `float32`, `half`, `complex64`, `complex128`. Shape is `[..., M, M]`. |\n| `rhs` | A `Tensor`. Must have the same type as `matrix`. Shape is `[..., M, K]`. |\n| `lower` | An optional `bool`. Defaults to `True`. Boolean indicating whether the innermost matrices in `matrix` are lower or upper triangular. |\n| `adjoint` | An optional `bool`. Defaults to `False`. Boolean indicating whether to solve with `matrix` or its (block-wise) adjoint. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor`. Has the same type as `matrix`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nnumpy compatibility\n-------------------\n\n\u003cbr /\u003e\n\nEquivalent to scipy.linalg.solve_triangular\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]