Type tf.linalg
Namespace tensorflow
Methods
- adjoint
- expm
- expm_dyn
- logdet
- logdet_dyn
- lu
- lu_dyn
- matrix_rank
- matrix_rank_dyn
- matvec
- matvec_dyn
- normalize
- normalize
- normalize
- normalize
- normalize
- normalize
- normalize_dyn
- pinv
- pinv_dyn
- tridiagonal_matmul
- tridiagonal_matmul
- tridiagonal_matmul
- tridiagonal_matmul_dyn
- tridiagonal_solve
- tridiagonal_solve
- tridiagonal_solve_dyn
Properties
Public static methods
Tensor adjoint(IGraphNodeBase matrix, string name)
Transposes the last two dimensions of and conjugates tensor `matrix`.
Parameters
-
IGraphNodeBase
matrix - A `Tensor`. Must be `float16`, `float32`, `float64`, `complex64`, or `complex128` with shape `[..., M, M]`.
-
string
name - A name to give this `Op` (optional).
Returns
-
Tensor
- The adjoint (a.k.a. Hermitian transpose a.k.a. conjugate transpose) of matrix.
Show Example
x = tf.constant([[1 + 1j, 2 + 2j, 3 + 3j], [4 + 4j, 5 + 5j, 6 + 6j]]) tf.linalg.adjoint(x) # [[1 - 1j, 4 - 4j], # [2 - 2j, 5 - 5j], # [3 - 3j, 6 - 6j]]
Tensor expm(IGraphNodeBase input, string name)
Computes the matrix exponential of one or more square matrices. exp(A) = \sum_{n=0}^\infty A^n/n! The exponential is computed using a combination of the scaling and squaring
method and the Pade approximation. Details can be found in:
Nicholas J. Higham, "The scaling and squaring method for the matrix
exponential revisited," SIAM J. Matrix Anal. Applic., 26:1179-1193, 2005. The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
form square matrices. The output is a tensor of the same shape as the input
containing the exponential for all input submatrices `[..., :, :]`.
Parameters
-
IGraphNodeBase
input - A `Tensor`. Must be `float16`, `float32`, `float64`, `complex64`, or `complex128` with shape `[..., M, M]`.
-
string
name - A name to give this `Op` (optional).
Returns
-
Tensor
- the matrix exponential of the input.
object expm_dyn(object input, object name)
Computes the matrix exponential of one or more square matrices. exp(A) = \sum_{n=0}^\infty A^n/n! The exponential is computed using a combination of the scaling and squaring
method and the Pade approximation. Details can be found in:
Nicholas J. Higham, "The scaling and squaring method for the matrix
exponential revisited," SIAM J. Matrix Anal. Applic., 26:1179-1193, 2005. The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
form square matrices. The output is a tensor of the same shape as the input
containing the exponential for all input submatrices `[..., :, :]`.
Parameters
-
object
input - A `Tensor`. Must be `float16`, `float32`, `float64`, `complex64`, or `complex128` with shape `[..., M, M]`.
-
object
name - A name to give this `Op` (optional).
Returns
-
object
- the matrix exponential of the input.
object logdet(IGraphNodeBase matrix, string name)
Computes log of the determinant of a hermitian positive definite matrix.
Parameters
-
IGraphNodeBase
matrix - A `Tensor`. Must be `float16`, `float32`, `float64`, `complex64`, or `complex128` with shape `[..., M, M]`.
-
string
name - A name to give this `Op`. Defaults to `logdet`.
Returns
-
object
- The natural log of the determinant of `matrix`.
Show Example
# Compute the determinant of a matrix while reducing the chance of over- or underflow: A =... # shape 10 x 10 det = tf.exp(tf.linalg.logdet(A)) # scalar
object logdet_dyn(object matrix, object name)
Computes log of the determinant of a hermitian positive definite matrix.
Parameters
-
object
matrix - A `Tensor`. Must be `float16`, `float32`, `float64`, `complex64`, or `complex128` with shape `[..., M, M]`.
-
object
name - A name to give this `Op`. Defaults to `logdet`.
Returns
-
object
- The natural log of the determinant of `matrix`.
Show Example
# Compute the determinant of a matrix while reducing the chance of over- or underflow: A =... # shape 10 x 10 det = tf.exp(tf.linalg.logdet(A)) # scalar
object lu(IGraphNodeBase input, ImplicitContainer<T> output_idx_type, string name)
Computes the LU decomposition of one or more square matrices. The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
form square matrices. The input has to be invertible. The output consists of two tensors LU and P containing the LU decomposition
of all input submatrices `[..., :, :]`. LU encodes the lower triangular and
upper triangular factors. For each input submatrix of shape `[M, M]`, L is a lower triangular matrix of
shape `[M, M]` with unit diagonal whose entries correspond to the strictly lower
triangular part of LU. U is a upper triangular matrix of shape `[M, M]` whose
entries correspond to the upper triangular part, including the diagonal, of LU. P represents a permutation matrix encoded as a list of indices each between `0`
and `M-1`, inclusive. If P_mat denotes the permutation matrix corresponding to
P, then the L, U and P satisfies P_mat * input = L * U.
Parameters
-
IGraphNodeBase
input - A `Tensor`. Must be one of the following types: `float64`, `float32`, `half`, `complex64`, `complex128`. A tensor of shape `[..., M, M]` whose inner-most 2 dimensions form matrices of size `[M, M]`.
-
ImplicitContainer<T>
output_idx_type - An optional
tf.DType
from: `tf.int32, tf.int64`. Defaults totf.int32
. -
string
name - A name for the operation (optional).
Returns
-
object
- A tuple of `Tensor` objects (lu, p).
object lu_dyn(object input, ImplicitContainer<T> output_idx_type, object name)
Computes the LU decomposition of one or more square matrices. The input is a tensor of shape `[..., M, M]` whose inner-most 2 dimensions
form square matrices. The input has to be invertible. The output consists of two tensors LU and P containing the LU decomposition
of all input submatrices `[..., :, :]`. LU encodes the lower triangular and
upper triangular factors. For each input submatrix of shape `[M, M]`, L is a lower triangular matrix of
shape `[M, M]` with unit diagonal whose entries correspond to the strictly lower
triangular part of LU. U is a upper triangular matrix of shape `[M, M]` whose
entries correspond to the upper triangular part, including the diagonal, of LU. P represents a permutation matrix encoded as a list of indices each between `0`
and `M-1`, inclusive. If P_mat denotes the permutation matrix corresponding to
P, then the L, U and P satisfies P_mat * input = L * U.
Parameters
-
object
input - A `Tensor`. Must be one of the following types: `float64`, `float32`, `half`, `complex64`, `complex128`. A tensor of shape `[..., M, M]` whose inner-most 2 dimensions form matrices of size `[M, M]`.
-
ImplicitContainer<T>
output_idx_type - An optional
tf.DType
from: `tf.int32, tf.int64`. Defaults totf.int32
. -
object
name - A name for the operation (optional).
Returns
-
object
- A tuple of `Tensor` objects (lu, p).
Tensor matrix_rank(IGraphNodeBase a, IEnumerable<object> tol, bool validate_args, string name)
Compute the matrix rank of one or more matrices.
Parameters
-
IGraphNodeBase
a - (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be pseudo-inverted.
-
IEnumerable<object>
tol - Threshold below which the singular value is counted as 'zero'. Default value: `None` (i.e., `eps * max(rows, cols) * max(singular_val)`).
-
bool
validate_args - When `True`, additional assertions might be embedded in the graph. Default value: `False` (i.e., no graph assertions are added).
-
string
name - Python `str` prefixed to ops created by this function. Default value: 'matrix_rank'.
Returns
object matrix_rank_dyn(object a, object tol, ImplicitContainer<T> validate_args, object name)
Compute the matrix rank of one or more matrices.
Parameters
-
object
a - (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be pseudo-inverted.
-
object
tol - Threshold below which the singular value is counted as 'zero'. Default value: `None` (i.e., `eps * max(rows, cols) * max(singular_val)`).
-
ImplicitContainer<T>
validate_args - When `True`, additional assertions might be embedded in the graph. Default value: `False` (i.e., no graph assertions are added).
-
object
name - Python `str` prefixed to ops created by this function. Default value: 'matrix_rank'.
Returns
-
object
Tensor matvec(ndarray a, ndarray b, bool transpose_a, bool adjoint_a, bool a_is_sparse, bool b_is_sparse, string name)
Multiplies matrix `a` by vector `b`, producing `a` * `b`. The matrix `a` must, following any transpositions, be a tensor of rank >= 2,
and we must have `shape(b) = shape(a)[:-2] + [shape(a)[-1]]`. Both `a` and `b` must be of the same type. The supported types are:
`float16`, `float32`, `float64`, `int32`, `complex64`, `complex128`. Matrix `a` can be transposed or adjointed (conjugated and transposed) on
the fly by setting one of the corresponding flag to `True`. These are `False`
by default. If one or both of the inputs contain a lot of zeros, a more efficient
multiplication algorithm can be used by setting the corresponding
`a_is_sparse` or `b_is_sparse` flag to `True`. These are `False` by default.
This optimization is only available for plain matrices/vectors (rank-2/1
tensors) with datatypes `bfloat16` or `float32`.
Parameters
-
ndarray
a - `Tensor` of type `float16`, `float32`, `float64`, `int32`, `complex64`, `complex128` and rank > 1.
-
ndarray
b - `Tensor` with same type and rank = `rank(a) - 1`.
-
bool
transpose_a - If `True`, `a` is transposed before multiplication.
-
bool
adjoint_a - If `True`, `a` is conjugated and transposed before multiplication.
-
bool
a_is_sparse - If `True`, `a` is treated as a sparse matrix.
-
bool
b_is_sparse - If `True`, `b` is treated as a sparse matrix.
-
string
name - Name for the operation (optional).
Returns
-
Tensor
- A `Tensor` of the same type as `a` and `b` where each inner-most vector is the product of the corresponding matrices in `a` and vectors in `b`, e.g. if all transpose or adjoint attributes are `False`: `output`[..., i] = sum_k (`a`[..., i, k] * `b`[..., k]), for all indices i.
Show Example
# 2-D tensor `a` # [[1, 2, 3], # [4, 5, 6]] a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) # 1-D tensor `b` # [7, 9, 11] b = tf.constant([7, 9, 11], shape=[3]) # `a` * `b` # [ 58, 64] c = tf.matvec(a, b) # 3-D tensor `a` # [[[ 1, 2, 3], # [ 4, 5, 6]], # [[ 7, 8, 9], # [10, 11, 12]]] a = tf.constant(np.arange(1, 13, dtype=np.int32), shape=[2, 2, 3]) # 2-D tensor `b` # [[13, 14, 15], # [16, 17, 18]] b = tf.constant(np.arange(13, 19, dtype=np.int32), shape=[2, 3]) # `a` * `b` # [[ 86, 212], # [410, 563]] c = tf.matvec(a, b)
object matvec_dyn(object a, object b, ImplicitContainer<T> transpose_a, ImplicitContainer<T> adjoint_a, ImplicitContainer<T> a_is_sparse, ImplicitContainer<T> b_is_sparse, object name)
Multiplies matrix `a` by vector `b`, producing `a` * `b`. The matrix `a` must, following any transpositions, be a tensor of rank >= 2,
and we must have `shape(b) = shape(a)[:-2] + [shape(a)[-1]]`. Both `a` and `b` must be of the same type. The supported types are:
`float16`, `float32`, `float64`, `int32`, `complex64`, `complex128`. Matrix `a` can be transposed or adjointed (conjugated and transposed) on
the fly by setting one of the corresponding flag to `True`. These are `False`
by default. If one or both of the inputs contain a lot of zeros, a more efficient
multiplication algorithm can be used by setting the corresponding
`a_is_sparse` or `b_is_sparse` flag to `True`. These are `False` by default.
This optimization is only available for plain matrices/vectors (rank-2/1
tensors) with datatypes `bfloat16` or `float32`.
Parameters
-
object
a - `Tensor` of type `float16`, `float32`, `float64`, `int32`, `complex64`, `complex128` and rank > 1.
-
object
b - `Tensor` with same type and rank = `rank(a) - 1`.
-
ImplicitContainer<T>
transpose_a - If `True`, `a` is transposed before multiplication.
-
ImplicitContainer<T>
adjoint_a - If `True`, `a` is conjugated and transposed before multiplication.
-
ImplicitContainer<T>
a_is_sparse - If `True`, `a` is treated as a sparse matrix.
-
ImplicitContainer<T>
b_is_sparse - If `True`, `b` is treated as a sparse matrix.
-
object
name - Name for the operation (optional).
Returns
-
object
- A `Tensor` of the same type as `a` and `b` where each inner-most vector is the product of the corresponding matrices in `a` and vectors in `b`, e.g. if all transpose or adjoint attributes are `False`: `output`[..., i] = sum_k (`a`[..., i, k] * `b`[..., k]), for all indices i.
Show Example
# 2-D tensor `a` # [[1, 2, 3], # [4, 5, 6]] a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) # 1-D tensor `b` # [7, 9, 11] b = tf.constant([7, 9, 11], shape=[3]) # `a` * `b` # [ 58, 64] c = tf.matvec(a, b) # 3-D tensor `a` # [[[ 1, 2, 3], # [ 4, 5, 6]], # [[ 7, 8, 9], # [10, 11, 12]]] a = tf.constant(np.arange(1, 13, dtype=np.int32), shape=[2, 2, 3]) # 2-D tensor `b` # [[13, 14, 15], # [16, 17, 18]] b = tf.constant(np.arange(13, 19, dtype=np.int32), shape=[2, 3]) # `a` * `b` # [[ 86, 212], # [410, 563]] c = tf.matvec(a, b)
ValueTuple<object, object> normalize(object tensor, double ord, int axis, string name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
double
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
int
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
string
name - The name of the op.
Returns
-
ValueTuple<object, object>
ValueTuple<object, object> normalize(object tensor, double ord, Nullable<ValueTuple<int, int>> axis, string name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
double
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
Nullable<ValueTuple<int, int>>
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
string
name - The name of the op.
Returns
-
ValueTuple<object, object>
ValueTuple<object, object> normalize(object tensor, string ord, int axis, string name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
string
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
int
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
string
name - The name of the op.
Returns
-
ValueTuple<object, object>
ValueTuple<object, object> normalize(object tensor, string ord, Nullable<ValueTuple<int, int>> axis, string name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
string
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
Nullable<ValueTuple<int, int>>
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
string
name - The name of the op.
Returns
-
ValueTuple<object, object>
ValueTuple<object, object> normalize(object tensor, int ord, Nullable<ValueTuple<int, int>> axis, string name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
int
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
Nullable<ValueTuple<int, int>>
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
string
name - The name of the op.
Returns
-
ValueTuple<object, object>
ValueTuple<object, object> normalize(object tensor, int ord, int axis, string name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
int
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
int
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
string
name - The name of the op.
Returns
-
ValueTuple<object, object>
object normalize_dyn(object tensor, ImplicitContainer<T> ord, object axis, object name)
Normalizes `tensor` along dimension `axis` using specified norm. This uses
tf.linalg.norm
to compute the norm along `axis`. This function can compute several different vector norms (the 1-norm, the
Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and
matrix norms (Frobenius, 1-norm, 2-norm and inf-norm).
Parameters
-
object
tensor - `Tensor` of types `float32`, `float64`, `complex64`, `complex128`
-
ImplicitContainer<T>
ord - Order of the norm. Supported values are `'fro'`, `'euclidean'`, `1`, `2`, `np.inf` and any positive real number yielding the corresponding p-norm. Default is `'euclidean'` which is equivalent to Frobenius norm if `tensor` is a matrix and equivalent to 2-norm for vectors. Some restrictions apply: a) The Frobenius norm `'fro'` is not defined for vectors, b) If axis is a 2-tuple (matrix norm), only `'euclidean'`, '`fro'`, `1`, `2`, `np.inf` are supported. See the description of `axis` on how to compute norms for a batch of vectors or matrices stored in a tensor.
-
object
axis - If `axis` is `None` (the default), the input is considered a vector and a single vector norm is computed over the entire set of values in the tensor, i.e. `norm(tensor, ord=ord)` is equivalent to `norm(reshape(tensor, [-1]), ord=ord)`. If `axis` is a Python integer, the input is considered a batch of vectors, and `axis` determines the axis in `tensor` over which to compute vector norms. If `axis` is a 2-tuple of Python integers it is considered a batch of matrices and `axis` determines the axes in `tensor` over which to compute a matrix norm. Negative indices are supported. Example: If you are passing a tensor that can be either a matrix or a batch of matrices at runtime, pass `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are computed.
-
object
name - The name of the op.
Returns
-
object
Tensor pinv(IGraphNodeBase a, IGraphNodeBase rcond, bool validate_args, string name)
Compute the Moore-Penrose pseudo-inverse of one or more matrices. Calculate the [generalized inverse of a matrix](
https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse) using its
singular-value decomposition (SVD) and including all large singular values. The pseudo-inverse of a matrix `A`, is defined as: 'the matrix that 'solves'
[the least-squares problem] `A @ x = b`,' i.e., if `x_hat` is a solution, then
`A_pinv` is the matrix such that `x_hat = A_pinv @ b`. It can be shown that if
`U @ Sigma @ V.T = A` is the singular value decomposition of `A`, then
`A_pinv = V @ inv(Sigma) U^T`. [(Strang, 1980)][1] This function is analogous to [`numpy.linalg.pinv`](
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.pinv.html).
It differs only in default value of `rcond`. In `numpy.linalg.pinv`, the
default `rcond` is `1e-15`. Here the default is
`10. * max(num_rows, num_cols) * np.finfo(dtype).eps`.
Parameters
-
IGraphNodeBase
a - (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be pseudo-inverted.
-
IGraphNodeBase
rcond - `Tensor` of small singular value cutoffs. Singular values smaller (in modulus) than `rcond` * largest_singular_value (again, in modulus) are set to zero. Must broadcast against `tf.shape(a)[:-2]`. Default value: `10. * max(num_rows, num_cols) * np.finfo(a.dtype).eps`.
-
bool
validate_args - When `True`, additional assertions might be embedded in the graph. Default value: `False` (i.e., no graph assertions are added).
-
string
name - Python `str` prefixed to ops created by this function. Default value: 'pinv'.
Returns
object pinv_dyn(object a, object rcond, ImplicitContainer<T> validate_args, object name)
Compute the Moore-Penrose pseudo-inverse of one or more matrices. Calculate the [generalized inverse of a matrix](
https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse) using its
singular-value decomposition (SVD) and including all large singular values. The pseudo-inverse of a matrix `A`, is defined as: 'the matrix that 'solves'
[the least-squares problem] `A @ x = b`,' i.e., if `x_hat` is a solution, then
`A_pinv` is the matrix such that `x_hat = A_pinv @ b`. It can be shown that if
`U @ Sigma @ V.T = A` is the singular value decomposition of `A`, then
`A_pinv = V @ inv(Sigma) U^T`. [(Strang, 1980)][1] This function is analogous to [`numpy.linalg.pinv`](
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.pinv.html).
It differs only in default value of `rcond`. In `numpy.linalg.pinv`, the
default `rcond` is `1e-15`. Here the default is
`10. * max(num_rows, num_cols) * np.finfo(dtype).eps`.
Parameters
-
object
a - (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be pseudo-inverted.
-
object
rcond - `Tensor` of small singular value cutoffs. Singular values smaller (in modulus) than `rcond` * largest_singular_value (again, in modulus) are set to zero. Must broadcast against `tf.shape(a)[:-2]`. Default value: `10. * max(num_rows, num_cols) * np.finfo(a.dtype).eps`.
-
ImplicitContainer<T>
validate_args - When `True`, additional assertions might be embedded in the graph. Default value: `False` (i.e., no graph assertions are added).
-
object
name - Python `str` prefixed to ops created by this function. Default value: 'pinv'.
Returns
-
object
Tensor tridiagonal_matmul(IGraphNodeBase diagonals, IGraphNodeBase rhs, string diagonals_format, string name)
Multiplies tridiagonal matrix by matrix. `diagonals` is representation of 3-diagonal NxN matrix, which depends on
`diagonals_format`. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. If `sequence` format, `diagonals` is list or tuple of three tensors:
`[superdiag, maindiag, subdiag]`, each having shape [..., M]. Last element
of `superdiag` first element of `subdiag` are ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `sequence` format is recommended as the one with the best performance. `rhs` is matrix to the right of multiplication. It has shape `[..., M, N]`. Example:
Parameters
-
IGraphNodeBase
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
IGraphNodeBase
rhs - A `Tensor` of shape [..., M, N] and with the same dtype as `diagonals`.
-
string
diagonals_format - one of `sequence`, or `compact`. Default is `compact`.
-
string
name - A name to give this `Op` (optional).
Returns
-
Tensor
- A `Tensor` of shape [..., M, N] containing the result of multiplication.
Show Example
superdiag = tf.constant([-1, -1, 0], dtype=tf.float64) maindiag = tf.constant([2, 2, 2], dtype=tf.float64) subdiag = tf.constant([0, -1, -1], dtype=tf.float64) diagonals = [superdiag, maindiag, subdiag] rhs = tf.constant([[1, 1], [1, 1], [1, 1]], dtype=tf.float64) x = tf.linalg.tridiagonal_matmul(diagonals, rhs, diagonals_format='sequence')
Tensor tridiagonal_matmul(ValueTuple<IGraphNodeBase, object, object> diagonals, IGraphNodeBase rhs, string diagonals_format, string name)
Multiplies tridiagonal matrix by matrix. `diagonals` is representation of 3-diagonal NxN matrix, which depends on
`diagonals_format`. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. If `sequence` format, `diagonals` is list or tuple of three tensors:
`[superdiag, maindiag, subdiag]`, each having shape [..., M]. Last element
of `superdiag` first element of `subdiag` are ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `sequence` format is recommended as the one with the best performance. `rhs` is matrix to the right of multiplication. It has shape `[..., M, N]`. Example:
Parameters
-
ValueTuple<IGraphNodeBase, object, object>
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
IGraphNodeBase
rhs - A `Tensor` of shape [..., M, N] and with the same dtype as `diagonals`.
-
string
diagonals_format - one of `sequence`, or `compact`. Default is `compact`.
-
string
name - A name to give this `Op` (optional).
Returns
-
Tensor
- A `Tensor` of shape [..., M, N] containing the result of multiplication.
Show Example
superdiag = tf.constant([-1, -1, 0], dtype=tf.float64) maindiag = tf.constant([2, 2, 2], dtype=tf.float64) subdiag = tf.constant([0, -1, -1], dtype=tf.float64) diagonals = [superdiag, maindiag, subdiag] rhs = tf.constant([[1, 1], [1, 1], [1, 1]], dtype=tf.float64) x = tf.linalg.tridiagonal_matmul(diagonals, rhs, diagonals_format='sequence')
Tensor tridiagonal_matmul(IEnumerable<IGraphNodeBase> diagonals, IGraphNodeBase rhs, string diagonals_format, string name)
Multiplies tridiagonal matrix by matrix. `diagonals` is representation of 3-diagonal NxN matrix, which depends on
`diagonals_format`. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. If `sequence` format, `diagonals` is list or tuple of three tensors:
`[superdiag, maindiag, subdiag]`, each having shape [..., M]. Last element
of `superdiag` first element of `subdiag` are ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `sequence` format is recommended as the one with the best performance. `rhs` is matrix to the right of multiplication. It has shape `[..., M, N]`. Example:
Parameters
-
IEnumerable<IGraphNodeBase>
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
IGraphNodeBase
rhs - A `Tensor` of shape [..., M, N] and with the same dtype as `diagonals`.
-
string
diagonals_format - one of `sequence`, or `compact`. Default is `compact`.
-
string
name - A name to give this `Op` (optional).
Returns
-
Tensor
- A `Tensor` of shape [..., M, N] containing the result of multiplication.
Show Example
superdiag = tf.constant([-1, -1, 0], dtype=tf.float64) maindiag = tf.constant([2, 2, 2], dtype=tf.float64) subdiag = tf.constant([0, -1, -1], dtype=tf.float64) diagonals = [superdiag, maindiag, subdiag] rhs = tf.constant([[1, 1], [1, 1], [1, 1]], dtype=tf.float64) x = tf.linalg.tridiagonal_matmul(diagonals, rhs, diagonals_format='sequence')
object tridiagonal_matmul_dyn(object diagonals, object rhs, ImplicitContainer<T> diagonals_format, object name)
Multiplies tridiagonal matrix by matrix. `diagonals` is representation of 3-diagonal NxN matrix, which depends on
`diagonals_format`. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. If `sequence` format, `diagonals` is list or tuple of three tensors:
`[superdiag, maindiag, subdiag]`, each having shape [..., M]. Last element
of `superdiag` first element of `subdiag` are ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `sequence` format is recommended as the one with the best performance. `rhs` is matrix to the right of multiplication. It has shape `[..., M, N]`. Example:
Parameters
-
object
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
object
rhs - A `Tensor` of shape [..., M, N] and with the same dtype as `diagonals`.
-
ImplicitContainer<T>
diagonals_format - one of `sequence`, or `compact`. Default is `compact`.
-
object
name - A name to give this `Op` (optional).
Returns
-
object
- A `Tensor` of shape [..., M, N] containing the result of multiplication.
Show Example
superdiag = tf.constant([-1, -1, 0], dtype=tf.float64) maindiag = tf.constant([2, 2, 2], dtype=tf.float64) subdiag = tf.constant([0, -1, -1], dtype=tf.float64) diagonals = [superdiag, maindiag, subdiag] rhs = tf.constant([[1, 1], [1, 1], [1, 1]], dtype=tf.float64) x = tf.linalg.tridiagonal_matmul(diagonals, rhs, diagonals_format='sequence')
Tensor tridiagonal_solve(IGraphNodeBase diagonals, IGraphNodeBase rhs, string diagonals_format, bool transpose_rhs, bool conjugate_rhs, string name, bool partial_pivoting)
Solves tridiagonal systems of equations. The input can be supplied in various formats: `matrix`, `sequence` and
`compact`, specified by the `diagonals_format` arg. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. In `sequence` format, `diagonals` are supplied as a tuple or list of three
tensors of shapes `[..., N]`, `[..., M]`, `[..., N]` representing
superdiagonals, diagonals, and subdiagonals, respectively. `N` can be either
`M-1` or `M`; in the latter case, the last element of superdiagonal and the
first element of subdiagonal will be ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `compact` format is recommended as the one with best performance. In case
you need to cast a tensor into a compact format manually, use
tf.gather_nd
.
An example for a tensor of shape [m, m]:
Regardless of the `diagonals_format`, `rhs` is a tensor of shape `[..., M]` or
`[..., M, K]`. The latter allows to simultaneously solve K systems with the
same left-hand sides and K different right-hand sides. If `transpose_rhs`
is set to `True` the expected shape is `[..., M]` or `[..., K, M]`. The batch dimensions, denoted as `...`, must be the same in `diagonals` and
`rhs`. The output is a tensor of the same shape as `rhs`: either `[..., M]` or
`[..., M, K]`. The op isn't guaranteed to raise an error if the input matrix is not
invertible. tf.debugging.check_numerics
can be applied to the output to
detect invertibility problems. **Note**: with large batch sizes, the computation on the GPU may be slow, if
either `partial_pivoting=True` or there are multiple right-hand sides
(`K > 1`). If this issue arises, consider if it's possible to disable pivoting
and have `K = 1`, or, alternatively, consider using CPU. On CPU, solution is computed via Gaussian elimination with or without partial
pivoting, depending on `partial_pivoting` parameter. On GPU, Nvidia's cuSPARSE
library is used: https://docs.nvidia.com/cuda/cusparse/index.html#gtsv
Parameters
-
IGraphNodeBase
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
IGraphNodeBase
rhs - A `Tensor` of shape [..., M] or [..., M, K] and with the same dtype as `diagonals`.
-
string
diagonals_format - one of `matrix`, `sequence`, or `compact`. Default is `compact`.
-
bool
transpose_rhs - If `True`, `rhs` is transposed before solving (has no effect if the shape of rhs is [..., M]).
-
bool
conjugate_rhs - If `True`, `rhs` is conjugated before solving.
-
string
name - A name to give this `Op` (optional).
-
bool
partial_pivoting - whether to perform partial pivoting. `True` by default. Partial pivoting makes the procedure more stable, but slower. Partial pivoting is unnecessary in some cases, including diagonally dominant and symmetric positive definite matrices (see e.g. theorem 9.12 in [1]).
Returns
-
Tensor
- A `Tensor` of shape [..., M] or [..., M, K] containing the solutions.
Show Example
rhs = tf.constant([...]) matrix = tf.constant([[...]]) m = matrix.shape[0] dummy_idx = [0, 0] # An arbitrary element to use as a dummy indices = [[[i, i + 1] for i in range(m - 1)] + [dummy_idx], # Superdiagonal [[i, i] for i in range(m)], # Diagonal [dummy_idx] + [[i + 1, i] for i in range(m - 1)]] # Subdiagonal diagonals=tf.gather_nd(matrix, indices) x = tf.linalg.tridiagonal_solve(diagonals, rhs)
Tensor tridiagonal_solve(ValueTuple<IGraphNodeBase, object, object> diagonals, IGraphNodeBase rhs, string diagonals_format, bool transpose_rhs, bool conjugate_rhs, string name, bool partial_pivoting)
Solves tridiagonal systems of equations. The input can be supplied in various formats: `matrix`, `sequence` and
`compact`, specified by the `diagonals_format` arg. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. In `sequence` format, `diagonals` are supplied as a tuple or list of three
tensors of shapes `[..., N]`, `[..., M]`, `[..., N]` representing
superdiagonals, diagonals, and subdiagonals, respectively. `N` can be either
`M-1` or `M`; in the latter case, the last element of superdiagonal and the
first element of subdiagonal will be ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `compact` format is recommended as the one with best performance. In case
you need to cast a tensor into a compact format manually, use
tf.gather_nd
.
An example for a tensor of shape [m, m]:
Regardless of the `diagonals_format`, `rhs` is a tensor of shape `[..., M]` or
`[..., M, K]`. The latter allows to simultaneously solve K systems with the
same left-hand sides and K different right-hand sides. If `transpose_rhs`
is set to `True` the expected shape is `[..., M]` or `[..., K, M]`. The batch dimensions, denoted as `...`, must be the same in `diagonals` and
`rhs`. The output is a tensor of the same shape as `rhs`: either `[..., M]` or
`[..., M, K]`. The op isn't guaranteed to raise an error if the input matrix is not
invertible. tf.debugging.check_numerics
can be applied to the output to
detect invertibility problems. **Note**: with large batch sizes, the computation on the GPU may be slow, if
either `partial_pivoting=True` or there are multiple right-hand sides
(`K > 1`). If this issue arises, consider if it's possible to disable pivoting
and have `K = 1`, or, alternatively, consider using CPU. On CPU, solution is computed via Gaussian elimination with or without partial
pivoting, depending on `partial_pivoting` parameter. On GPU, Nvidia's cuSPARSE
library is used: https://docs.nvidia.com/cuda/cusparse/index.html#gtsv
Parameters
-
ValueTuple<IGraphNodeBase, object, object>
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
IGraphNodeBase
rhs - A `Tensor` of shape [..., M] or [..., M, K] and with the same dtype as `diagonals`.
-
string
diagonals_format - one of `matrix`, `sequence`, or `compact`. Default is `compact`.
-
bool
transpose_rhs - If `True`, `rhs` is transposed before solving (has no effect if the shape of rhs is [..., M]).
-
bool
conjugate_rhs - If `True`, `rhs` is conjugated before solving.
-
string
name - A name to give this `Op` (optional).
-
bool
partial_pivoting - whether to perform partial pivoting. `True` by default. Partial pivoting makes the procedure more stable, but slower. Partial pivoting is unnecessary in some cases, including diagonally dominant and symmetric positive definite matrices (see e.g. theorem 9.12 in [1]).
Returns
-
Tensor
- A `Tensor` of shape [..., M] or [..., M, K] containing the solutions.
Show Example
rhs = tf.constant([...]) matrix = tf.constant([[...]]) m = matrix.shape[0] dummy_idx = [0, 0] # An arbitrary element to use as a dummy indices = [[[i, i + 1] for i in range(m - 1)] + [dummy_idx], # Superdiagonal [[i, i] for i in range(m)], # Diagonal [dummy_idx] + [[i + 1, i] for i in range(m - 1)]] # Subdiagonal diagonals=tf.gather_nd(matrix, indices) x = tf.linalg.tridiagonal_solve(diagonals, rhs)
object tridiagonal_solve_dyn(object diagonals, object rhs, ImplicitContainer<T> diagonals_format, ImplicitContainer<T> transpose_rhs, ImplicitContainer<T> conjugate_rhs, object name, ImplicitContainer<T> partial_pivoting)
Solves tridiagonal systems of equations. The input can be supplied in various formats: `matrix`, `sequence` and
`compact`, specified by the `diagonals_format` arg. In `matrix` format, `diagonals` must be a tensor of shape `[..., M, M]`, with
two inner-most dimensions representing the square tridiagonal matrices.
Elements outside of the three diagonals will be ignored. In `sequence` format, `diagonals` are supplied as a tuple or list of three
tensors of shapes `[..., N]`, `[..., M]`, `[..., N]` representing
superdiagonals, diagonals, and subdiagonals, respectively. `N` can be either
`M-1` or `M`; in the latter case, the last element of superdiagonal and the
first element of subdiagonal will be ignored. In `compact` format the three diagonals are brought together into one tensor
of shape `[..., 3, M]`, with last two dimensions containing superdiagonals,
diagonals, and subdiagonals, in order. Similarly to `sequence` format,
elements `diagonals[..., 0, M-1]` and `diagonals[..., 2, 0]` are ignored. The `compact` format is recommended as the one with best performance. In case
you need to cast a tensor into a compact format manually, use
tf.gather_nd
.
An example for a tensor of shape [m, m]:
Regardless of the `diagonals_format`, `rhs` is a tensor of shape `[..., M]` or
`[..., M, K]`. The latter allows to simultaneously solve K systems with the
same left-hand sides and K different right-hand sides. If `transpose_rhs`
is set to `True` the expected shape is `[..., M]` or `[..., K, M]`. The batch dimensions, denoted as `...`, must be the same in `diagonals` and
`rhs`. The output is a tensor of the same shape as `rhs`: either `[..., M]` or
`[..., M, K]`. The op isn't guaranteed to raise an error if the input matrix is not
invertible. tf.debugging.check_numerics
can be applied to the output to
detect invertibility problems. **Note**: with large batch sizes, the computation on the GPU may be slow, if
either `partial_pivoting=True` or there are multiple right-hand sides
(`K > 1`). If this issue arises, consider if it's possible to disable pivoting
and have `K = 1`, or, alternatively, consider using CPU. On CPU, solution is computed via Gaussian elimination with or without partial
pivoting, depending on `partial_pivoting` parameter. On GPU, Nvidia's cuSPARSE
library is used: https://docs.nvidia.com/cuda/cusparse/index.html#gtsv
Parameters
-
object
diagonals - A `Tensor` or tuple of `Tensor`s describing left-hand sides. The shape depends of `diagonals_format`, see description above. Must be `float32`, `float64`, `complex64`, or `complex128`.
-
object
rhs - A `Tensor` of shape [..., M] or [..., M, K] and with the same dtype as `diagonals`.
-
ImplicitContainer<T>
diagonals_format - one of `matrix`, `sequence`, or `compact`. Default is `compact`.
-
ImplicitContainer<T>
transpose_rhs - If `True`, `rhs` is transposed before solving (has no effect if the shape of rhs is [..., M]).
-
ImplicitContainer<T>
conjugate_rhs - If `True`, `rhs` is conjugated before solving.
-
object
name - A name to give this `Op` (optional).
-
ImplicitContainer<T>
partial_pivoting - whether to perform partial pivoting. `True` by default. Partial pivoting makes the procedure more stable, but slower. Partial pivoting is unnecessary in some cases, including diagonally dominant and symmetric positive definite matrices (see e.g. theorem 9.12 in [1]).
Returns
-
object
- A `Tensor` of shape [..., M] or [..., M, K] containing the solutions.
Show Example
rhs = tf.constant([...]) matrix = tf.constant([[...]]) m = matrix.shape[0] dummy_idx = [0, 0] # An arbitrary element to use as a dummy indices = [[[i, i + 1] for i in range(m - 1)] + [dummy_idx], # Superdiagonal [[i, i] for i in range(m)], # Diagonal [dummy_idx] + [[i + 1, i] for i in range(m - 1)]] # Subdiagonal diagonals=tf.gather_nd(matrix, indices) x = tf.linalg.tridiagonal_solve(diagonals, rhs)