Commit 17c15fd4 authored by Philipp Arras's avatar Philipp Arras
Browse files

Merge branch 'testing_ve' into 'NIFTy_6'

numpy tests added

See merge request !507
parents a8c78eb9 b2746955
Pipeline #75656 passed with stages
in 14 minutes and 17 seconds
......@@ -28,9 +28,12 @@ def test_conjugation_operator():
dom = ift.makeDomain(sp)
f = ift.from_random(dom, dtype=np.complex128)
op = ift.ScalingOperator(sp, 1).conjugate()
arr = f.val
res1 = f.conjugate()
res2 = op(f)
res3 = arr.conjugate()
assert_allclose(res1.val, res2.val)
assert_allclose(res1.val, res3)
ift.extra.consistency_check(op, domain_dtype=np.float64,
target_dtype=np.float64)
ift.extra.consistency_check(op, domain_dtype=np.complex128,
......
......@@ -23,25 +23,33 @@ import nifty6 as ift
from ..common import setup_function, teardown_function
def test_contraction_operator():
def test_operator_sum():
x1 = ift.RGSpace((9,), distances=2.)
x2 = ift.RGSpace((2, 12), distances=(0.3,))
dom1 = ift.makeDomain(x1)
dom2 = ift.makeDomain((x1, x2))
f1 = ift.from_random(dom1)
f2 = ift.from_random(dom2)
arr1 = f1.val
arr2 = f2.val
op1 = ift.ScalingOperator(dom1, 1).sum()
op2 = ift.ScalingOperator(dom2, 1).sum()
op3 = ift.ScalingOperator(dom2, 1).sum(spaces=1)
res1 = f1.sum()
res2 = op1(f1)
res3 = arr1.sum()
assert_allclose(res1.val, res2.val)
res3 = f2.sum()
res4 = op2(f2)
assert_allclose(res3.val, res4.val)
res5 = f2.sum(spaces=1)
res6 = op3(f2)
assert_allclose(res5.val, res6.val)
assert_allclose(res1.val, res3)
res4 = f2.sum()
res5 = op2(f2)
res6 = arr2.sum()
assert_allclose(res4.val, res5.val)
assert_allclose(res4.val, res6)
res7 = f2.sum(spaces=1)
res8 = op3(f2)
res9 = arr2.sum(axis=(1, 2))
assert_allclose(res7.val, res8.val)
assert_allclose(res7.val, res9)
for op in [op1, op2, op3]:
ift.extra.consistency_check(op, domain_dtype=np.float64,
target_dtype=np.float64)
......
......@@ -35,13 +35,19 @@ def test_integration_operator():
op3 = ift.ScalingOperator(dom2, 1).integrate(spaces=1)
res1 = f1.integrate()
res2 = op1(f1)
res3 = (f1.val*x1.dvol).sum()
assert_allclose(res1.val, res2.val)
res3 = f2.integrate()
res4 = op2(f2)
assert_allclose(res3.val, res4.val)
res5 = f2.integrate(spaces=1)
res6 = op3(f2)
assert_allclose(res5.val, res6.val)
assert_allclose(res1.val, res3)
res4 = f2.integrate()
res5 = op2(f2)
res6 = (f2.val*x1.dvol*x2.dvol).sum()
assert_allclose(res4.val, res5.val)
assert_allclose(res4.val, res6)
res7 = f2.integrate(spaces=1)
res8 = op3(f2)
res9 = (f2.val*x2.dvol).sum(axis=(1, 2))
assert_allclose(res7.val, res8.val)
assert_allclose(res7.val, res9)
for op in [op1, op2, op3]:
ift.extra.consistency_check(op, domain_dtype=np.float64,
target_dtype=np.float64)
......
......@@ -22,14 +22,18 @@ import nifty6 as ift
from ..common import setup_function, teardown_function
def test_vdot_operator():
dom = ift.makeDomain(ift.RGSpace(8))
fa_1 = ift.FieldAdapter(dom, 'f1')
fa_2 = ift.FieldAdapter(dom, 'f2')
op1 = fa_1.vdot(fa_2)
f = ift.from_random(op1.domain, dtype=np.float64)
arr1 = f['f1'].val
arr2 = f['f2'].val
res1 = f['f1'].vdot(f['f2'])
res2 = op1(f)
res3 = np.vdot(arr1, arr2)
assert_allclose(res1.val, res2.val)
assert_allclose(res1.val, res3)
ift.extra.check_jacobian_consistency(op1, f)
#another Test for linearization?
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