Skip to content
Snippets Groups Projects
Commit f40b7222 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

don't print to console

parent ab127321
No related branches found
No related tags found
No related merge requests found
...@@ -38,32 +38,29 @@ pmp = pytest.mark.parametrize ...@@ -38,32 +38,29 @@ pmp = pytest.mark.parametrize
dtype = list2fixture([np.float64, np.complex128]) dtype = list2fixture([np.float64, np.complex128])
def _check_repr(op):
rep = op.__repr__()
@pmp('sp', _p_RG_spaces) @pmp('sp', _p_RG_spaces)
def testLOSResponse(sp, dtype): def testLOSResponse(sp, dtype):
starts = np.random.randn(len(sp.shape), 10) starts = np.random.randn(len(sp.shape), 10)
ends = np.random.randn(len(sp.shape), 10) ends = np.random.randn(len(sp.shape), 10)
sigma_low = 1e-4*np.random.randn(10) sigma_low = 1e-4*np.random.randn(10)
sigma_ups = 1e-5*np.random.randn(10) sigma_ups = 1e-5*np.random.randn(10)
op = ift.LOSResponse(sp, starts, ends, sigma_low, sigma_ups) _check_repr(ift.LOSResponse(sp, starts, ends, sigma_low, sigma_ups))
print(op)
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces) @pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
def testOperatorCombinations(sp, dtype): def testOperatorCombinations(sp, dtype):
a = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype)) a = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype))
b = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype)) b = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype))
op = ift.SandwichOperator.make(a, b) _check_repr(ift.SandwichOperator.make(a, b))
print(op) _check_repr(a(b))
op = a(b) _check_repr(a+b)
print(op) _check_repr(a-b)
op = a + b _check_repr(a*b)
print(op) _check_repr(a**2)
op = a * b
print(op)
op = a**2
print(op)
op = a - b
print(op)
def testLinearInterpolator(): def testLinearInterpolator():
...@@ -71,8 +68,7 @@ def testLinearInterpolator(): ...@@ -71,8 +68,7 @@ def testLinearInterpolator():
pos = np.random.rand(2, 23) pos = np.random.rand(2, 23)
pos[0, :] *= 0.9 pos[0, :] *= 0.9
pos[1, :] *= 7*3.5 pos[1, :] *= 7*3.5
op = ift.LinearInterpolator(sp, pos) _check_repr(ift.LinearInterpolator(sp, pos))
print(op)
@pmp('args', [(ift.RGSpace(10, harmonic=True), 4, 0), (ift.RGSpace( @pmp('args', [(ift.RGSpace(10, harmonic=True), 4, 0), (ift.RGSpace(
...@@ -81,16 +77,15 @@ def testLinearInterpolator(): ...@@ -81,16 +77,15 @@ def testLinearInterpolator():
def testSlopeOperator(args, dtype): def testSlopeOperator(args, dtype):
tmp = ift.ExpTransform(ift.PowerSpace(args[0]), args[1], args[2]) tmp = ift.ExpTransform(ift.PowerSpace(args[0]), args[1], args[2])
tgt = tmp.domain[0] tgt = tmp.domain[0]
op = ift.SlopeOperator(tgt) _check_repr(ift.SlopeOperator(tgt))
print(op)
@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))
print(op.adjoint) _check_repr(op.adjoint)
print(op.inverse) _check_repr(op.inverse)
print(op.inverse.adjoint) _check_repr(op.inverse.adjoint)
@pmp('sp1', _h_spaces + _p_spaces + _pow_spaces) @pmp('sp1', _h_spaces + _p_spaces + _pow_spaces)
...@@ -100,18 +95,14 @@ def testNullOperator(sp1, sp2, dtype): ...@@ -100,18 +95,14 @@ def testNullOperator(sp1, sp2, dtype):
ift.extra.consistency_check(op, dtype, dtype) ift.extra.consistency_check(op, dtype, dtype)
mdom1 = ift.MultiDomain.make({'a': sp1}) mdom1 = ift.MultiDomain.make({'a': sp1})
mdom2 = ift.MultiDomain.make({'b': sp2}) mdom2 = ift.MultiDomain.make({'b': sp2})
op = ift.NullOperator(mdom1, mdom2) _check_repr(ift.NullOperator(mdom1, mdom2))
print(op) _check_repr(ift.NullOperator(sp1, mdom2))
op = ift.NullOperator(sp1, mdom2) _check_repr(ift.NullOperator(mdom1, sp2))
print(op)
op = ift.NullOperator(mdom1, sp2)
print(op)
@pmp('sp', _p_RG_spaces) @pmp('sp', _p_RG_spaces)
def testHarmonicSmoothingOperator(sp, dtype): def testHarmonicSmoothingOperator(sp, dtype):
op = ift.HarmonicSmoothingOperator(sp, 0.1) _check_repr(ift.HarmonicSmoothingOperator(sp, 0.1))
print(op)
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces) @pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
...@@ -121,44 +112,35 @@ def testDOFDistributor(sp, dtype): ...@@ -121,44 +112,35 @@ def testDOFDistributor(sp, dtype):
return return
dofdex = np.arange(sp.size).reshape(sp.shape) % 3 dofdex = np.arange(sp.size).reshape(sp.shape) % 3
dofdex = ift.Field.from_global_data(sp, dofdex) dofdex = ift.Field.from_global_data(sp, dofdex)
op = ift.DOFDistributor(dofdex) _check_repr(ift.DOFDistributor(dofdex))
print(op)
@pmp('sp', _h_spaces) @pmp('sp', _h_spaces)
def testPPO(sp, dtype): def testPPO(sp, dtype):
op = ift.PowerDistributor(target=sp) _check_repr(ift.PowerDistributor(target=sp))
print(op)
ps = ift.PowerSpace( ps = ift.PowerSpace(
sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=False, nbin=3)) sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=False, nbin=3))
op = ift.PowerDistributor(target=sp, power_space=ps) _check_repr(ift.PowerDistributor(target=sp, power_space=ps))
print(op)
ps = ift.PowerSpace( ps = ift.PowerSpace(
sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=True, nbin=3)) sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=True, nbin=3))
op = ift.PowerDistributor(target=sp, power_space=ps) _check_repr(ift.PowerDistributor(target=sp, power_space=ps))
print(op)
@pmp('sp', _h_RG_spaces + _p_RG_spaces) @pmp('sp', _h_RG_spaces + _p_RG_spaces)
def testFFT(sp, dtype): def testFFT(sp, dtype):
op = ift.FFTOperator(sp) _check_repr(ift.FFTOperator(sp))
print(op) _check_repr(ift.FFTOperator(sp.get_default_codomain()))
op = ift.FFTOperator(sp.get_default_codomain())
print(op)
@pmp('sp', _h_RG_spaces + _p_RG_spaces) @pmp('sp', _h_RG_spaces + _p_RG_spaces)
def testHartley(sp, dtype): def testHartley(sp, dtype):
op = ift.HartleyOperator(sp) _check_repr(ift.HartleyOperator(sp))
print(op) _check_repr(ift.HartleyOperator(sp.get_default_codomain()))
op = ift.HartleyOperator(sp.get_default_codomain())
print(op)
@pmp('sp', _h_spaces) @pmp('sp', _h_spaces)
def testHarmonic(sp, dtype): def testHarmonic(sp, dtype):
op = ift.HarmonicTransformOperator(sp) _check_repr(ift.HarmonicTransformOperator(sp))
print(op)
@pmp('sp', _p_spaces) @pmp('sp', _p_spaces)
...@@ -169,28 +151,25 @@ def testMask(sp, dtype): ...@@ -169,28 +151,25 @@ def testMask(sp, dtype):
mask[f > 0] = 1 mask[f > 0] = 1
mask = ift.Field.from_global_data(sp, mask) mask = ift.Field.from_global_data(sp, mask)
# Test MaskOperator # Test MaskOperator
op = ift.MaskOperator(mask) _check_repr(ift.MaskOperator(mask))
print(op)
@pmp('sp', _h_spaces + _p_spaces) @pmp('sp', _h_spaces + _p_spaces)
def testDiagonal(sp, dtype): def testDiagonal(sp, dtype):
op = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype)) op = ift.DiagonalOperator(ift.Field.from_random("normal", sp, dtype=dtype))
print(op) _check_repr(op)
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces) @pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
def testGeometryRemover(sp, dtype): def testGeometryRemover(sp, dtype):
op = ift.GeometryRemover(sp) _check_repr(ift.GeometryRemover(sp))
print(op)
@pmp('spaces', [0, 1, 2, 3, (0, 1), (0, 2), (0, 1, 2), (0, 2, 3), (1, 3)]) @pmp('spaces', [0, 1, 2, 3, (0, 1), (0, 2), (0, 1, 2), (0, 2, 3), (1, 3)])
@pmp('wgt', [0, 1, 2, -1]) @pmp('wgt', [0, 1, 2, -1])
def testContractionOperator(spaces, wgt, dtype): def testContractionOperator(spaces, wgt, dtype):
dom = (ift.RGSpace(10), ift.RGSpace(13), ift.GLSpace(5), ift.HPSpace(4)) dom = (ift.RGSpace(10), ift.RGSpace(13), ift.GLSpace(5), ift.HPSpace(4))
op = ift.ContractionOperator(dom, spaces, wgt) _check_repr(ift.ContractionOperator(dom, spaces, wgt))
ift.extra.consistency_check(op, dtype, dtype)
def testDomainTupleFieldInserter(): def testDomainTupleFieldInserter():
...@@ -198,16 +177,14 @@ def testDomainTupleFieldInserter(): ...@@ -198,16 +177,14 @@ def testDomainTupleFieldInserter():
ift.RGSpace([4, 22]))) ift.RGSpace([4, 22])))
new_space = ift.UnstructuredDomain(7) new_space = ift.UnstructuredDomain(7)
pos = (5,) pos = (5,)
op = ift.DomainTupleFieldInserter(domain, new_space, 0, pos) _check_repr(ift.DomainTupleFieldInserter(domain, new_space, 0, pos))
print(op)
@pmp('space', [0, 2]) @pmp('space', [0, 2])
def testSymmetrizingOperator(space, dtype): def testSymmetrizingOperator(space, dtype):
dom = (ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13), dom = (ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13),
ift.LogRGSpace((5, 27), [1., 2.7], [0., 4.]), ift.HPSpace(4)) ift.LogRGSpace((5, 27), [1., 2.7], [0., 4.]), ift.HPSpace(4))
op = ift.SymmetrizingOperator(dom, space) _check_repr(ift.SymmetrizingOperator(dom, space))
print(op)
@pmp('space', [0, 2]) @pmp('space', [0, 2])
...@@ -217,8 +194,7 @@ def testZeroPadder(space, factor, dtype, central): ...@@ -217,8 +194,7 @@ def testZeroPadder(space, factor, dtype, central):
dom = (ift.RGSpace(10), ift.UnstructuredDomain(13), ift.RGSpace(7, 12), dom = (ift.RGSpace(10), ift.UnstructuredDomain(13), ift.RGSpace(7, 12),
ift.HPSpace(4)) ift.HPSpace(4))
newshape = [int(factor*l) for l in dom[space].shape] newshape = [int(factor*l) for l in dom[space].shape]
op = ift.FieldZeroPadder(dom, newshape, space, central) _check_repr(ift.FieldZeroPadder(dom, newshape, space, central))
print(op)
@pmp('args', @pmp('args',
...@@ -228,8 +204,7 @@ def testZeroPadder(space, factor, dtype, central): ...@@ -228,8 +204,7 @@ def testZeroPadder(space, factor, dtype, central):
(10,), 1), (10,), 1),
(ift.PowerSpace(ift.RGSpace(10, distances=0.3, harmonic=True)), 6, 0)]) (ift.PowerSpace(ift.RGSpace(10, distances=0.3, harmonic=True)), 6, 0)])
def testExpTransform(args, dtype): def testExpTransform(args, dtype):
op = ift.ExpTransform(args[0], args[1], args[2]) _check_repr(ift.ExpTransform(args[0], args[1], args[2]))
print(op)
@pmp('args', @pmp('args',
...@@ -239,8 +214,7 @@ def testExpTransform(args, dtype): ...@@ -239,8 +214,7 @@ def testExpTransform(args, dtype):
def testQHTOperator(args): def testQHTOperator(args):
dtype = np.float64 dtype = np.float64
tgt = ift.DomainTuple.make(args[0]) tgt = ift.DomainTuple.make(args[0])
op = ift.QHTOperator(tgt, args[1]) _check_repr(ift.QHTOperator(tgt, args[1]))
print(op)
@pmp('args', [[ift.RGSpace( @pmp('args', [[ift.RGSpace(
...@@ -249,8 +223,7 @@ def testQHTOperator(args): ...@@ -249,8 +223,7 @@ def testQHTOperator(args):
(ift.HPSpace(3), ift.RGSpace((12, 24), distances=0.3)), (12, 12), 1 (ift.HPSpace(3), ift.RGSpace((12, 24), distances=0.3)), (12, 12), 1
]]) ]])
def testRegridding(args): def testRegridding(args):
op = ift.RegriddingOperator(*args) _check_repr(ift.RegriddingOperator(*args))
print(op)
@pmp( @pmp(
...@@ -267,8 +240,7 @@ def testRegridding(args): ...@@ -267,8 +240,7 @@ def testRegridding(args):
]) ])
def testOuter(fdomain, domain): def testOuter(fdomain, domain):
f = ift.from_random('normal', fdomain) f = ift.from_random('normal', fdomain)
op = ift.OuterProduct(f, domain) _check_repr(ift.OuterProduct(f, domain))
print(op)
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces) @pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
...@@ -281,5 +253,4 @@ def testValueInserter(sp, seed): ...@@ -281,5 +253,4 @@ def testValueInserter(sp, seed):
ind.append(0) ind.append(0)
else: else:
ind.append(np.random.randint(0, ss-1)) ind.append(np.random.randint(0, ss-1))
op = ift.ValueInserter(sp, ind) _check_repr(ift.ValueInserter(sp, ind))
print(op)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment