determinant of a complex matrix in PyTorch

泪湿孤枕 提交于 2021-01-28 05:00:07

问题


Is there a way to calculate the determinant of a complex matrix in PyTroch?

torch.det is not implemented for 'ComplexFloat'


回答1:


Unfortunately it's not implemented currently. One way would be to implement your own version or simply use np.linalg.det. Here is a short function which computes the determinant of a complex matrix that I wrote using LU-decomposition:

def complex_det(A):
    def complex_diag(A):
        return torch.view_as_complex(torch.stack((A.real.diag(), A.imag.diag()),dim=1))
    #Perform LU decomposition to matrix A:
    A_LU, pivots = A.lu()
    P, A_L, A_U = torch.lu_unpack(A_LU, pivots)
    #Det. of multiplied matrices is multiplcation of det.:
    det = torch.prod(complex_diag(A_L)) * torch.prod(complex_diag(A_U)) * torch.det(P.real) #Could probably calculate det(P) [which is +-1] efficiently using Sylvester's determinant identity
    return det
#Test it:
A = torch.view_as_complex(torch.randn(3,3,2))
complex_det(A)


来源:https://stackoverflow.com/questions/63928808/determinant-of-a-complex-matrix-in-pytorch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!