Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator in BlockDatacontainer #1558

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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