Skip to content

Commit

Permalink
Iterator in BlockDatacontainer (#1558)
Browse files Browse the repository at this point in the history
* Iterator in BlockDatacontainer bugfix
---------

Co-authored by: Margaret Duff <43645617+MargaretDuff@users.noreply.github.com>
Co-authored by: Vaggelis Papoutsellis <epapoutsellis@gmail.com>
  • Loading branch information
MargaretDuff authored Nov 27, 2023
1 parent 9bdb70f commit be57697
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

* x.x.x
- Allow reduction methods on the DataContainer class to accept axis argument as string which matches values in dimension_labels
- Added the functions `set_norms` and `get_norms` to the `BlockOperator` class
- Internal variable name change in BlockOperator to aid understanding
- Added the functions `set_norms` and `get_norms` to the `BlockOperator` class
- Internal variable name change in BlockOperator to aid understanding
- Bug fix for BlockDataContainer as iterator
- Dropped support for IPP versions older than 2021.10 due to header changes
- Fix build include directories


* 23.1.0
- Fix bug in IndicatorBox proximal_conjugate
- Allow CCPi Regulariser functions for non CIL object
Expand Down
1 change: 1 addition & 0 deletions Wrappers/Python/cil/framework/BlockDataContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(self, *args, **kwargs):

def __iter__(self):
'''BlockDataContainer is Iterable'''
self.index=0
return self
def next(self):
'''python2 backwards compatibility'''
Expand Down
26 changes: 23 additions & 3 deletions Wrappers/Python/test/test_BlockDataContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import unittest
from utils import initialise_tests
import numpy as np
from cil.framework import ImageGeometry, AcquisitionGeometry
from cil.framework import ImageGeometry, AcquisitionGeometry, VectorGeometry
from cil.framework import ImageData, AcquisitionData, Partitioner
from cil.framework import BlockDataContainer, BlockGeometry
import functools
Expand Down Expand Up @@ -851,6 +851,23 @@ def test_sapyb_ab_blockdc_y_dc(self):
res = BlockDataContainer(res0, res2)

self.assertBlockDataContainerEqual(out, res)

def test_iterator(self):
ig0 = VectorGeometry(5)
data0=ig0.allocate(0)
data1=ig0.allocate(1)
data2=ig0.allocate(2)
container=BlockDataContainer(data0,data1,data2)
a=[]
for data in container:
a.append(list(data.array))
self.assertListEqual(a, [[0.,0.,0.,0.,0.],[1.,1.,1.,1.,1.],[2,2,2,2,2]])

a=[] #check it works a second time!
for data in container:
a.append(list(data.array))
self.assertListEqual(a, [[0.,0.,0.,0.,0.],[1.,1.,1.,1.,1.],[2,2,2,2,2]])


class TestBlockGeometry(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -920,7 +937,8 @@ def test_partition_diff_num_batches(self):
with self.assertRaises(ValueError):
data = self.data.partition(num_batches, 'sequential')







Expand All @@ -941,4 +959,6 @@ def assertDataIsTheSame(self, data, idxs, msg=None):
wrong += 1
k += 1

assert wrong == 0
assert wrong == 0


0 comments on commit be57697

Please sign in to comment.