Commit 23c5f455 authored by Martin Reinecke's avatar Martin Reinecke

PEP8 and test tweaking

parent 339398ad
Pipeline #13205 passed with stage
in 5 minutes and 15 seconds
...@@ -31,8 +31,9 @@ dependency_injector = keepers.DependencyInjector( ...@@ -31,8 +31,9 @@ dependency_injector = keepers.DependencyInjector(
'pyHealpix', 'pyHealpix',
'plotly']) 'plotly'])
dependency_injector.register(('pyfftw','fftw_mpi'), lambda z: hasattr(z, 'FFTW_MPI')) dependency_injector.register(('pyfftw', 'fftw_mpi'),
dependency_injector.register(('pyfftw','fftw_scalar')) lambda z: hasattr(z, 'FFTW_MPI'))
dependency_injector.register(('pyfftw', 'fftw_scalar'))
# Initialize the variables # Initialize the variables
variable_fft_module = keepers.Variable( variable_fft_module = keepers.Variable(
......
...@@ -634,9 +634,11 @@ class ScalarFFT(Transform): ...@@ -634,9 +634,11 @@ class ScalarFFT(Transform):
# perform the transformation # perform the transformation
if fftw_scalar is not None: if fftw_scalar is not None:
if self.codomain.harmonic: if self.codomain.harmonic:
result_val = fftw_scalar.interfaces.numpy_fft.fftn(local_val, axes=axes) result_val = fftw_scalar.interfaces.numpy_fft.fftn(
local_val, axes=axes)
else: else:
result_val = fftw_scalar.interfaces.numpy_fft.ifftn(local_val, axes=axes) result_val = fftw_scalar.interfaces.numpy_fft.ifftn(
local_val, axes=axes)
else: else:
if self.codomain.harmonic: if self.codomain.harmonic:
result_val = np.fft.fftn(local_val, axes=axes) result_val = np.fft.fftn(local_val, axes=axes)
......
...@@ -62,7 +62,7 @@ class FFTOperatorTests(unittest.TestCase): ...@@ -62,7 +62,7 @@ class FFTOperatorTests(unittest.TestCase):
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.)
@expand(product(["scalar","mpi"], [10, 11], [False, True], [False, True], @expand(product(["scalar", "mpi"], [10, 11], [False, True], [False, True],
[0.1, 1, 3.7], [0.1, 1, 3.7],
[np.float64, np.complex128, np.float32, np.complex64])) [np.float64, np.complex128, np.float32, np.complex64]))
def test_fft1D(self, module, dim1, zc1, zc2, d, itp): def test_fft1D(self, module, dim1, zc1, zc2, d, itp):
......
...@@ -28,30 +28,34 @@ from nifty import PowerSpace, RGSpace, Space, LMSpace ...@@ -28,30 +28,34 @@ from nifty import PowerSpace, RGSpace, Space, LMSpace
from types import NoneType from types import NoneType
from test.common import expand from test.common import expand
from itertools import product, chain from itertools import product, chain
#needed to check wether fftw is available # needed to check wether fftw is available
from d2o.config import dependency_injector as gdi from d2o.config import dependency_injector as gdi
from nose.plugins.skip import SkipTest
HARMONIC_SPACES = [RGSpace((8,), harmonic=True), HARMONIC_SPACES = [RGSpace((8,), harmonic=True),
RGSpace((7,), harmonic=True,zerocenter=True), RGSpace((7,), harmonic=True, zerocenter=True),
RGSpace((8,), harmonic=True,zerocenter=True), RGSpace((8,), harmonic=True, zerocenter=True),
RGSpace((7,8), harmonic=True), RGSpace((7, 8), harmonic=True),
RGSpace((7,8), harmonic=True, zerocenter=True), RGSpace((7, 8), harmonic=True, zerocenter=True),
RGSpace((6,6), harmonic=True, zerocenter=True), RGSpace((6, 6), harmonic=True, zerocenter=True),
RGSpace((7,5), harmonic=True, zerocenter=True), RGSpace((7, 5), harmonic=True, zerocenter=True),
RGSpace((5,5), harmonic=True), RGSpace((5, 5), harmonic=True),
RGSpace((4,5,7), harmonic=True), RGSpace((4, 5, 7), harmonic=True),
RGSpace((4,5,7), harmonic=True, zerocenter=True), RGSpace((4, 5, 7), harmonic=True, zerocenter=True),
LMSpace(6), LMSpace(6),
LMSpace(9)] LMSpace(9)]
#Try all sensible kinds of combinations of spaces, distributuion strategy and # Try all sensible kinds of combinations of spaces, distributuion strategy and
#binning parameters # binning parameters
_maybe_fftw = ["fftw"] if ('fftw_mpi' in gdi) else [] CONSISTENCY_CONFIGS_IMPLICIT = product(HARMONIC_SPACES,
["not", "equal", "fftw"],
CONSISTENCY_CONFIGS_IMPLICIT = product(HARMONIC_SPACES, ["not", "equal"] + _maybe_fftw, [None], [None, 3,4], [True, False]) [None], [None, 3, 4], [True, False])
CONSISTENCY_CONFIGS_EXPLICIT = product(HARMONIC_SPACES, ["not", "equal"] + _maybe_fftw, [[0.,1.3]],[None],[False]) CONSISTENCY_CONFIGS_EXPLICIT = product(HARMONIC_SPACES,
CONSISTENCY_CONFIGS = chain(CONSISTENCY_CONFIGS_IMPLICIT, CONSISTENCY_CONFIGS_EXPLICIT) ["not", "equal", "fftw"],
[[0., 1.3]], [None], [False])
CONSISTENCY_CONFIGS = chain(CONSISTENCY_CONFIGS_IMPLICIT,
CONSISTENCY_CONFIGS_EXPLICIT)
# [harmonic_partner, distribution_strategy, # [harmonic_partner, distribution_strategy,
# logarithmic, nbin, binbounds, expected] # logarithmic, nbin, binbounds, expected]
...@@ -128,27 +132,40 @@ class PowerSpaceInterfaceTest(unittest.TestCase): ...@@ -128,27 +132,40 @@ class PowerSpaceInterfaceTest(unittest.TestCase):
p = PowerSpace(r) p = PowerSpace(r)
assert_(isinstance(getattr(p, attribute), expected_type)) assert_(isinstance(getattr(p, attribute), expected_type))
class PowerSpaceConsistencyCheck(unittest.TestCase): class PowerSpaceConsistencyCheck(unittest.TestCase):
@expand(CONSISTENCY_CONFIGS) @expand(CONSISTENCY_CONFIGS)
def test_pipundexInversion(self, harmonic_partner, distribution_strategy, def test_pipundexInversion(self, harmonic_partner, distribution_strategy,
binbounds, nbin,logarithmic): binbounds, nbin, logarithmic):
if distribution_strategy == "fftw" and "fftw_mpi" not in gdi:
raise SkipTest
p = PowerSpace(harmonic_partner=harmonic_partner, p = PowerSpace(harmonic_partner=harmonic_partner,
distribution_strategy=distribution_strategy, distribution_strategy=distribution_strategy,
logarithmic=logarithmic, nbin=nbin, logarithmic=logarithmic, nbin=nbin,
binbounds=binbounds) binbounds=binbounds)
assert_equal(p.pindex.flatten()[p.pundex],np.arange(p.dim), assert_equal(p.pindex.flatten()[p.pundex], np.arange(p.dim),
err_msg='pundex is not right-inverse of pindex!') err_msg='pundex is not right-inverse of pindex!')
@expand(CONSISTENCY_CONFIGS) @expand(CONSISTENCY_CONFIGS)
def test_rhopindexConsistency(self, harmonic_partner, distribution_strategy, def test_rhopindexConsistency(self, harmonic_partner,
binbounds, nbin,logarithmic): distribution_strategy, binbounds, nbin,
logarithmic):
if distribution_strategy == "fftw" and "fftw_mpi" not in gdi:
raise SkipTest
p = PowerSpace(harmonic_partner=harmonic_partner,
distribution_strategy=distribution_strategy,
logarithmic=logarithmic, nbin=nbin,
binbounds=binbounds)
assert_equal(p.pindex.flatten().bincount(), p.rho, assert_equal(p.pindex.flatten().bincount(), p.rho,
err_msg='rho is not equal to pindex degeneracy') err_msg='rho is not equal to pindex degeneracy')
class PowerSpaceFunctionalityTest(unittest.TestCase): class PowerSpaceFunctionalityTest(unittest.TestCase):
@expand(CONSISTENCY_CONFIGS) @expand(CONSTRUCTOR_CONFIGS)
def test_constructor(self, harmonic_partner, distribution_strategy, def test_constructor(self, harmonic_partner, distribution_strategy,
logarithmic, nbin, binbounds, expected): logarithmic, nbin, binbounds, expected):
if distribution_strategy == "fftw" and "fftw_mpi" not in gdi:
raise SkipTest
if 'error' in expected: if 'error' in expected:
with assert_raises(expected['error']): with assert_raises(expected['error']):
PowerSpace(harmonic_partner=harmonic_partner, PowerSpace(harmonic_partner=harmonic_partner,
......
Markdown is supported
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