Skip to content

Commit

Permalink
added test for BlockDataContainer pnorm(2)
Browse files Browse the repository at this point in the history
  • Loading branch information
paskino committed Oct 11, 2023
1 parent 2d2fdac commit 3a387ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Wrappers/Python/test/test_BlockDataContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,25 @@ def test_NestedBlockDataContainer2(self):

c5 = d.get_item(0).power(2).sum()

def test_Nested_BlockDataContainer3(self):
from cil.optimisation.functions.MixedL21Norm import _proximal_step_numpy
from cil.framework import ImageGeometry, AcquisitionGeometry
from cil.optimisation.operators import LinearOperator, GradientOperator

ag = AcquisitionGeometry.create_Parallel2D()\
.set_panel(3)\
.set_angles(np.linspace(0,360,4), angle_unit='degree')

ig = ag.get_ImageGeometry()

L = LinearOperator(domain_geometry=ig, range_geometry=ag)
L.set_norm(1)
Grad = GradientOperator(ig)
K = BlockOperator(L, Grad)

tmp = K.range_geometry().allocate(1)

a = tmp.pnorm(2)

def test_BlockDataContainer_fill(self):

Expand Down
14 changes: 7 additions & 7 deletions Wrappers/Python/test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_MixedL21Norm_proximal_step_numpy_bdc(self):
from cil.optimisation.operators import LinearOperator, GradientOperator

ag = AcquisitionGeometry.create_Parallel2D()\
.set_panel(4)\
.set_panel(3)\
.set_angles(np.linspace(0,360,4), angle_unit='degree')

ig = ag.get_ImageGeometry()
Expand All @@ -456,20 +456,20 @@ def test_MixedL21Norm_proximal_step_numpy_bdc(self):
tmp_sigma = K.range_geometry().allocate(1)

sigma1 = 1./tmp_sigma
tmp = ig.allocate(1)

# this test only makes sense if the shape of the various containers
# in the bdc is the same.
# Does it make sense to keep this?
tmp = K.range_geometry().allocate(1.5)

a = _proximal_step_numpy(tmp, sigma1)

sigma2 = -1./tmp_sigma
b = _proximal_step_numpy(tmp, sigma2)

assert len(a) == len(b)

for i in range(len(a)):
np.testing.assert_allclose(a[i].as_array(), b[i].as_array())
# assert equality of nested bdc
self.assertBlockDataContainerAlmostEqual(a,b)
# for i in range(len(a)):
# np.testing.assert_allclose(a[i].as_array(), b[i].as_array())

def test_smoothL21Norm(self):
ig = ImageGeometry(4, 5)
Expand Down

0 comments on commit 3a387ac

Please sign in to comment.