tf.linalg.banded_triangular_solve
Stay organized with collections
Save and categorize content based on your preferences.
Solve triangular systems of equations with a banded solver.
tf.linalg.banded_triangular_solve(
bands, rhs, lower=True, adjoint=False, name=None
)
bands
is a tensor of shape [..., K, M]
, where K
represents the number
of bands stored. This corresponds to a batch of M
by M
matrices, whose
K
subdiagonals (when lower
is True
) are stored.
This operator broadcasts the batch dimensions of bands
and the batch
dimensions of rhs
.
Examples:
Storing 2 bands of a 3x3 matrix.
Note that first element in the second row is ignored due to
the 'LEFT_RIGHT' padding.
x = [[2., 3., 4.], [1., 2., 3.]]
x2 = [[2., 3., 4.], [10000., 2., 3.]]
y = tf.zeros([3, 3])
z = tf.linalg.set_diag(y, x, align='LEFT_RIGHT', k=(-1, 0))
z
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[2., 0., 0.],
[2., 3., 0.],
[0., 3., 4.]], dtype=float32)>
soln = tf.linalg.banded_triangular_solve(x, tf.ones([3, 1]))
soln
<tf.Tensor: shape=(3, 1), dtype=float32, numpy=
array([[0.5 ],
[0. ],
[0.25]], dtype=float32)>
are_equal = soln == tf.linalg.banded_triangular_solve(x2, tf.ones([3, 1]))
tf.reduce_all(are_equal).numpy()
True
are_equal = soln == tf.linalg.triangular_solve(z, tf.ones([3, 1]))
tf.reduce_all(are_equal).numpy()
True
Storing 2 superdiagonals of a 4x4 matrix. Because of the 'LEFT_RIGHT' padding
the last element of the first row is ignored.
x = [[2., 3., 4., 5.], [-1., -2., -3., -4.]]
y = tf.zeros([4, 4])
z = tf.linalg.set_diag(y, x, align='LEFT_RIGHT', k=(0, 1))
z
<tf.Tensor: shape=(4, 4), dtype=float32, numpy=
array([[-1., 2., 0., 0.],
[ 0., -2., 3., 0.],
[ 0., 0., -3., 4.],
[ 0., 0., -0., -4.]], dtype=float32)>
soln = tf.linalg.banded_triangular_solve(x, tf.ones([4, 1]), lower=False)
soln
<tf.Tensor: shape=(4, 1), dtype=float32, numpy=
array([[-4. ],
[-1.5 ],
[-0.6666667],
[-0.25 ]], dtype=float32)>
are_equal = (soln == tf.linalg.triangular_solve(
z, tf.ones([4, 1]), lower=False))
tf.reduce_all(are_equal).numpy()
True
Args |
bands
|
A Tensor describing the bands of the left hand side, with shape
[..., K, M] . The K rows correspond to the diagonal to the K - 1 -th
diagonal (the diagonal is the top row) when lower is True and
otherwise the K - 1 -th superdiagonal to the diagonal (the diagonal is
the bottom row) when lower is False . The bands are stored with
'LEFT_RIGHT' alignment, where the superdiagonals are padded on the right
and subdiagonals are padded on the left. This is the alignment cuSPARSE
uses. See tf.linalg.set_diag for more details.
|
rhs
|
A Tensor of shape [..., M] or [..., M, N] and with the same dtype as
diagonals . Note that if the shape of rhs and/or diags isn't known
statically, rhs will be treated as a matrix rather than a vector.
|
lower
|
An optional bool . Defaults to True . Boolean indicating whether
bands represents a lower or upper triangular matrix.
|
adjoint
|
An optional bool . Defaults to False . Boolean indicating whether
to solve with the matrix's block-wise adjoint.
|
name
|
A name to give this Op (optional).
|
Returns |
A Tensor of shape [..., M] or [..., M, N] containing the solutions.
|
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.linalg.banded_triangular_solve\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/linalg/linalg_impl.py#L350-L443) |\n\nSolve triangular systems of equations with a banded solver. \n\n tf.linalg.banded_triangular_solve(\n bands, rhs, lower=True, adjoint=False, name=None\n )\n\n`bands` is a tensor of shape `[..., K, M]`, where `K` represents the number\nof bands stored. This corresponds to a batch of `M` by `M` matrices, whose\n`K` subdiagonals (when `lower` is `True`) are stored.\n\nThis operator broadcasts the batch dimensions of `bands` and the batch\ndimensions of `rhs`.\n\n#### Examples:\n\nStoring 2 bands of a 3x3 matrix.\nNote that first element in the second row is ignored due to\nthe 'LEFT_RIGHT' padding. \n\n x = [[2., 3., 4.], [1., 2., 3.]]\n x2 = [[2., 3., 4.], [10000., 2., 3.]]\n y = tf.zeros([3, 3])\n z = tf.linalg.set_diag(y, x, align='LEFT_RIGHT', k=(-1, 0))\n z\n \u003ctf.Tensor: shape=(3, 3), dtype=float32, numpy=\n array([[2., 0., 0.],\n [2., 3., 0.],\n [0., 3., 4.]], dtype=float32)\u003e\n soln = tf.linalg.banded_triangular_solve(x, tf.ones([3, 1]))\n soln\n \u003ctf.Tensor: shape=(3, 1), dtype=float32, numpy=\n array([[0.5 ],\n [0. ],\n [0.25]], dtype=float32)\u003e\n are_equal = soln == tf.linalg.banded_triangular_solve(x2, tf.ones([3, 1]))\n tf.reduce_all(are_equal).numpy()\n True\n are_equal = soln == tf.linalg.triangular_solve(z, tf.ones([3, 1]))\n tf.reduce_all(are_equal).numpy()\n True\n\nStoring 2 superdiagonals of a 4x4 matrix. Because of the 'LEFT_RIGHT' padding\nthe last element of the first row is ignored. \n\n x = [[2., 3., 4., 5.], [-1., -2., -3., -4.]]\n y = tf.zeros([4, 4])\n z = tf.linalg.set_diag(y, x, align='LEFT_RIGHT', k=(0, 1))\n z\n \u003ctf.Tensor: shape=(4, 4), dtype=float32, numpy=\n array([[-1., 2., 0., 0.],\n [ 0., -2., 3., 0.],\n [ 0., 0., -3., 4.],\n [ 0., 0., -0., -4.]], dtype=float32)\u003e\n soln = tf.linalg.banded_triangular_solve(x, tf.ones([4, 1]), lower=False)\n soln\n \u003ctf.Tensor: shape=(4, 1), dtype=float32, numpy=\n array([[-4. ],\n [-1.5 ],\n [-0.6666667],\n [-0.25 ]], dtype=float32)\u003e\n are_equal = (soln == tf.linalg.triangular_solve(\n z, tf.ones([4, 1]), lower=False))\n tf.reduce_all(are_equal).numpy()\n True\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `bands` | A `Tensor` describing the bands of the left hand side, with shape `[..., K, M]`. The `K` rows correspond to the diagonal to the `K - 1`-th diagonal (the diagonal is the top row) when `lower` is `True` and otherwise the `K - 1`-th superdiagonal to the diagonal (the diagonal is the bottom row) when `lower` is `False`. The bands are stored with 'LEFT_RIGHT' alignment, where the superdiagonals are padded on the right and subdiagonals are padded on the left. This is the alignment cuSPARSE uses. See [`tf.linalg.set_diag`](../../tf/linalg/set_diag) for more details. |\n| `rhs` | A `Tensor` of shape \\[..., M\\] or \\[..., M, N\\] and with the same dtype as `diagonals`. Note that if the shape of `rhs` and/or `diags` isn't known statically, `rhs` will be treated as a matrix rather than a vector. |\n| `lower` | An optional `bool`. Defaults to `True`. Boolean indicating whether `bands` represents a lower or upper triangular matrix. |\n| `adjoint` | An optional `bool`. Defaults to `False`. Boolean indicating whether to solve with the matrix's block-wise adjoint. |\n| `name` | A name to give this `Op` (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` of shape \\[..., M\\] or \\[..., M, N\\] containing the solutions. ||\n\n\u003cbr /\u003e"]]