Commit cbacf1b1 authored by Gordian Edenhofer's avatar Gordian Edenhofer
Browse files

Seed test_simple_without_asp_fluct

While at it, stop using numpy's deprecated `assert_` method.
parent fbc57654
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import numpy as np import numpy as np
import pytest import pytest
from numpy.testing import assert_, assert_allclose from numpy.testing import assert_allclose
import nifty7 as ift import nifty7 as ift
...@@ -114,8 +114,8 @@ def testAmplitudesInvariants(sspace, N): ...@@ -114,8 +114,8 @@ def testAmplitudesInvariants(sspace, N):
em, estd = _stats(fa.slice_fluctuation(0), samples) em, estd = _stats(fa.slice_fluctuation(0), samples)
assert_allclose(m, em, rtol=0.5) assert_allclose(m, em, rtol=0.5)
assert_(op.target[-2] == sspace) assert op.target[-2] == sspace
assert_(op.target[-1] == fsspace) assert op.target[-1] == fsspace
for ampl in fa.normalized_amplitudes: for ampl in fa.normalized_amplitudes:
ift.extra.check_operator(ampl, 0.1*ift.from_random(ampl.domain), ntries=10) ift.extra.check_operator(ampl, 0.1*ift.from_random(ampl.domain), ntries=10)
...@@ -160,32 +160,41 @@ def test_complicated_vs_simple(seed, domain): ...@@ -160,32 +160,41 @@ def test_complicated_vs_simple(seed, domain):
harmonic_partner=hspace) harmonic_partner=hspace)
inp = ift.from_random(scf.domain) inp = ift.from_random(scf.domain)
op1 = cfm.finalize() op1 = cfm.finalize()
assert_(scf.domain is op1.domain) assert scf.domain is op1.domain
ift.extra.assert_allclose(scf(inp), op1(inp)) ift.extra.assert_allclose(scf(inp), op1(inp))
ift.extra.check_operator(scf, inp, ntries=10) ift.extra.check_operator(scf, inp, ntries=10)
op1 = cfm.amplitude op1 = cfm.amplitude
op0 = scf.amplitude op0 = scf.amplitude
assert_(op0.domain is op1.domain) assert op0.domain is op1.domain
ift.extra.assert_allclose(op0.force(inp), op1.force(inp)) ift.extra.assert_allclose(op0.force(inp), op1.force(inp))
@pmp('asperity', [None, (_posrand(), _posrand())]) @pmp('seed', [42, 31])
@pmp('flexibility', [None, (_posrand(), _posrand())]) @pmp('without', (('asperity', ), ('flexibility', ), ('flexibility', 'asperity')))
def test_simple_without_asp_fluct(asperity, flexibility): def test_simple_without_asp_fluct(seed, without):
domain = ift.RGSpace((4, 4), (0.123, 0.4)) with ift.random.Context(seed):
offset_mean = _rand() domain = ift.RGSpace((4, 4), (0.123, 0.4))
offset_std = _posrand(), _posrand() offset_mean = _rand()
fluctuations = _posrand(), _posrand() offset_std = _posrand(), _posrand()
loglogavgslope = _posrand(), _posrand() if "flexibility" in without:
prefix = 'foobar' flexibility = None
hspace = domain.get_default_codomain() else:
args = (domain, offset_mean, offset_std, fluctuations, flexibility, flexibility = _posrand(), _posrand()
asperity, loglogavgslope, prefix, hspace) if "asperity" in without:
if asperity is not None and flexibility is None: asperity = None
with pytest.raises(ValueError): else:
asperity = _posrand(), _posrand()
fluctuations = _posrand(), _posrand()
loglogavgslope = _posrand(), _posrand()
prefix = 'foobar'
hspace = domain.get_default_codomain()
args = (domain, offset_mean, offset_std, fluctuations, flexibility,
asperity, loglogavgslope, prefix, hspace)
if asperity is not None and flexibility is None:
with pytest.raises(ValueError):
scf = ift.SimpleCorrelatedField(*args)
else:
scf = ift.SimpleCorrelatedField(*args) scf = ift.SimpleCorrelatedField(*args)
else: inp = ift.from_random(scf.domain)
scf = ift.SimpleCorrelatedField(*args) ift.extra.check_operator(scf, inp, ntries=10)
inp = ift.from_random(scf.domain)
ift.extra.check_operator(scf, inp, ntries=10)
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