test_composed_operator.py 1.59 KB
 Pumpe, Daniel (dpumpe) committed May 14, 2017 1 ``````import unittest `````` Martin Reinecke committed Oct 28, 2017 2 ``````from numpy.testing import assert_allclose `````` Martin Reinecke committed Nov 13, 2017 3 ``````import nifty2go as ift `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 4 5 6 ``````from test.common import generate_spaces from itertools import product from test.common import expand `````` Martin Reinecke committed Oct 28, 2017 7 `````` `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 8 9 10 11 `````` class ComposedOperator_Tests(unittest.TestCase): spaces = generate_spaces() `````` Martin Reinecke committed Oct 28, 2017 12 `````` @expand(product(spaces, spaces)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 13 `````` def test_times_adjoint_times(self, space1, space2): `````` Martin Reinecke committed Sep 25, 2017 14 `````` cspace = (space1, space2) `````` Martin Reinecke committed Nov 13, 2017 15 16 17 18 `````` diag1 = ift.Field.from_random('normal', domain=space1) diag2 = ift.Field.from_random('normal', domain=space2) op1 = ift.DiagonalOperator(diag1, cspace, spaces=(0,)) op2 = ift.DiagonalOperator(diag2, cspace, spaces=(1,)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 19 `````` `````` Martin Reinecke committed Nov 13, 2017 20 `````` op = ift.ComposedOperator((op1, op2)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 21 `````` `````` Martin Reinecke committed Nov 13, 2017 22 23 `````` rand1 = ift.Field.from_random('normal', domain=(space1, space2)) rand2 = ift.Field.from_random('normal', domain=(space1, space2)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 24 `````` `````` Martin Reinecke committed Jun 20, 2017 25 26 `````` tt1 = rand2.vdot(op.times(rand1)) tt2 = rand1.vdot(op.adjoint_times(rand2)) `````` Martin Reinecke committed Oct 28, 2017 27 `````` assert_allclose(tt1, tt2) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 28 `````` `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 29 `````` @expand(product(spaces, spaces)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 30 `````` def test_times_inverse_times(self, space1, space2): `````` Martin Reinecke committed Sep 25, 2017 31 `````` cspace = (space1, space2) `````` Martin Reinecke committed Nov 13, 2017 32 33 34 35 `````` diag1 = ift.Field.from_random('normal', domain=space1) diag2 = ift.Field.from_random('normal', domain=space2) op1 = ift.DiagonalOperator(diag1, cspace, spaces=(0,)) op2 = ift.DiagonalOperator(diag2, cspace, spaces=(1,)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 36 `````` `````` Martin Reinecke committed Nov 13, 2017 37 `````` op = ift.ComposedOperator((op1, op2)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 38 `````` `````` Martin Reinecke committed Nov 13, 2017 39 `````` rand1 = ift.Field.from_random('normal', domain=(space1, space2)) `````` Pumpe, Daniel (dpumpe) committed May 14, 2017 40 41 `````` tt1 = op.inverse_times(op.times(rand1)) `````` Martin Reinecke committed Nov 13, 2017 42 43 `````` assert_allclose(ift.dobj.to_global_data(tt1.val), ift.dobj.to_global_data(rand1.val))``````