Scheduled maintenance on Monday 2019-06-24 between 10:00-11:00 CEST

Commit b746da72 authored by Martin Reinecke's avatar Martin Reinecke

cosmetics

parent 4f6b914c
Pipeline #49097 passed with stages
in 8 minutes and 5 seconds
......@@ -72,7 +72,7 @@ def _full_implementation(op, domain_dtype, target_dtype, atol, rtol,
def _check_linearity(op, domain_dtype, atol, rtol):
fld1 = from_random("normal", op.domain, dtype=domain_dtype)
fld2 = from_random("normal", op.domain, dtype=domain_dtype)
alpha = np.random.random() # FIXME: this can break badly with MPI!
alpha = np.random.random() # FIXME: this can break badly with MPI!
val1 = op(alpha*fld1+fld2)
val2 = alpha*op(fld1)+op(fld2)
_assert_allclose(val1, val2, atol=atol, rtol=rtol)
......@@ -81,8 +81,9 @@ def _check_linearity(op, domain_dtype, atol, rtol):
def _domain_check(op):
for dd in [op.domain, op.target]:
if not isinstance(dd, (DomainTuple, MultiDomain)):
raise TypeError('The domain and the target of an operator need to',
'be instances of either DomainTuple or MultiDomain.')
raise TypeError(
'The domain and the target of an operator need to',
'be instances of either DomainTuple or MultiDomain.')
def consistency_check(op, domain_dtype=np.float64, target_dtype=np.float64,
......
......@@ -158,7 +158,7 @@ class DiagonalOperator(EndomorphicOperator):
def process_sample(self, samp, from_inverse):
if (self._complex or (self._diagmin < 0.) or
(self._diagmin == 0. and from_inverse)):
raise ValueError("operator not positive definite")
raise ValueError("operator not positive definite")
if from_inverse:
res = samp.local_data/np.sqrt(self._ldiag)
else:
......
......@@ -87,7 +87,7 @@ class ScalingOperator(EndomorphicOperator):
fct = self._factor
if (fct.imag != 0. or fct.real < 0. or
(fct.real == 0. and from_inverse)):
raise ValueError("operator not positive definite")
raise ValueError("operator not positive definite")
return 1./np.sqrt(fct) if from_inverse else np.sqrt(fct)
# def process_sample(self, samp, from_inverse):
......
......@@ -423,7 +423,7 @@ def _plot(f, ax, **kwargs):
if len(f) == 0:
raise ValueError("need something to plot")
if not isinstance(f[0], Field):
raise TypeError("incorrect data type")
raise TypeError("incorrect data type")
dom1 = f[0].domain
if (len(dom1) == 1 and
(isinstance(dom1[0], PowerSpace) or
......
......@@ -39,6 +39,7 @@ dtype = list2fixture([np.float64, np.complex128])
np.random.seed(42)
@pmp('sp', _p_RG_spaces)
def testLOSResponse(sp, dtype):
starts = np.random.randn(len(sp.shape), 10)
......@@ -76,14 +77,14 @@ def testLinearInterpolator():
def testRealizer(sp):
op = ift.Realizer(sp)
ift.extra.consistency_check(op, np.complex128, np.float64,
only_r_linear=True)
only_r_linear=True)
@pmp('sp', _h_spaces + _p_spaces + _pow_spaces)
def testConjugationOperator(sp):
op = ift.ConjugationOperator(sp)
ift.extra.consistency_check(op, np.complex128, np.complex128,
only_r_linear=True)
only_r_linear=True)
@pmp('args', [(ift.RGSpace(10, harmonic=True), 4, 0), (ift.RGSpace(
......
......@@ -17,7 +17,7 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose
from numpy.testing import assert_allclose, assert_
import nifty5 as ift
......@@ -26,11 +26,11 @@ np.random.seed(40)
pmp = pytest.mark.parametrize
def _l2error(a,b):
def _l2error(a, b):
return np.sqrt(np.sum(np.abs(a-b)**2)/np.sum(np.abs(a)**2))
@pmp('eps', [ 1e-2, 1e-4, 1e-7, 1e-10, 1e-11, 1e-12, 2e-13])
@pmp('eps', [1e-2, 1e-4, 1e-7, 1e-10, 1e-11, 1e-12, 2e-13])
@pmp('nu', [12, 128])
@pmp('nv', [4, 12, 128])
@pmp('N', [1, 10, 100])
......@@ -39,7 +39,7 @@ def test_gridding(nu, nv, N, eps):
vis = np.random.randn(N) + 1j*np.random.randn(N)
# Nifty
GM = ift.GridderMaker(ift.RGSpace((nu, nv)),eps=eps)
GM = ift.GridderMaker(ift.RGSpace((nu, nv)), eps=eps)
# re-order for performance
idx = GM.getReordering(uv)
uv, vis = uv[idx], vis[idx]
......@@ -53,7 +53,7 @@ def test_gridding(nu, nv, N, eps):
dft = pynu*0.
for i in range(N):
dft += (vis[i]*np.exp(2j*np.pi*(x*uv[i, 0] + y*uv[i, 1]))).real
assert(_l2error(dft,pynu)<eps)
assert_(_l2error(dft, pynu) < eps)
@pmp('eps', [1e-2, 1e-6, 2e-13])
......
......@@ -23,23 +23,23 @@ import nifty5 as ift
def test_simplification():
from nifty5.operators.operator import _ConstantOperator
f1 = ift.Field.full(ift.RGSpace(10),2.)
f1 = ift.Field.full(ift.RGSpace(10), 2.)
op = ift.FFTOperator(f1.domain)
_, op2 = op.simplify_for_constant_input(f1)
assert_equal(isinstance(op2, _ConstantOperator), True)
assert_allclose(op(f1).local_data, op2(f1).local_data)
dom = {"a": ift.RGSpace(10)}
f1 = ift.full(dom,2.)
f1 = ift.full(dom, 2.)
op = ift.FFTOperator(f1.domain["a"]).ducktape("a")
_, op2 = op.simplify_for_constant_input(f1)
assert_equal(isinstance(op2, _ConstantOperator), True)
assert_allclose(op(f1).local_data, op2(f1).local_data)
dom = {"a": ift.RGSpace(10), "b": ift.RGSpace(5)}
f1 = ift.full(dom,2.)
f1 = ift.full(dom, 2.)
pdom = {"a": ift.RGSpace(10)}
f2 = ift.full(pdom,2.)
f2 = ift.full(pdom, 2.)
o1 = ift.FFTOperator(f1.domain["a"])
o2 = ift.FFTOperator(f1.domain["b"])
op = (o1.ducktape("a").ducktape_left("a") +
......
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