Commit 3c6a47d2 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

improve tests

parent 096ee7a0
Pipeline #12114 passed with stage
in 4 minutes and 42 seconds
...@@ -34,6 +34,9 @@ from nifty import Field,\ ...@@ -34,6 +34,9 @@ from nifty import Field,\
LMHPTransformation, \ LMHPTransformation, \
FFTOperator FFTOperator
from itertools import product
from test.common import expand
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
def _harmonic_type(itp): def _harmonic_type(itp):
...@@ -44,87 +47,79 @@ def _harmonic_type(itp): ...@@ -44,87 +47,79 @@ def _harmonic_type(itp):
otp=np.complex64 otp=np.complex64
return otp return otp
def _sub_fft1D(module): def _get_rtol(tp):
for dim1 in [10,11]: if (tp==np.float64) or (tp==np.complex128):
for zc1 in [False,True]: return 1e-10
for zc2 in [False,True]: else:
for d in [0.1,1,3.7]: return 1e-5
for itp in [np.float64,np.complex128,np.float32,np.complex64]:
a = RGSpace(dim1, zerocenter=zc1, distances=d)
b = RGRGTransformation.get_codomain(a, zerocenter=zc2)
fft = FFTOperator(domain=a, target=b, domain_dtype=itp, target_dtype=_harmonic_type(itp),module=module)
inp = Field.from_random(domain=a,random_type='normal',std=7,mean=3,dtype=itp)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val)
def _sub_fft2D(module):
for dim1 in [10,11]:
for dim2 in [9,12]:
for zc1 in [False,True]:
for zc2 in [False,True]:
for zc3 in [False,True]:
for zc4 in [False,True]:
for d in [0.1,1,3.7]:
for itp in [np.float64,np.complex128,np.float32,np.complex64]:
a = RGSpace([dim1,dim2], zerocenter=[zc1,zc2], distances=d)
b = RGRGTransformation.get_codomain(a, zerocenter=[zc3,zc4])
fft = FFTOperator(domain=a, target=b, domain_dtype=itp, target_dtype=_harmonic_type(itp),module=module)
inp = Field.from_random(domain=a,random_type='normal',std=7,mean=3,dtype=itp)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val)
class Misc_Tests(unittest.TestCase): class Misc_Tests(unittest.TestCase):
def test_RG_distance_1D(self): @expand(product([10,11],[False,True],[0.1,1,3.7]))
for dim1 in [10,11]: def test_RG_distance_1D(self,dim1,zc1,d):
for zc1 in [False,True]: foo = RGSpace([dim1],zerocenter=zc1,distances=d)
for d in [0.1,1,3.7]:
foo = RGSpace([dim1],zerocenter=zc1)
res = foo.get_distance_array('not') res = foo.get_distance_array('not')
assert_equal(res[zc1*(dim1//2)],0.) assert_equal(res[zc1*(dim1//2)],0.)
def test_RG_distance_2D(self): @expand(product([10,11],[9,28],[False,True],[False,True],[0.1,1,3.7]))
for dim1 in [10,11]: def test_RG_distance_2D(self, dim1, dim2, zc1, zc2, d):
for dim2 in [9,28]: foo = RGSpace([dim1,dim2],zerocenter=[zc1,zc2],distances=d)
for zc1 in [False,True]:
for zc2 in [False,True]:
for d in [0.1,1,3.7]:
foo = RGSpace([dim1,dim2],zerocenter=[zc1,zc2])
res = foo.get_distance_array('not') res = foo.get_distance_array('not')
assert_equal(res[zc1*(dim1//2),zc2*(dim2//2)],0.) assert_equal(res[zc1*(dim1//2),zc2*(dim2//2)],0.)
def test_fft1D_numpy(self): @expand(product(["numpy","fftw"],[10,11],[False,True],[False,True],[0.1,1,3.7],
_sub_fft1D("numpy") [np.float64,np.complex128,np.float32,np.complex64]))
def test_fft1D_pyfftw(self): def test_fft1D(self,module,dim1,zc1,zc2,d,itp):
if 'pyfftw' not in di: if module=="fftw" and "pyfftw" not in di:
raise SkipTest raise SkipTest
_sub_fft1D("fftw") tol=_get_rtol(itp)
a = RGSpace(dim1, zerocenter=zc1, distances=d)
b = RGRGTransformation.get_codomain(a, zerocenter=zc2)
fft = FFTOperator(domain=a, target=b, domain_dtype=itp,
target_dtype=_harmonic_type(itp),module=module)
inp = Field.from_random(domain=a,random_type='normal',std=7,mean=3,
dtype=itp)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val,rtol=tol,atol=tol)
def test_fft2D_numpy(self): @expand(product(["numpy","fftw"],[10,11],[9,12],[False,True],[False,True],
_sub_fft2D("numpy") [False,True], [False,True],[0.1,1,3.7],
def test_fft2D_pyfftw(self): [np.float64,np.complex128,np.float32,np.complex64]))
if 'pyfftw' not in di: def test_fft2D(self,module,dim1,dim2,zc1,zc2,zc3,zc4,d,itp):
if module=="fftw" and "pyfftw" not in di:
raise SkipTest raise SkipTest
_sub_fft2D("fftw") tol=_get_rtol(itp)
a = RGSpace([dim1,dim2], zerocenter=[zc1,zc2], distances=d)
b = RGRGTransformation.get_codomain(a, zerocenter=[zc3,zc4])
fft = FFTOperator(domain=a, target=b, domain_dtype=itp,
target_dtype=_harmonic_type(itp),module=module)
inp = Field.from_random(domain=a,random_type='normal',std=7,mean=3,
dtype=itp)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val,rtol=tol,atol=tol)
def test_sht(self): @expand(product([0,3,6,11,30],
[np.float64,np.complex128,np.float32,np.complex64]))
def test_sht(self,lm,tp):
if 'pyHealpix' not in di: if 'pyHealpix' not in di:
raise SkipTest raise SkipTest
for lm in [0,3,6,11,30]: tol=_get_rtol(tp)
for tp in [np.float64,np.complex128,np.float32,np.complex64]:
a = LMSpace(lmax=lm) a = LMSpace(lmax=lm)
b = LMGLTransformation.get_codomain(a) b = LMGLTransformation.get_codomain(a)
fft = FFTOperator(domain=a, target=b, domain_dtype=tp, target_dtype=tp) fft = FFTOperator(domain=a, target=b, domain_dtype=tp, target_dtype=tp)
inp = Field.from_random(domain=a,random_type='normal',std=7,mean=3,dtype=tp) inp = Field.from_random(domain=a,random_type='normal',std=7,mean=3,
dtype=tp)
out = fft.inverse_times(fft.times(inp)) out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val) assert_allclose(inp.val, out.val,rtol=tol,atol=tol)
def test_sht2(self): @expand(product([128,256],
[np.float64,np.complex128,np.float32,np.complex64]))
def test_sht2(self,lm,tp):
if 'pyHealpix' not in di: if 'pyHealpix' not in di:
raise SkipTest raise SkipTest
for lm in [128,256]:
for tp in [np.float64,np.complex128,np.float32,np.complex64]:
a = LMSpace(lmax=lm) a = LMSpace(lmax=lm)
b = LMHPTransformation.get_codomain(a) b = LMHPTransformation.get_codomain(a)
fft = FFTOperator(domain=a, target=b, domain_dtype=tp, target_dtype=tp) fft = FFTOperator(domain=a, target=b, domain_dtype=tp, target_dtype=tp)
inp = Field.from_random(domain=a,random_type='normal',std=1,mean=0,dtype=tp) inp = Field.from_random(domain=a,random_type='normal',std=1,mean=0,
dtype=tp)
out = fft.inverse_times(fft.times(inp)) out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val,rtol=1e-3,atol=1e-3) assert_allclose(inp.val, out.val,rtol=1e-3,atol=1e-3)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment