test_composed_operator.py 1.57 KB
Newer Older
1 2 3 4 5 6
import unittest

from numpy.testing import assert_equal,\
    assert_allclose,\
    assert_approx_equal

Martin Reinecke's avatar
Martin Reinecke committed
7
from nifty2go import Field,\
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()

19
    @expand(product(spaces,spaces))
20
    def test_times_adjoint_times(self, space1, space2):
21
        cspace = (space1, space2)
22 23
        diag1 = Field.from_random('normal', domain=space1)
        diag2 = Field.from_random('normal', domain=space2)
24 25
        op1 = DiagonalOperator(diag1, cspace, spaces=(0,))
        op2 = DiagonalOperator(diag2, cspace, spaces=(1,))
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's avatar
Martin Reinecke committed
32 33
        tt1 = rand2.vdot(op.times(rand1))
        tt2 = rand1.vdot(op.adjoint_times(rand2))
34 35
        assert_approx_equal(tt1, tt2)

36
    @expand(product(spaces, spaces))
37
    def test_times_inverse_times(self, space1, space2):
38
        cspace = (space1, space2)
39 40
        diag1 = Field.from_random('normal', domain=space1)
        diag2 = Field.from_random('normal', domain=space2)
41 42
        op1 = DiagonalOperator(diag1, cspace, spaces=(0,))
        op2 = DiagonalOperator(diag2, cspace, spaces=(1,))
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's avatar
Martin Reinecke committed
49
        assert_allclose(tt1.val, rand1.val)
50