diff --git a/CHANGELOG.md b/CHANGELOG.md index 4adf4ec594..7a1b83afac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Wrappers/Python/cil/framework/BlockDataContainer.py b/Wrappers/Python/cil/framework/BlockDataContainer.py index d624c201e2..9fc1eda8ef 100644 --- a/Wrappers/Python/cil/framework/BlockDataContainer.py +++ b/Wrappers/Python/cil/framework/BlockDataContainer.py @@ -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''' diff --git a/Wrappers/Python/test/test_BlockDataContainer.py b/Wrappers/Python/test/test_BlockDataContainer.py index 11cab04682..57c11ae886 100644 --- a/Wrappers/Python/test/test_BlockDataContainer.py +++ b/Wrappers/Python/test/test_BlockDataContainer.py @@ -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 @@ -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): @@ -920,7 +937,8 @@ def test_partition_diff_num_batches(self): with self.assertRaises(ValueError): data = self.data.partition(num_batches, 'sequential') - + + @@ -941,4 +959,6 @@ def assertDataIsTheSame(self, data, idxs, msg=None): wrong += 1 k += 1 - assert wrong == 0 \ No newline at end of file + assert wrong == 0 + + \ No newline at end of file