dpnp.scipy.linalg.solve_triangular

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

Solve the equation a x = b for x, assuming a is a triangular matrix.

For full documentation refer to scipy.linalg.solve_triangular.

Parameters:
a(..., M, M) {dpnp.ndarray, usm_ndarray}

A triangular matrix.

b{(M,), (..., M, N)} {dpnp.ndarray, usm_ndarray}

Right-hand side matrix in a x = b.

trans{0, 1, 2, 'N', 'T', 'C'}, optional

Type of system to solve:

trans

system

0 or 'N'

a x = b

1 or 'T'

a^T x = b

2 or 'C'

a^H x = b

Default: 0.

lower{bool, array_like of bool}, optional

Use only data contained in the lower triangle of a, instead of the upper one. An array or a sequence is accepted if all its values are equal.

Default: False.

unit_diagonalbool, optional

If True, diagonal elements of a are assumed to be 1 and will not be referenced.

Default: False.

overwrite_bbool, optional

Allow overwriting data in b (may enhance performance).

Default: False.

check_finitebool, 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:
x{(M,), (..., M, N)} dpnp.ndarray

Solution to the system a x = b. Its shape is the shape of b, with the batch dimensions of a and b broadcast.

Raises:
dpnp.linalg.LinAlgError

If a is singular: it has a zero on the diagonal and unit_diagonal=False.

ValueError

If a is not square, if b is 0-D, if the shapes of a and b are incompatible, if trans is none of the values above, if lower is empty, not bool or its values are not all equal, or if check_finite=True and a or b contains infinities or NaNs.

Warning

This function synchronizes in order to check the diagonal of a for zeros unless unit_diagonal=True, to validate array elements when check_finite=True, and to read lower or unit_diagonal given as a dpnp array.

See also

dpnp.scipy.linalg.cho_solve()

Solve a linear set equations using the Cholesky factorization of a matrix.

dpnp.scipy.linalg.lu_solve()

Solve a linear set equations using the LU factorization of a matrix.

dpnp.linalg.solve()

Solve a linear matrix equation.

Notes

Unlike SciPy:

  • a zero-size batch is supported and gives an empty solution;

  • a trans other than the values above raises ValueError, while SciPy may solve the transposed system for it;

  • integer and boolean inputs are treated as arrays of the default floating point data type of the device, as in the other linear algebra functions of DPNP, with no DeprecationWarning for boolean input.

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 dpnp as np
>>> a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]])
>>> b = np.array([4, 2, 4, 2])
>>> x = np.scipy.linalg.solve_triangular(a, b, lower=True)
>>> x
array([ 1.33333333, -0.66666667,  2.66666667, -1.33333333])
>>> a @ x  # Check the result
array([4., 2., 4., 2.])