import torch
A = torch.randn(100, 100).tril()
B = torch.randn(100, 1)
X = torch.gesv(B, A)[0]
X_ = torch.trtrs(B, A, False)[0]
X__ = torch.potrs(B, A, False) # solution for (A.A_t)X = B
print("gesv error: ", torch.dist(A.matmul(X), B))
print("trtrs error: ", torch.dist(A.matmul(X_), B))
print("potrs error: ", torch.dist(A.matmul(A.t()).matmul(X__), B))
gesv error: 80.30836486816406
trtrs error: inf
potrs error: nan
The following simple script says that the current implementations of
torch.trtrs,torch.potrsare not stable with high dimensional linear equations. These methods are useful, especially when working with Cholesky decomposition.Output: