Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

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

ax=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 ax=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 ax=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 ax=b. Shape of x matches b.

Raises
Supported Platforms:

CPU GPU

Examples

Solve the lower triangular system ax=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.]