torch.cholesky_inverse¶
- torch.cholesky_inverse(L, upper=False, *, out=None) Tensor ¶
计算给定 Cholesky 分解的复 Hermitian 或实对称正定矩阵的逆矩阵。
设 为复 Hermitian 或实对称正定矩阵, 为其 Cholesky 分解,使得
其中 是当 为复数时的共轭转置,当 为实值时的转置。
计算逆矩阵 。
支持 float、double、cfloat 和 cdouble dtypes 的输入。也支持矩阵批处理,如果 是矩阵批处理,则输出具有相同的批处理维度。
- 参数
- 关键字参数
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 >>> torch.cholesky_inverse(L) tensor([[ 1.9314, 1.2251, -0.0889], [ 1.2251, 2.4439, 0.2122], [-0.0889, 0.2122, 0.1412]]) >>> A.inverse() tensor([[ 1.9314, 1.2251, -0.0889], [ 1.2251, 2.4439, 0.2122], [-0.0889, 0.2122, 0.1412]]) >>> 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) >>> torch.dist(torch.inverse(A), torch.cholesky_inverse(L)) tensor(5.6358e-7)