mindspore.scipy.linalg.solve_triangular

mindspore.scipy.linalg.solve_triangular(a, b, trans=0, lower=False, unit_diagonal=False, overwrite_b=False, debug=None, check_finite=True)[source]

Assuming a is a batched triangular matrix, solve the equation

\[a x = b\]

Note

  • solve_triangular is not supported on Windows platform yet.

  • Only float32, float64, int32, int64 are supported Tensor dtypes. If Tensor with dtype int32 or int64 is passed, it will be cast to mstype.float64.

  • The floating point error will accumulate when the size of input matrix gets larger. Substituting result x back into \(a x = b\) would be a way to evaluate the result. If the input shape is large enough, using float64 instead of float32 is also a way to mitigate the error.

Parameters
  • a (Tensor) – A non-singular triangular matrix of shape \((M, M)\).

  • b (Tensor) – A Tensor of shape \((M,)\) or \((M, N)\). Right-hand side matrix in \(a x = b\).

  • lower (bool, optional) – Use only data contained in the lower triangle of a. Default: False.

  • trans (0, 1, 2, 'N', 'T', 'C', optional) –

    Type of system to solve. Default: 0.

    trans

    system

    0 or ‘N’

    a x = b

    1 or ‘T’

    a^T x = b

    2 or ‘C’

    a^H x = b

  • unit_diagonal (bool, optional) – If True, diagonal elements of \(a\) are assumed to be 1 and will not be referenced. Default: False.

  • overwrite_b (bool, optional) – Allow overwriting data in \(b\) (may enhance performance). Default: False.

  • debug (None) – Not implemented now. Default: None.

  • check_finite (bool, optional) – Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Default: True.

Returns

Tensor of shape \((M,)\) or \((M, N)\), which is the solution to the system \(a x = b\). Shape of \(x\) matches \(b\).

Raises
Supported Platforms:

CPU GPU

Examples

Solve the lower triangular system \(a x = b\), where:

     [3  0  0  0]       [4]
a =  [2  1  0  0]   b = [2]
     [1  0  1  0]       [4]
     [1  1  1  1]       [2]
>>> import numpy as onp
>>> from mindspore.common import Tensor
>>> import mindspore.numpy as mnp
>>> from mindspore.scipy.linalg import solve_triangular
>>> a = Tensor(onp.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]], onp.float64))
>>> b = Tensor(onp.array([4, 2, 4, 2], onp.float64))
>>> x = solve_triangular(a, b, lower=True, unit_diagonal=False, trans='N')
>>> print(x)
[ 1.33333333 -0.66666667  2.66666667 -1.33333333]
>>> print(mnp.dot(a, x))  # Check the result
[4. 2. 4. 2.]