From 4351c81a0f1bbbc52e7d2971ed53af0110c3b696 Mon Sep 17 00:00:00 2001 From: Philipp Arras <parras@mpa-garching.mpg.de> Date: Thu, 7 Nov 2019 14:13:43 +0100 Subject: [PATCH] Add jacobian test --- nifty5/library/correlated_fields.py | 2 +- test/test_operators/test_jacobian.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nifty5/library/correlated_fields.py b/nifty5/library/correlated_fields.py index e3b04e93b..90d282924 100644 --- a/nifty5/library/correlated_fields.py +++ b/nifty5/library/correlated_fields.py @@ -128,7 +128,7 @@ class _Normalization(Operator): def __init__(self, domain): self._domain = self._target = makeDomain(domain) assert len(self._domain) == 1 - assert isinstance(domain[0], PowerSpace) + assert isinstance(self._domain[0], PowerSpace) hspace = self._domain[0].harmonic_partner pd = PowerDistributor(hspace, power_space=self._domain[0]) cst = pd.adjoint(full(pd.target, 1.)).to_global_data_rw() diff --git a/test/test_operators/test_jacobian.py b/test/test_operators/test_jacobian.py index 55c046c91..8323eec35 100644 --- a/test/test_operators/test_jacobian.py +++ b/test/test_operators/test_jacobian.py @@ -29,6 +29,11 @@ space = list2fixture([ ift.RGSpace(64, distances=.789), ift.RGSpace([32, 32], distances=.789) ]) +_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)] space1 = space seed = list2fixture([4, 78, 23]) @@ -163,3 +168,20 @@ def testDynamicModel(target, causal, minimum_phase, seed): # FIXME I dont know why smaller tol fails for 3D example ift.extra.check_jacobian_consistency( model, pos, tol=1e-5, ntries=20) + + +@pmp('h_space', _h_spaces) +@pmp('specialbinbounds', [True, False]) +@pmp('logarithmic', [True, False]) +@pmp('nbin', [3, None]) +def testNormalization(h_space, specialbinbounds, logarithmic, nbin): + if not specialbinbounds and (not logarithmic or nbin is not None): + return + if specialbinbounds: + binbounds = ift.PowerSpace.useful_binbounds(h_space, logarithmic, nbin) + else: + binbounds = None + dom = ift.PowerSpace(h_space, binbounds) + op = ift.library.correlated_fields._Normalization(dom) + pos = 0.1*ift.from_random('normal', op.domain) + ift.extra.check_jacobian_consistency(op, pos) -- GitLab