Rate this Page

torch.linalg.lu_solve#

torch.linalg.lu_solve(LU,pivots,B,*,left=True,adjoint=False,out=None)Tensor#

Computes the solution of a square system of linear equations with a unique solution given an LU decomposition.

LettingK\mathbb{K} beR\mathbb{R} orC\mathbb{C},this function computes the solutionXKn×kX \in \mathbb{K}^{n \times k} of thelinear system associated toAKn×n,BKn×kA \in \mathbb{K}^{n \times n}, B \in \mathbb{K}^{n \times k}, which is defined as

AX=BAX = B

whereAA is given factorized as returned bylu_factor().

Ifleft= False, this function returns the matrixXKn×kX \in \mathbb{K}^{n \times k} that solves the system

Ifadjoint= True (andleft= True), given an LU factorization ofAAthis function function returns theXKn×kX \in \mathbb{K}^{n \times k} that solves the system

whereAHA^{\text{H}} is the conjugate transpose whenAA is complex, and thetranspose whenAA is real-valued. Theleft= False case is analogous.

Supports inputs of float, double, cfloat and cdouble dtypes.Also supports batches of matrices, and if the inputs are batches of matrices thenthe output has the same batch dimensions.

Parameters
  • LU (Tensor) – tensor of shape(*, n, n) (or(*, k, k) ifleft= True)where* is zero or more batch dimensions as returned bylu_factor().

  • pivots (Tensor) – tensor of shape(*, n) (or(*, k) ifleft= True)where* is zero or more batch dimensions as returned bylu_factor().

  • B (Tensor) – right-hand side tensor of shape(*, n, k).

Keyword Arguments
  • left (bool,optional) – whether to solve the systemAX=BAX=B orXA=BXA = B. Default:True.

  • adjoint (bool,optional) – whether to solve the systemAX=BAX=B orAHX=BA^{\text{H}}X = B. Default:False.

  • out (Tensor,optional) – output tensor. Ignored ifNone. Default:None.

Examples:

>>>A=torch.randn(3,3)>>>LU,pivots=torch.linalg.lu_factor(A)>>>B=torch.randn(3,2)>>>X=torch.linalg.lu_solve(LU,pivots,B)>>>torch.allclose(A@X,B)True>>>B=torch.randn(3,3,2)# Broadcasting rules apply: A is broadcasted>>>X=torch.linalg.lu_solve(LU,pivots,B)>>>torch.allclose(A@X,B)True>>>B=torch.randn(3,5,3)>>>X=torch.linalg.lu_solve(LU,pivots,B,left=False)>>>torch.allclose(X@A,B)True>>>B=torch.randn(3,3,4)# Now solve for A^T>>>X=torch.linalg.lu_solve(LU,pivots,B,adjoint=True)>>>torch.allclose(A.mT@X,B)True