Commit a78e1e01 authored by Philipp Arras's avatar Philipp Arras

Cleanup and cosmetics in tests

parent 1c1a6b51
Pipeline #52937 passed with stages
in 8 minutes and 9 seconds
......@@ -57,8 +57,6 @@ def test_power_synthesize_analyze(space1, space2):
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)
......@@ -345,11 +343,11 @@ def test_funcs(num, dom, func):
@pmp('dtype', [np.float64, np.complex128])
def test_from_random(rtype, dtype):
sp = ift.RGSpace(3)
f = ift.Field.from_random(rtype, sp, dtype=dtype)
ift.Field.from_random(rtype, sp, dtype=dtype)
def test_field_of_objects():
arr = np.array(['x', 'y', 'z'])
sp = ift.RGSpace(3)
with assert_raises(TypeError):
f = ift.Field.from_global_data(sp, arr)
ift.Field.from_global_data(sp, arr)
......@@ -77,7 +77,6 @@ def test_quadratic_minimization(minimizer, space):
@pmp('space', spaces)
def test_WF_curvature(space):
np.random.seed(42)
starting_point = ift.Field.from_random('normal', domain=space)*10
required_result = ift.full(space, 1.)
s = ift.Field.from_random('uniform', domain=space) + 0.5
......
......@@ -15,7 +15,7 @@
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
from numpy.testing import assert_allclose, assert_equal
from numpy.testing import assert_allclose
import nifty5 as ift
import numpy as np
......@@ -30,9 +30,8 @@ space = list2fixture([
def test_const_func(space):
ones = lambda x: np.ones(x.shape)
sig = ift.Field.from_random('normal', domain=space)
fco_op = ift.FuncConvolutionOperator(space, ones)
fco_op = ift.FuncConvolutionOperator(space, lambda x: np.ones(x.shape))
vals = fco_op(sig).to_global_data()
vals = np.round(vals, decimals=5)
assert len(np.unique(vals)) == 1
......
......@@ -33,19 +33,11 @@ space1 = space
seed = list2fixture([4, 78, 23])
def _make_linearization(type, space, seed):
def testBasics(space, seed):
np.random.seed(seed)
S = ift.ScalingOperator(1., space)
s = S.draw_sample()
if type == "Constant":
return ift.Linearization.make_const(s)
elif type == "Variable":
return ift.Linearization.make_var(s)
raise ValueError('unknown type passed')
def testBasics(space, seed):
var = _make_linearization("Variable", space, seed)
var = ift.Linearization.make_var(s)
model = ift.ScalingOperator(6., var.target)
ift.extra.check_jacobian_consistency(model, var.val)
......@@ -55,11 +47,7 @@ def testBasics(space, seed):
def testBinary(type1, type2, space, seed):
dom1 = ift.MultiDomain.make({'s1': space})
dom2 = ift.MultiDomain.make({'s2': space})
# FIXME Remove this?
_make_linearization(type1, dom1, seed)
_make_linearization(type2, dom2, seed)
np.random.seed(seed)
dom = ift.MultiDomain.union((dom1, dom2))
select_s1 = ift.ducktape(None, dom1, "s1")
select_s2 = ift.ducktape(None, dom2, "s2")
......
......@@ -17,7 +17,7 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_
from numpy.testing import assert_
import nifty5 as ift
......
......@@ -57,8 +57,8 @@ def testOperatorCombinations(sp, dtype):
b = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype))
_check_repr(ift.SandwichOperator.make(a, b))
_check_repr(a(b))
_check_repr(a+b)
_check_repr(a-b)
_check_repr(a + b)
_check_repr(a - b)
_check_repr(a*b)
_check_repr(a**2)
......@@ -211,7 +211,6 @@ def testExpTransform(args, dtype):
((ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13)), 0),
((ift.UnstructuredDomain(13), ift.LogRGSpace(17, [3.], [.7])), 1)])
def testQHTOperator(args):
dtype = np.float64
tgt = ift.DomainTuple.make(args[0])
_check_repr(ift.QHTOperator(tgt, args[1]))
......@@ -225,14 +224,11 @@ def testRegridding(args):
_check_repr(ift.RegriddingOperator(*args))
@pmp(
'fdomain',
[
ift.DomainTuple.make((ift.RGSpace(
(3, 5, 4)), ift.RGSpace((16,), distances=(7.,))),),
ift.DomainTuple.make(ift.HPSpace(12),)
],
)
@pmp('fdomain', [
ift.DomainTuple.make((ift.RGSpace(
(3, 5, 4)), ift.RGSpace((16,), distances=(7.,))),),
ift.DomainTuple.make(ift.HPSpace(12),)
])
@pmp('domain', [
ift.DomainTuple.make((ift.RGSpace((2,)), ift.GLSpace(10)),),
ift.DomainTuple.make(ift.RGSpace((10, 12), distances=(0.1, 1.)),)
......@@ -251,5 +247,5 @@ def testValueInserter(sp, seed):
if ss == 1:
ind.append(0)
else:
ind.append(np.random.randint(0, ss-1))
ind.append(np.random.randint(0, ss - 1))
_check_repr(ift.ValueInserter(sp, ind))
......@@ -15,7 +15,6 @@
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import pytest
from numpy.testing import assert_allclose, assert_equal
import nifty5 as ift
......
......@@ -66,8 +66,7 @@ def get_k_length_array_configs():
@pmp('attribute', ['lmax', 'mmax', 'size'])
def test_property_ret_type(attribute):
l = ift.LMSpace(7, 5)
assert_(isinstance(getattr(l, attribute), int))
assert_(isinstance(getattr(ift.LMSpace(7, 5), attribute), int))
@pmp('lmax, mmax, expected', CONSTRUCTOR_CONFIGS)
......@@ -76,9 +75,8 @@ def test_constructor(lmax, mmax, 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)
assert_equal(getattr(ift.LMSpace(lmax, mmax), key), value)
def test_dvol():
......@@ -87,5 +85,5 @@ def test_dvol():
@pmp('lmax, expected', get_k_length_array_configs())
def test_k_length_array(lmax, expected):
l = ift.LMSpace(lmax)
assert_allclose(l.get_k_length_array().to_global_data(), expected)
assert_allclose(ift.LMSpace(lmax).get_k_length_array().to_global_data(),
expected)
......@@ -17,11 +17,12 @@
from itertools import chain, product
import pytest
import nifty5 as ift
import numpy as np
import pytest
from numpy.testing import assert_, assert_allclose, assert_equal, assert_raises
import nifty5 as ift
pmp = pytest.mark.parametrize
HARMONIC_SPACES = [
......
......@@ -16,8 +16,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_equal, assert_raises
from numpy.testing import assert_equal
import nifty5 as ift
......@@ -25,8 +24,8 @@ import nifty5 as ift
def test_get_signal_variance():
space = ift.RGSpace(3)
hspace = space.get_default_codomain()
spec1 = lambda x: np.ones_like(x)
assert_equal(ift.get_signal_variance(spec1, hspace), 3.)
sv = ift.get_signal_variance(lambda x: np.ones_like(x), hspace)
assert_equal(sv, 3.)
space = ift.RGSpace(3, distances=1.)
hspace = space.get_default_codomain()
......
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