# Matrix_exp gives unexpected result on complex matrix

Hi, I am happy to find PyTorch support for complex numbers, but when I used torch.matrix_exp, it returned unexpected result.
I think torch.matrix_exp may have the same function as scipy.linalg.expm, and they return same result on real matrix:

``````import numpy as np
from scipy.linalg import expm
a=np.zeros((2,2),dtype=np.float64)
a[0,1]=1
a[1,0]=1
b=expm(a)
print(b)
``````

[[1.54308063 1.17520119]
[1.17520119 1.54308063]]

``````import torch
a=torch.zeros(2,2,dtype=torch.float64)
a[0,1]=1
a[1,0]=1
b=torch.matrix_exp(a)
print(b)
``````

tensor([[1.5431, 1.1752],
[1.1752, 1.5431]], dtype=torch.float64)

But the result differs on complex matrix:

``````import numpy as np
from scipy.linalg import expm
a=np.zeros((2,2),dtype=np.complex128)
a[0,1]=1
a[1,0]=1
b=expm(a)
print(b)
``````

[[1.54308063+0.j 1.17520119+0.j]
[1.17520119+0.j 1.54308063+0.j]]

``````import torch
a=torch.zeros(2,2,dtype=torch.complex128)
a[0,1]=1
a[1,0]=1
b=torch.matrix_exp(a)
print(b)
``````

tensor([[-10.9104+0.j, 1.6732+0.j],
[ 1.6732+0.j, -10.9104+0.j]], dtype=torch.complex128)

I am using PyTorch 1.7.0, Python 3.8.5
Thanks

Hi!

Support for complex numbers with `matrix_exp` was added yesterday: https://github.com/pytorch/pytorch/pull/48363
You can install a nightly build and it should work fine now!

Thanks, it helps a lot