Skip to content
Snippets Groups Projects
Commit 0cba5f1f authored by Vincent Eberle's avatar Vincent Eberle
Browse files

numpy tests added

parent 2884f274
No related branches found
No related tags found
1 merge request!507numpy tests added
Pipeline #75545 passed
......@@ -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_contraction_operator(): # actually this tests .sum() -> clarification
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() #richtig?
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() # richtig?
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)
......
......@@ -28,8 +28,12 @@ def test_vdot_operator():
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?
  • Maintainer

    @parras could you doublecheck the numpy tests? for me they seem to be logical and they pass. But a second opinion is always better.

    should we change the name of the contraction test? actually it is only testing .sum()? what do you think about a cleanup in a way, that reduces test_blabla_operator files? for example: Testing all the functions of the operator class in one file?

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment