提交 aec6d167 authored 作者: Benjamin Scellier's avatar Benjamin Scellier

file theano/gpuarray/tests/test_fft.py

上级 e869f5ef
...@@ -7,7 +7,6 @@ import theano.tensor as T ...@@ -7,7 +7,6 @@ import theano.tensor as T
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
import theano.gpuarray.fft import theano.gpuarray.fft
import numpy.fft
from .config import mode_with_gpu from .config import mode_with_gpu
...@@ -37,7 +36,7 @@ class TestFFT(unittest.TestCase): ...@@ -37,7 +36,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp = (np.asarray(res_rfft[:, :, 0]) + res_rfft_comp = (np.asarray(res_rfft[:, :, 0]) +
1j * np.asarray(res_rfft[:, :, 1])) 1j * np.asarray(res_rfft[:, :, 1]))
rfft_ref = numpy.fft.rfft(inputs_val, axis=1) rfft_ref = np.fft.rfft(inputs_val, axis=1)
utt.assert_allclose(rfft_ref, res_rfft_comp) utt.assert_allclose(rfft_ref, res_rfft_comp)
...@@ -72,7 +71,7 @@ class TestFFT(unittest.TestCase): ...@@ -72,7 +71,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp = (np.asarray(res_rfft[:, :, :, 0]) + res_rfft_comp = (np.asarray(res_rfft[:, :, :, 0]) +
1j * np.asarray(res_rfft[:, :, :, 1])) 1j * np.asarray(res_rfft[:, :, :, 1]))
rfft_ref = numpy.fft.rfftn(inputs_val, axes=(1, 2)) rfft_ref = np.fft.rfftn(inputs_val, axes=(1, 2))
utt.assert_allclose(rfft_ref, res_rfft_comp, atol=1e-4, rtol=1e-4) utt.assert_allclose(rfft_ref, res_rfft_comp, atol=1e-4, rtol=1e-4)
...@@ -91,7 +90,7 @@ class TestFFT(unittest.TestCase): ...@@ -91,7 +90,7 @@ class TestFFT(unittest.TestCase):
utt.assert_allclose(inputs_val, np.asarray(res_ifft)) utt.assert_allclose(inputs_val, np.asarray(res_ifft))
inputs_val = numpy.random.random((1, N, N, 2)).astype('float32') inputs_val = np.random.random((1, N, N, 2)).astype('float32')
inputs = theano.shared(inputs_val) inputs = theano.shared(inputs_val)
irfft = theano.gpuarray.fft.cuirfft(inputs) irfft = theano.gpuarray.fft.cuirfft(inputs)
...@@ -123,7 +122,7 @@ class TestFFT(unittest.TestCase): ...@@ -123,7 +122,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp = (np.asarray(res_rfft[:, :, :, 0]) + res_rfft_comp = (np.asarray(res_rfft[:, :, :, 0]) +
1j * np.asarray(res_rfft[:, :, :, 1])) 1j * np.asarray(res_rfft[:, :, :, 1]))
rfft_ref = numpy.fft.rfftn(inputs_val, axes=(1, 2)) rfft_ref = np.fft.rfftn(inputs_val, axes=(1, 2))
utt.assert_allclose(rfft_ref / N, res_rfft_comp, atol=1e-4, rtol=1e-4) utt.assert_allclose(rfft_ref / N, res_rfft_comp, atol=1e-4, rtol=1e-4)
...@@ -146,7 +145,7 @@ class TestFFT(unittest.TestCase): ...@@ -146,7 +145,7 @@ class TestFFT(unittest.TestCase):
f_irfft = theano.function([], irfft, mode=mode_with_gpu) f_irfft = theano.function([], irfft, mode=mode_with_gpu)
res_irfft = f_irfft() res_irfft = f_irfft()
irfft_ref = numpy.fft.irfftn(inputs_ref, axes=(1, 2)) irfft_ref = np.fft.irfftn(inputs_ref, axes=(1, 2))
utt.assert_allclose(irfft_ref * N, res_irfft, atol=1e-4, rtol=1e-4) utt.assert_allclose(irfft_ref * N, res_irfft, atol=1e-4, rtol=1e-4)
...@@ -195,7 +194,7 @@ class TestFFT(unittest.TestCase): ...@@ -195,7 +194,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp = (np.asarray(res_rfft[:, :, :, 0]) + res_rfft_comp = (np.asarray(res_rfft[:, :, :, 0]) +
1j * np.asarray(res_rfft[:, :, :, 1])) 1j * np.asarray(res_rfft[:, :, :, 1]))
rfft_ref = numpy.fft.rfftn(inputs_val, s=(M, M), axes=(1, 2)) rfft_ref = np.fft.rfftn(inputs_val, s=(M, M), axes=(1, 2))
utt.assert_allclose(rfft_ref, res_rfft_comp, atol=1e-4, rtol=1e-4) utt.assert_allclose(rfft_ref, res_rfft_comp, atol=1e-4, rtol=1e-4)
...@@ -214,7 +213,7 @@ class TestFFT(unittest.TestCase): ...@@ -214,7 +213,7 @@ class TestFFT(unittest.TestCase):
res_irfft = f_irfft() res_irfft = f_irfft()
inputs_ref = inputs_val[:, :, :, 0] + 1j * inputs_val[:, :, :, 1] inputs_ref = inputs_val[:, :, :, 0] + 1j * inputs_val[:, :, :, 1]
irfft_ref = numpy.fft.irfftn(inputs_ref, s=(M, M), axes=(1, 2)) * M irfft_ref = np.fft.irfftn(inputs_ref, s=(M, M), axes=(1, 2)) * M
utt.assert_allclose(irfft_ref, res_irfft, atol=1e-4, rtol=1e-4) utt.assert_allclose(irfft_ref, res_irfft, atol=1e-4, rtol=1e-4)
...@@ -243,12 +242,12 @@ class TestFFT(unittest.TestCase): ...@@ -243,12 +242,12 @@ class TestFFT(unittest.TestCase):
utt.verify_grad(f_irfft, [inputs_val], eps=eps) utt.verify_grad(f_irfft, [inputs_val], eps=eps)
def test_params(self): def test_params(self):
inputs_val = numpy.random.random((1, N)).astype('float32') inputs_val = np.random.random((1, N)).astype('float32')
inputs = theano.shared(inputs_val) inputs = theano.shared(inputs_val)
self.assertRaises(ValueError, theano.gpuarray.fft.curfft, inputs, norm=123) self.assertRaises(ValueError, theano.gpuarray.fft.curfft, inputs, norm=123)
inputs_val = numpy.random.random((1, N // 2 + 1, 2)).astype('float32') inputs_val = np.random.random((1, N // 2 + 1, 2)).astype('float32')
inputs = theano.shared(inputs_val) inputs = theano.shared(inputs_val)
self.assertRaises(ValueError, theano.gpuarray.fft.cuirfft, inputs, norm=123) self.assertRaises(ValueError, theano.gpuarray.fft.cuirfft, inputs, norm=123)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论