Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.triangular_solve function

PyTorch torch.triangular_solve function


PyTorch torch reference manual PyTorch torch reference manual

torch.triangular_solve is a function in PyTorch used to solve triangular systems of linear equations. It solves AX = B, where A is a triangular matrix.

Function definition

torch.triangular_solve(A, B, upper, transpose, unitriangular)

Parameter Description


Usage examples

Example

import

torch

Create an upper triangular coefficient matrix

A

=

torch.

tensor

(

[

[

3.0

,

1.0

,

2.0

]

,

                 

[

0.0

,

2.0

,

1.0

]

,

                 

[

0.0

,

0.0

,

1.0

]

]

)

Right-hand side vector

B

=

torch.

tensor

(

[

9.0

,

5.0

,

2.0

]

)

Solve AX = B

X

=

torch.

triangular_solve

(

B.

unsqueeze

(

1

)

,

A

,

upper

=

True

)

print

(

"Solution X:"

)

print

(

X.

solution

)

The output is:

解 X:

tensor([[1.],

        [2.],

        [2.]])


PyTorch torch reference manual PyTorch torch reference manual