Skip to content

Commit

Permalink
TST: Update of test for matrix representation.
Browse files Browse the repository at this point in the history
See #49.
  • Loading branch information
aringh committed Nov 25, 2015
1 parent a61f22a commit 316b2f2
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions test/operator/operator_utilities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# ODL imports
import odl
from odl.operator.operator_utilities import matrix_representation
from odl.set.pspace import ProductSpace
from odl.operator.pspace_ops import ProductSpaceOperator

from odl.space.ntuples import MatVecOperator
from odl.util.testutils import almost_equal

Expand All @@ -46,5 +49,98 @@ def test_matrix_representation():
assert almost_equal(np.sum(np.abs(A - the_matrix)), 1e-6)


def test_three_matrix_representation_product_to_lin_space():
# Verify that the matrix representation function returns the correct matrix

n = 3
rn = odl.Rn(n)
A = np.random.rand(n, n)
Aop = MatVecOperator(rn, rn, A)

m = 2
rm = odl.Rn(m)
B = np.random.rand(n, m)
Bop = MatVecOperator(rm, rn, B)

dom = ProductSpace(rn, rm)
ran = ProductSpace(rn, 1)

AB_matrix = np.hstack([A, B])
ABop = ProductSpaceOperator([Aop, Bop], dom, ran)

the_matrix = matrix_representation(ABop)

assert almost_equal(np.sum(np.abs(AB_matrix - the_matrix)), 1e-6)


def test_matrix_representation_lin_space_to_product():
# Verify that the matrix representation function returns the correct matrix

n = 3
rn = odl.Rn(n)
A = np.random.rand(n, n)
Aop = MatVecOperator(rn, rn, A)

m = 2
rm = odl.Rn(m)
B = np.random.rand(m, n)
Bop = MatVecOperator(rn, rm, B)

dom = ProductSpace(rn, 1)
ran = ProductSpace(rn, rm)

AB_matrix = np.vstack([A, B])
ABop = ProductSpaceOperator([[Aop], [Bop]], dom, ran)

the_matrix = matrix_representation(ABop)

assert almost_equal(np.sum(np.abs(AB_matrix - the_matrix)), 1e-6)


def test_matrix_representation_product_to_product():
# Verify that the matrix representation function returns the correct matrix

n = 3
rn = odl.Rn(n)
A = np.random.rand(n, n)
Aop = MatVecOperator(rn, rn, A)

m = 2
rm = odl.Rn(m)
B = np.random.rand(m, m)
Bop = MatVecOperator(rm, rm, B)

ran_and_dom = ProductSpace(rn, rm)

AB_matrix = np.vstack([np.hstack([A, np.zeros((n, m))]),
np.hstack([np.zeros((m, n)), B])])
ABop = ProductSpaceOperator([[Aop, None], [None, Bop]],
ran_and_dom, ran_and_dom)
the_matrix = matrix_representation(ABop)

assert almost_equal(np.sum(np.abs(AB_matrix - the_matrix)), 1e-6)


def test_five_matrix_representation_product_to_product_two():
# Verify that the matrix representation function returns the correct matrix

n = 3
rn = odl.Rn(n)
A = np.random.rand(n, n)
Aop = MatVecOperator(rn, rn, A)

B = np.random.rand(n, n)
Bop = MatVecOperator(rn, rn, B)

ran_and_dom = ProductSpace(rn, 2)

AB_matrix = np.vstack([np.hstack([A, np.zeros((n, n))]),
np.hstack([np.zeros((n, n)), B])])
ABop = ProductSpaceOperator([[Aop, None], [None, Bop]],
ran_and_dom, ran_and_dom)
the_matrix = matrix_representation(ABop)

assert almost_equal(np.sum(np.abs(AB_matrix - the_matrix)), 1e-6)

if __name__ == '__main__':
pytest.main(str(__file__.replace('\\', '/')) + ' -v')

0 comments on commit 316b2f2

Please sign in to comment.