我们如何检查矩阵是 PSD 还是 PyTorch?

How can we check if a matrix is PSD is PyTorch?

在 Python 中有一个关于检查矩阵是否为 PSD 的 poste。我想知道我们如何在 PyTorch 中检查它?有那个功能吗?

尚未找到 PyTorch 函数,但您应该能够轻松确定它,类似于您链接的 post,通过检查矩阵是否对称以及所有特征值是否为non-negative:

def is_psd(mat):
    return bool((mat == mat.T).all() and (torch.eig(mat)[0][:,0]>=0).all())
#Test:
is_psd(torch.randn(2,2))