torch.cholesky_inverse¶
- torch.cholesky_inverse(L, upper=False, *, out=None) Tensor ¶
計算給定一個複數 Hermitian 矩陣或實數對稱正定矩陣的 Cholesky 分解的逆矩陣。
令 為複數 Hermitian 矩陣或實數對稱正定矩陣, 為其 Cholesky 分解,使得
其中 在 是複數時是共軛轉置,在 是實數值時是轉置。
計算逆矩陣 。
支援 float、double、cfloat 和 cdouble 資料類型輸入。 也支援批次的矩陣,並且如果 是一個矩陣批次,則輸出具有相同的批次維度。
- 參數
- 關鍵字參數
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)