torch.cholesky_inverse¶
- torch.cholesky_inverse(L, upper=False, *, out=None) Tensor¶
計算給定複數 Hermitian 矩陣或實數對稱正定矩陣的 Cholesky 分解後的逆矩陣。
令 為複數 Hermitian 矩陣或實數對稱正定矩陣,\(L\) 是其 Cholesky 分解,使得
其中,當 \(L\) 是複數時 \(L^{\text{H}}\) 是共軛轉置,當 \(L\) 是實數時是轉置。
計算逆矩陣 \(A^{-1}\)。
支援 float、double、cfloat 和 cdouble 資料型別的輸入。也支援矩陣批次輸入,如果 \(A\) 是矩陣批次,則輸出具有相同的批次維度。
- 引數
- 關鍵字引數
out (Tensor, 可選) – 輸出張量。如果為 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)