评价此页

torch.cholesky_solve#

torch.cholesky_solve(B, L, upper=False, *, out=None) Tensor#

Computes the solution of a system of linear equations with complex Hermitian or real symmetric positive-definite lhs given its Cholesky decomposition.

Let AA be a complex Hermitian or real symmetric positive-definite matrix, and LL its Cholesky decomposition such that

A=LLHA = LL^{\text{H}}

where LHL^{\text{H}} is the conjugate transpose when LL is complex, and the transpose when LL is real-valued.

返回以下线性方程组的解 XX

AX=BAX = B

支持 float、double、cfloat 和 cdouble 数据类型。还支持矩阵批次,如果 AABB 是矩阵批次,则输出具有相同的批次维度。

参数
  • B (Tensor) – 右侧张量,形状为 (*, n, k),其中 * 是零个或多个批次维度

  • L (Tensor) – 张量,形状为 (*, n, n),其中 * 是零个或多个批次维度,由对称或厄米正定矩阵的下三角或上三角乔列斯基分解组成。

  • upper (bool, optional) – 指示 LL 是下三角还是上三角的标志。默认为 False

关键字参数

out (Tensor, optional) – 输出张量。如果为 None 则忽略。默认为 None

示例

>>> A = torch.randn(3, 3)
>>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
>>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
>>> B = torch.randn(3, 2)
>>> torch.cholesky_solve(B, L)
tensor([[ -8.1625,  19.6097],
        [ -5.8398,  14.2387],
        [ -4.3771,  10.4173]])
>>> A.inverse() @  B
tensor([[ -8.1626,  19.6097],
        [ -5.8398,  14.2387],
        [ -4.3771,  10.4173]])

>>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
>>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
>>> L = torch.linalg.cholesky(A)
>>> B = torch.randn(2, 1, dtype=torch.complex64)
>>> X = torch.cholesky_solve(B, L)
>>> torch.dist(X, A.inverse() @ B)
tensor(1.6881e-5)