Skip to content

Instantly share code, notes, and snippets.

@liaocs2008
Last active March 29, 2017 21:55
Show Gist options
  • Select an option

  • Save liaocs2008/629111e3279a7bd0cfcaea0b1ef65491 to your computer and use it in GitHub Desktop.

Select an option

Save liaocs2008/629111e3279a7bd0cfcaea0b1ef65491 to your computer and use it in GitHub Desktop.
"""
real part
[[ 2.98023224e-08 0.00000000e+00 2.98023224e-08]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00]]
img part
[[ 0.00000000e+00 0.00000000e+00 0.00000000e+00]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00]
[ 0.00000000e+00 2.98023224e-08 0.00000000e+00]]
real part
[[[[ 9.79645666e+00 4.05509353e-01 -5.98364770e-02]
[ -3.55478082e-01 1.95642087e+00 -2.57848706e-01]
[ -2.45258212e-03 1.69161871e-01 1.00241494e+00]]
[[ -4.37298611e+00 -2.96933994e+00 2.48340973e+00]
[ -1.71750426e+00 1.20498252e+00 2.00737816e+00]
[ -1.02334494e+00 -1.72791123e+00 1.49052728e+00]]]]
img part
[[[[ 0. 0.74940148 0. ]
[-0.90688866 0.68082649 -0.64381433]
[ 0.90688866 -0.43813284 0.64381433]]
[[ 0. -0.73076117 0. ]
[ 0.29543054 0.28315097 -1.53902638]
[-0.29543054 0.94440503 1.53902638]]]]
"""
import numpy as np
import theano
import theano.tensor as T
from theano.tensor import fft
def test1():
x = T.matrix('x', dtype=theano.config.floatX)
rfft = fft.rfft(x)
f_rfft = theano.function([x], rfft)
a = np.random.random([3,4]).astype(np.float32)
res1 = np.fft.rfft(a)
res2 = f_rfft(a)
print "real part"
print res2[..., 0] - np.real(res1)
print "img part"
print res2[..., 1] - np.imag(res1)
def test2():
x = T.tensor4('x', dtype=theano.config.floatX)
rfft = fft.rfft(x)
f_rfft = theano.function([x], rfft)
a = np.random.random([1,2,3,4]).astype(np.float32)
res1 = np.fft.rfft(a)
res2 = f_rfft(a)
print "real part"
print res2[..., 0] - np.real(res1)
print "img part"
print res2[..., 1] - np.imag(res1)
if __name__ == "__main__":
test1()
test2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment