Skip to content

Commit

Permalink
Debugging and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MargaretDuff committed Sep 26, 2023
1 parent 41b6dd3 commit 439567f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Wrappers/Python/cil/optimisation/operators/Operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,13 @@ def PowerMethod(operator, max_iteration=10, initial=None, tolerance=1e-5, retur
"""
convergence_check = True

if compose_with_adjoint is None:
try:
if operator.domain_geometry() == operator.range_geometry():
compose_with_adjoint= False
else:
compose_with_adjoint=True
except AssertionError:
# catch AssertionError for SIRF objects https://github.com/SyneRBI/SIRF-SuperBuild/runs/5110228626?check_suite_focus=true#step:8:972
compose_with_adjoint=True
Expand Down
9 changes: 5 additions & 4 deletions Wrappers/Python/test/test_Operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def test_PowerMethod(self):

# Test with the norm
res2 = M1op.norm()
res1 = M1op.PowerMethod(M1op,100, compose_with_adjoint=True)
numpy.testing.assert_almost_equal(res1,res2, decimal=4)


Expand All @@ -302,19 +303,19 @@ def test_PowerMethod(self):
# 3x3 complex matrix, (real+complex eigenvalue), dominant eigenvalue = 3.1624439599276974
M1 = numpy.array([[2,0,0],[1,2j,1j],[3, 3-1j,3]])
M1op = MatrixOperator(M1)
res1 = M1op.PowerMethod(M1op,100)
numpy.testing.assert_almost_equal(res1,3.1624439599276974, decimal=4)
res1 = M1op.PowerMethod(M1op,120)
numpy.testing.assert_almost_equal(res1,3.1624439599276974, decimal=3)

# 2x2 non-diagonalisable nilpotent matrix
M1=numpy.array([[0.,1.], [0.,0.]])
M1op = MatrixOperator(M1)
res1 = M1op.PowerMethod(M1op,5)
numpy.testing.assert_almost_equal(res1,0, decimal=4)

# 2x2 non-diagonalisable nilpotent matrix where range_is_domain is False
# 2x2 non-diagonalisable nilpotent matrix where compose_with_adjoint=True
M1=numpy.array([[0.,1.], [0.,0.]])
M1op = MatrixOperator(M1)
res1 = M1op.PowerMethod(M1op,5, range_is_domain=False)
res1 = M1op.PowerMethod(M1op,5, compose_with_adjoint=True)
numpy.testing.assert_almost_equal(res1,1, decimal=4)


Expand Down

0 comments on commit 439567f

Please sign in to comment.