def test_dotsht(lm, tp): tol = 10*_get_rtol(tp) a = ift.LMSpace(lmax=lm) b = ift.GLSpace(nlat=lm + 1) 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)
def test_weight(): s1 = ift.RGSpace((10, )) f = ift.Field.full(s1, 10.) f2 = f.weight(1) assert_equal(f.weight(1).local_data, f2.local_data) assert_equal(f.total_volume(), 1) assert_equal(f.total_volume(0), 1) assert_equal(f.total_volume((0, )), 1) assert_equal(f.scalar_weight(), 0.1) assert_equal(f.scalar_weight(0), 0.1) assert_equal(f.scalar_weight((0, )), 0.1) s1 = ift.GLSpace(10) f = ift.Field.full(s1, 10.) assert_equal(f.scalar_weight(), None) assert_equal(f.scalar_weight(0), None) assert_equal(f.scalar_weight((0, )), None)
# 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 itertools import product # Currently it is not possible to parametrize fixtures. But this will # hopefully be fixed in the future. # https://docs.pytest.org/en/latest/proposals/parametrize_with_fixtures.html SPACES = [ ift.GLSpace(15), ift.RGSpace(64, distances=.789), ift.RGSpace([32, 32], distances=.789) ] SEEDS = [4, 78, 23] PARAMS = product(SEEDS, SPACES) @pytest.fixture(params=PARAMS) def field(request): np.random.seed(request.param[0]) S = ift.ScalingOperator(1., request.param[1]) s = S.draw_sample() return ift.MultiField.from_dict({'s1': s})['s1']
def testContractionOperator(spaces, wgt, dtype): dom = (ift.RGSpace(10), ift.RGSpace(13), ift.GLSpace(5), ift.HPSpace(4)) _check_repr(ift.ContractionOperator(dom, spaces, wgt))
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__() @pmp('sp', _p_RG_spaces) def testLOSResponse(sp, dtype): starts = np.random.randn(len(sp.shape), 10) ends = np.random.randn(len(sp.shape), 10) sigma_low = 1e-4 * np.random.randn(10)
# 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) rand1 = ift.Field.from_random('normal', domain=(space1, space2)) rand2 = ift.Field.from_random('normal', domain=(space1, space2))
def testContractionOperator(spaces, wgt, dtype): dom = (ift.RGSpace(10), ift.RGSpace(13), ift.GLSpace(5), ift.HPSpace(4)) op = ift.ContractionOperator(dom, spaces, wgt) ift.extra.consistency_check(op, dtype, dtype)
f2 = f.weight(1) assert_equal(f.weight(1).local_data, f2.local_data) assert_equal(f.total_volume(), 1) assert_equal(f.total_volume(0), 1) assert_equal(f.total_volume((0, )), 1) assert_equal(f.scalar_weight(), 0.1) assert_equal(f.scalar_weight(0), 0.1) assert_equal(f.scalar_weight((0, )), 0.1) s1 = ift.GLSpace(10) f = ift.Field.full(s1, 10.) assert_equal(f.scalar_weight(), None) assert_equal(f.scalar_weight(0), None) assert_equal(f.scalar_weight((0, )), None) @pmp('dom', [ift.RGSpace(10), ift.GLSpace(10)]) @pmp('dt', [np.float64, np.complex128]) def test_reduction(dom, dt): s1 = ift.Field.full(dom, dt(1.)) assert_allclose(s1.mean(), 1.) assert_allclose(s1.mean(0), 1.) assert_allclose(s1.var(), 0., atol=1e-14) assert_allclose(s1.var(0), 0., atol=1e-14) assert_allclose(s1.std(), 0., atol=1e-14) assert_allclose(s1.std(0), 0., atol=1e-14) def test_err(): s1 = ift.RGSpace((10, )) s2 = ift.RGSpace((11, )) f1 = ift.Field.full(s1, 27)