Commit f5118b0b authored by Philipp Haim's avatar Philipp Haim

Checkout modified tests

parent 87e34527
Pipeline #63550 passed with stages
in 6 minutes and 54 seconds
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
import numpy as np import numpy as np
import pytest import pytest
from numpy.testing import assert_
import nifty5 as ift import nifty5 as ift
...@@ -29,6 +28,11 @@ space = list2fixture([ ...@@ -29,6 +28,11 @@ space = list2fixture([
ift.RGSpace(64, distances=.789), ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], 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 space1 = space
seed = list2fixture([4, 78, 23]) seed = list2fixture([4, 78, 23])
...@@ -85,29 +89,6 @@ def testBinary(type1, type2, space, seed): ...@@ -85,29 +89,6 @@ def testBinary(type1, type2, space, seed):
ift.extra.check_jacobian_consistency(model, pos, ntries=20) ift.extra.check_jacobian_consistency(model, pos, ntries=20)
def testModelLibrary(space, seed):
# Tests amplitude model and coorelated field model
np.random.seed(seed)
domain = ift.PowerSpace(space.get_default_codomain())
model = ift.SLAmplitude(target=domain, n_pix=4, a=.5, k0=2, sm=3, sv=1.5,
im=1.75, iv=1.3)
assert_(isinstance(model, ift.Operator))
S = ift.ScalingOperator(1., model.domain)
pos = S.draw_sample()
ift.extra.check_jacobian_consistency(model, pos, ntries=20)
model2 = ift.CorrelatedField(space, model)
S = ift.ScalingOperator(1., model2.domain)
pos = S.draw_sample()
ift.extra.check_jacobian_consistency(model2, pos, ntries=20)
domtup = ift.DomainTuple.make((space, space))
model3 = ift.MfCorrelatedField(domtup, [model, model])
S = ift.ScalingOperator(1., model3.domain)
pos = S.draw_sample()
ift.extra.check_jacobian_consistency(model3, pos, ntries=20)
def testPointModel(space, seed): def testPointModel(space, seed):
S = ift.ScalingOperator(1., space) S = ift.ScalingOperator(1., space)
pos = S.draw_sample() pos = S.draw_sample()
...@@ -163,3 +144,20 @@ def testDynamicModel(target, causal, minimum_phase, seed): ...@@ -163,3 +144,20 @@ def testDynamicModel(target, causal, minimum_phase, seed):
# FIXME I dont know why smaller tol fails for 3D example # FIXME I dont know why smaller tol fails for 3D example
ift.extra.check_jacobian_consistency( ift.extra.check_jacobian_consistency(
model, pos, tol=1e-5, ntries=20) 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)
...@@ -71,15 +71,6 @@ def testLinearInterpolator(): ...@@ -71,15 +71,6 @@ def testLinearInterpolator():
_check_repr(ift.LinearInterpolator(sp, pos)) _check_repr(ift.LinearInterpolator(sp, pos))
@pmp('args', [(ift.RGSpace(10, harmonic=True), 4, 0), (ift.RGSpace(
(24, 31), distances=(0.4, 2.34), harmonic=True), 3, 0),
(ift.LMSpace(4), 10, 0)])
def testSlopeOperator(args, dtype):
tmp = ift.ExpTransform(ift.PowerSpace(args[0]), args[1], args[2])
tgt = tmp.domain[0]
_check_repr(ift.SlopeOperator(tgt))
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces) @pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
def testOperatorAdaptor(sp, dtype): def testOperatorAdaptor(sp, dtype):
op = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype)) op = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype))
...@@ -179,13 +170,6 @@ def testDomainTupleFieldInserter(): ...@@ -179,13 +170,6 @@ def testDomainTupleFieldInserter():
_check_repr(ift.DomainTupleFieldInserter(target, 1, (5,))) _check_repr(ift.DomainTupleFieldInserter(target, 1, (5,)))
@pmp('space', [0, 2])
def testSymmetrizingOperator(space, dtype):
dom = (ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13),
ift.LogRGSpace((5, 27), [1., 2.7], [0., 4.]), ift.HPSpace(4))
_check_repr(ift.SymmetrizingOperator(dom, space))
@pmp('space', [0, 2]) @pmp('space', [0, 2])
@pmp('factor', [1, 2, 2.7]) @pmp('factor', [1, 2, 2.7])
@pmp('central', [False, True]) @pmp('central', [False, True])
...@@ -196,25 +180,6 @@ def testZeroPadder(space, factor, dtype, central): ...@@ -196,25 +180,6 @@ def testZeroPadder(space, factor, dtype, central):
_check_repr(ift.FieldZeroPadder(dom, newshape, space, central)) _check_repr(ift.FieldZeroPadder(dom, newshape, space, central))
@pmp('args',
[(ift.RGSpace(10, harmonic=True), 4, 0), (ift.RGSpace(
(24, 31), distances=(0.4, 2.34), harmonic=True), (4, 3), 0),
((ift.HPSpace(4), ift.RGSpace(27, distances=0.3, harmonic=True)),
(10,), 1),
(ift.PowerSpace(ift.RGSpace(10, distances=0.3, harmonic=True)), 6, 0)])
def testExpTransform(args, dtype):
_check_repr(ift.ExpTransform(args[0], args[1], args[2]))
@pmp('args',
[(ift.LogRGSpace([10, 17], [2., 3.], [1., 0.]), 0),
((ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13)), 0),
((ift.UnstructuredDomain(13), ift.LogRGSpace(17, [3.], [.7])), 1)])
def testQHTOperator(args):
tgt = ift.DomainTuple.make(args[0])
_check_repr(ift.QHTOperator(tgt, args[1]))
@pmp('args', [[ift.RGSpace( @pmp('args', [[ift.RGSpace(
(13, 52, 40)), (4, 6, 25), None], [ift.RGSpace( (13, 52, 40)), (4, 6, 25), None], [ift.RGSpace(
(128, 128)), (45, 48), 0], [ift.RGSpace(13), (7,), None], [ (128, 128)), (45, 48), 0], [ift.RGSpace(13), (7,), None], [
......
...@@ -34,8 +34,8 @@ def test_value_inserter(sp, seed): ...@@ -34,8 +34,8 @@ def test_value_inserter(sp, seed):
np.random.seed(seed) np.random.seed(seed)
ind = tuple([np.random.randint(0, ss - 1) for ss in sp.shape]) ind = tuple([np.random.randint(0, ss - 1) for ss in sp.shape])
op = ift.ValueInserter(sp, ind) op = ift.ValueInserter(sp, ind)
f = ift.from_random('normal', ift.UnstructuredDomain((1,))) f = ift.from_random('normal', op.domain)
inp = f.to_global_data()[0] inp = f.to_global_data()
ret = op(f).to_global_data() ret = op(f).to_global_data()
assert_(ret[ind] == inp) assert_(ret[ind] == inp)
assert_(np.sum(ret) == inp) assert_(np.sum(ret) == inp)
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