Cytnx-dev / Cytnx

Project Cytnx, A Cross-section of Python & C++,Tensor network library
Apache License 2.0
35 stars 14 forks source link

cytnx.linalg.ExpM always returns complex UniTensor #493

Closed chiamin closed 1 month ago

chiamin commented 1 month ago

cytnx.linalg.ExpM(T) returns a complex UniTensor even if the input tensor is real. It can be demonstrated as follows.

T = cytnx.UniTensor.uniform([2,2], low=0., high=1.)
Q = cytnx.linalg.ExpM(T)
print(T.dtype_str())
print(Q.dtype_str())
kaihsin commented 1 month ago

ExpM rely on diagonalization, which eigenvalues is not always real right? ExpH is the the one that can always guarantee that

chiamin commented 1 month ago

You are right! I will close this issue.

ianmccul commented 1 month ago

Well, you should be careful, that if the matrix doesn't have a complete set of real eigenvalues then diagonalization is a really terrible way of calculating the exponential! There are much better ways of calculating the matrix exponential; I use https://www.maths.uq.edu.au/expokit/ that uses a Pade approximation. Scipy also uses Pade.

kaihsin commented 1 month ago

Yes. There are also other approximation methods via iteration.

On Sat, Oct 19, 2024, 05:26 Ian McCulloch @.***> wrote:

Well, you should be careful, that if the matrix doesn't have a complete set of real eigenvalues then diagonalization is a really terrible way of calculating the exponential! There are much better ways of calculating the matrix exponential; I use https://www.maths.uq.edu.au/expokit/ that uses a Pade approximation. Scipy also uses Pade.

— Reply to this email directly, view it on GitHub https://github.com/Cytnx-dev/Cytnx/issues/493#issuecomment-2423716418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFCX3SKML6PZNYNOTRO6C3DZ4IQUJAVCNFSM6AAAAABQHF3XBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRTG4YTMNBRHA . You are receiving this because you commented.Message ID: @.***>