def test_constructor(lmax, mmax, expected): if 'error' in expected: with assert_raises(expected['error']): ift.LMSpace(lmax, mmax) else: l = ift.LMSpace(lmax, mmax) for key, value in expected.items(): assert_equal(getattr(l, key), value)
def test_dotsht2(lm, tp): tol = 10*_get_rtol(tp) a = ift.LMSpace(lmax=lm) b = ift.HPSpace(nside=lm//2) fft = ift.HarmonicTransformOperator(domain=a, target=b) inp = ift.Field.from_random( domain=a, random_type='normal', std=1, mean=0, dtype=tp) out = fft.times(inp) v1 = np.sqrt(out.vdot(out)) v2 = np.sqrt(inp.vdot(fft.adjoint_times(out))) assert_allclose(v1, v2, rtol=tol, atol=tol)
# Copyright(C) 2013-2019 Max-Planck-Society # # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik. import numpy as np import pytest import nifty5 as ift from ..common import list2fixture _h_RG_spaces = [ ift.RGSpace(7, distances=0.2, harmonic=True), ift.RGSpace((12, 46), distances=(.2, .3), harmonic=True) ] _h_spaces = _h_RG_spaces + [ift.LMSpace(17)] _p_RG_spaces = [ ift.RGSpace(19, distances=0.7), ift.RGSpace((1, 2, 3, 6), distances=(0.2, 0.25, 0.34, .8)) ] _p_spaces = _p_RG_spaces + [ift.HPSpace(17), ift.GLSpace(8, 13)] _pow_spaces = [ift.PowerSpace(ift.RGSpace((17, 38), harmonic=True))] pmp = pytest.mark.parametrize dtype = list2fixture([np.float64, np.complex128]) def _check_repr(op): op.__repr__()
# along with this program. If not, see <http://www.gnu.org/licenses/>. # # Copyright(C) 2013-2019 Max-Planck-Society # # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik. from numpy.testing import assert_allclose, assert_equal import nifty5 as ift from ..common import list2fixture space1 = list2fixture([ ift.RGSpace(4), ift.PowerSpace(ift.RGSpace((4, 4), harmonic=True)), ift.LMSpace(5), ift.HPSpace(4), ift.GLSpace(4) ]) space2 = space1 def test_times_adjoint_times(space1, space2): cspace = (space1, space2) diag1 = ift.Field.from_random('normal', domain=space1) diag2 = ift.Field.from_random('normal', domain=space2) op1 = ift.DiagonalOperator(diag1, cspace, spaces=(0, )) op2 = ift.DiagonalOperator(diag2, cspace, spaces=(1, )) op = op2(op1)
from itertools import chain, product import pytest import nifty5 as ift import numpy as np from numpy.testing import assert_, assert_allclose, assert_equal, assert_raises pmp = pytest.mark.parametrize HARMONIC_SPACES = [ ift.RGSpace((8,), harmonic=True), ift.RGSpace((7, 8), harmonic=True), ift.RGSpace((6, 6), harmonic=True), ift.RGSpace((5, 5), harmonic=True), ift.RGSpace((4, 5, 7), harmonic=True), ift.LMSpace(6), ift.LMSpace(9) ] # Try all sensible kinds of combinations of spaces and binning parameters CONSISTENCY_CONFIGS_IMPLICIT = product(HARMONIC_SPACES, [None], [None, 3, 4], [True, False]) CONSISTENCY_CONFIGS_EXPLICIT = product(HARMONIC_SPACES, [[0., 1.3]], [None], [None]) CONSISTENCY_CONFIGS = chain(CONSISTENCY_CONFIGS_IMPLICIT, CONSISTENCY_CONFIGS_EXPLICIT) # [harmonic_partner, logarithmic, nbin, binbounds, expected] CONSTRUCTOR_CONFIGS = [ [1, False, None, None, { 'error': (ValueError, NotImplementedError)
def test_k_length_array(lmax, expected): l = ift.LMSpace(lmax) assert_allclose(l.get_k_length_array().to_global_data(), expected)
def test_dvol(): assert_allclose(ift.LMSpace(5).dvol, 1.)
def test_property_ret_type(attribute): l = ift.LMSpace(7, 5) assert_(isinstance(getattr(l, attribute), int))
from types import LambdaType import pytest from numpy.testing import assert_ import nifty5 as ift pmp = pytest.mark.parametrize @pmp('attr_expected_type', [['harmonic', bool], ['shape', tuple], ['size', int]]) @pmp('space', [ ift.RGSpace(4), ift.PowerSpace(ift.RGSpace((4, 4), harmonic=True)), ift.LMSpace(5), ift.HPSpace(4), ift.GLSpace(4) ]) def test_property_ret_type(space, attr_expected_type): assert_( isinstance(getattr(space, attr_expected_type[0]), attr_expected_type[1])) @pmp('method_expected_type', [['get_k_length_array', ift.Field], ['get_fft_smoothing_kernel_function', 2.0, LambdaType]]) @pmp('space', [ift.RGSpace(4, harmonic=True), ift.LMSpace(5)]) def test_method_ret_type(space, method_expected_type): assert_(
out = fft.times(inp) v1 = np.sqrt(out.vdot(out)) v2 = np.sqrt(inp.vdot(fft.adjoint_times(out))) assert_allclose(v1, v2, rtol=tol, atol=tol) def test_dotsht2(lm, tp): tol = 10*_get_rtol(tp) a = ift.LMSpace(lmax=lm) b = ift.HPSpace(nside=lm//2) fft = ift.HarmonicTransformOperator(domain=a, target=b) inp = ift.Field.from_random( domain=a, random_type='normal', std=1, mean=0, dtype=tp) out = fft.times(inp) v1 = np.sqrt(out.vdot(out)) v2 = np.sqrt(inp.vdot(fft.adjoint_times(out))) assert_allclose(v1, v2, rtol=tol, atol=tol) @pmp('space', [ift.LMSpace(lmax=30, mmax=25)]) def test_normalisation(space, tp): tol = 10*_get_rtol(tp) cospace = space.get_default_codomain() fft = ift.HarmonicTransformOperator(space, cospace) inp = ift.Field.from_random( domain=space, random_type='normal', std=1, mean=2, dtype=tp) out = fft.times(inp) zero_idx = tuple([0]*len(space.shape)) assert_allclose( inp.to_global_data()[zero_idx], out.integrate(), rtol=tol, atol=tol)
assert_equal(isinstance(getattr(f, attribute), desired_type), True) def _spec1(k): return 42 / (1. + k)**2 def _spec2(k): return 42 / (1. + k)**3 @pmp('space1', [ ift.RGSpace((8, ), harmonic=True), ift.RGSpace((8, 8), harmonic=True, distances=0.123) ]) @pmp('space2', [ift.RGSpace((8, ), harmonic=True), ift.LMSpace(12)]) def test_power_synthesize_analyze(space1, space2): np.random.seed(11) p1 = ift.PowerSpace(space1) fp1 = ift.PS_field(p1, _spec1) p2 = ift.PowerSpace(space2) fp2 = ift.PS_field(p2, _spec2) outer = np.outer(fp1.to_global_data(), fp2.to_global_data()) fp = ift.Field.from_global_data((p1, p2), outer) op1 = ift.create_power_operator((space1, space2), _spec1, 0) op2 = ift.create_power_operator((space1, space2), _spec2, 1) opfull = op2(op1) samples = 500