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