Commit 8daf1615 authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'more_tests' into 'master'

More tests

See merge request !82
parents 68823ce1 d886c279
Pipeline #12145 passed with stages
in 11 minutes and 14 seconds
......@@ -101,7 +101,7 @@ Starting with a fresh Ubuntu installation move to a folder like
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure && sudo make install
autoreconf -i && ./configure && make -j4 && sudo make install
cd ..
- Finally, NIFTy:
......@@ -135,7 +135,7 @@ For pyHealpix, use:
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure --prefix=$HOME/.local && make install
autoreconf -i && ./configure --prefix=$HOME/.local && make -j4 && make install
cd ..
### Installation on OS X 10.11
......@@ -156,7 +156,7 @@ may cause trouble.
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure && sudo make install
autoreconf -i && ./configure --prefix=`python-config --prefix` && make -j4 && sudo make install
cd ..
- Install NIFTy:
......
......@@ -19,109 +19,109 @@
import unittest
import numpy as np
from numpy.testing import assert_,\
assert_equal, \
assert_allclose
from numpy.testing import assert_equal,\
assert_allclose
from nifty.config import dependency_injector as di
from nifty import Field,\
RGSpace,\
LMSpace,\
GLSpace,\
FieldArray, \
RGRGTransformation, \
LMGLTransformation, \
LMHPTransformation, \
FFTOperator
RGSpace,\
LMSpace,\
RGRGTransformation, \
LMGLTransformation, \
LMHPTransformation, \
FFTOperator
from itertools import product
from test.common import expand
from nose.plugins.skip import SkipTest
def _harmonic_type(itp):
otp=itp
if otp==np.float64:
otp=np.complex128
elif otp==np.float32:
otp=np.complex64
otp = itp
if otp == np.float64:
otp = np.complex128
elif otp == np.float32:
otp = np.complex64
return otp
def _get_rtol(tp):
if (tp==np.float64) or (tp==np.complex128):
if (tp == np.float64) or (tp == np.complex128):
return 1e-10
else:
return 1e-5
class Misc_Tests(unittest.TestCase):
def test_RG_distance_1D(self):
for dim1 in [10,11]:
for zc1 in [False,True]:
for d in [0.1,1,3.7]:
foo = RGSpace([dim1],zerocenter=zc1)
res = foo.get_distance_array('not')
assert_equal(res[zc1*(dim1//2)],0.)
def test_RG_distance_2D(self):
for dim1 in [10,11]:
for dim2 in [9,28]:
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')
assert_equal(res[zc1*(dim1//2),zc2*(dim2//2)],0.)
def test_fft1D(self):
for dim1 in [10,11]:
for zc1 in [False,True]:
for zc2 in [False,True]:
for d in [0.1,1,3.7]:
for itp in [np.float64,np.complex128,np.float32,np.complex64]:
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))
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(self):
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]:
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))
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([10, 11], [False, True], [0.1, 1, 3.7]))
def test_RG_distance_1D(self, dim1, zc1, d):
foo = RGSpace([dim1], zerocenter=zc1, distances=d)
res = foo.get_distance_array('not')
assert_equal(res[zc1 * (dim1 // 2)], 0.)
@expand(product([10, 11], [9, 28], [False, True], [False, True],
[0.1, 1, 3.7]))
def test_RG_distance_2D(self, dim1, dim2, zc1, zc2, d):
foo = RGSpace([dim1, dim2], zerocenter=[zc1, zc2], distances=d)
res = foo.get_distance_array('not')
assert_equal(res[zc1 * (dim1 // 2), zc2 * (dim2 // 2)], 0.)
@expand(product(["numpy", "fftw"], [10, 11], [False, True], [False, True],
[0.1, 1, 3.7],
[np.float64, np.complex128, np.float32, np.complex64]))
def test_fft1D(self, module, dim1, zc1, zc2, d, itp):
if module == "fftw" and "pyfftw" not in di:
raise SkipTest
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)
@expand(product(["numpy", "fftw"], [10, 11], [9, 12], [False, True],
[False, True], [False, True], [False, True], [0.1, 1, 3.7],
[np.float64, np.complex128, np.float32, np.complex64]))
def test_fft2D(self, module, dim1, dim2, zc1, zc2, zc3, zc4, d, itp):
if module == "fftw" and "pyfftw" not in di:
raise SkipTest
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)
@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:
raise SkipTest
for lm in [0,3,6,11,30]:
for tp in [np.float64,np.complex128,np.float32,np.complex64]:
tol=_get_rtol(tp)
a = LMSpace(lmax=lm)
b = LMGLTransformation.get_codomain(a)
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)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val,rtol=tol,atol=tol)
def test_sht2(self):
tol = _get_rtol(tp)
a = LMSpace(lmax=lm)
b = LMGLTransformation.get_codomain(a)
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)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val, rtol=tol, atol=tol)
@expand(product([128, 256],
[np.float64, np.complex128, np.float32, np.complex64]))
def test_sht2(self, lm, tp):
if 'pyHealpix' not in di:
raise SkipTest
for lm in [128,256]:
for tp in [np.float64,np.complex128,np.float32,np.complex64]:
a = LMSpace(lmax=lm)
b = LMHPTransformation.get_codomain(a)
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)
out = fft.inverse_times(fft.times(inp))
assert_allclose(inp.val, out.val,rtol=1e-3,atol=1e-3)
a = LMSpace(lmax=lm)
b = LMHPTransformation.get_codomain(a)
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)
out = fft.inverse_times(fft.times(inp))
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