Hi Abhi!



 planet:

input = np.array([[2,4,6],[3,5,7],[1,6,8]], dtype=np.float32) 
eigval_all, eigvec_all = tf.self_adjoint_eig(input)

Pytorch equivalent:
torch.symeig(torch.tensor(input), eigenvectors=True)


Your problem is that you are passing a matrix that is not symmetric
to eigenvalue routines that require symmetric (or self-adjoint) matrices.
Pytorch doesn’t verify that the matrix is symmetric and simply uses,
by default, its upper triangle.
Note that you can reproduce the tensorflow result by telling
torch.symeig() to use the lower triangle or by transposing its input:
>>> import torch
>>> torch.__version__
'1.9.0'
>>> t = torch.tensor ([[2,4,6],[3,5,7],[1,6,8]], dtype = torch.float)
>>> torch.symeig (t, upper = True)
torch.return_types.symeig(
eigenvalues=tensor([-1.7482, -0.3348, 17.0831]),
eigenvectors=tensor([]))
>>> torch.symeig (t, upper = False)
torch.return_types.symeig(
eigenvalues=tensor([-0.9423,  2.6310, 13.3113]),
eigenvectors=tensor([]))
>>> torch.symeig (t.T, upper = True)
torch.return_types.symeig(
eigenvalues=tensor([-0.9423,  2.6310, 13.3113]),
eigenvectors=tensor([]))

Be aware, given that your input matrix is asymmetric, the above results
are not correct; the correct result is the one with complex eigenvalues
that you obtained with torch.eig().
Best.
K. Frank