diff --git a/pyclesperanto_prototype/__init__.py b/pyclesperanto_prototype/__init__.py index 3422757f..ef2e88c6 100644 --- a/pyclesperanto_prototype/__init__.py +++ b/pyclesperanto_prototype/__init__.py @@ -10,5 +10,5 @@ from ._tier10 import * from ._tier11 import * -__version__ = "0.23.3" +__version__ = "0.23.4" __common_alias__ = "cle" diff --git a/pyclesperanto_prototype/_tier0/_array_operators.py b/pyclesperanto_prototype/_tier0/_array_operators.py index fde23dba..c45d9135 100644 --- a/pyclesperanto_prototype/_tier0/_array_operators.py +++ b/pyclesperanto_prototype/_tier0/_array_operators.py @@ -377,13 +377,13 @@ def __next__(self): self._iter_index = 0 if self._iter_index < self.image.shape[0]: - if len(self.image.shape) == 2: + if len(self.image.shape) < 3: result = np.asarray(self.image)[self._iter_index] elif len(self.image.shape) == 3: output = create(self.image.shape[1:]) result = copy_slice(self.image, output, self._iter_index) else: - raise ValueError("Only 2D or 3D array are supported.") + raise ValueError("Only 1D, 2D or 3D array are supported.") self._iter_index = self._iter_index + 1 return result diff --git a/setup.cfg b/setup.cfg index 08f0d56c..512fdf58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pyclesperanto_prototype -version = 0.23.3 +version = 0.23.4 author = Robert Haase author_email = robert.haase@tu-dresden.de url = https://github.com/clEsperanto/pyclesperanto_prototype diff --git a/tests/test_iterator.py b/tests/test_iterator.py index 860241ee..6c96e602 100644 --- a/tests/test_iterator.py +++ b/tests/test_iterator.py @@ -9,3 +9,48 @@ def test_iterator(): print(cle.array_equal(i,j)) assert cle.array_equal(i,j) + +def test_enumerate(): + import pyclesperanto_prototype as cle + + cle_array = cle.create((2, 10)) + cle.set_ramp_x(cle_array) + + sum_ = 0 + for i, y in enumerate(cle_array[0]): + print(i, y) + sum_ += y + + assert sum_ == 45 + +def test_zip(): + import pyclesperanto_prototype as cle + + cle_array = cle.create((2, 10)) + cle.set_ramp_x(cle_array) + + sum_ = 0 + for x, y in zip(cle_array[0], cle_array[1]): + print(x, y) + sum_ += y + + assert sum_ == 45 + +def test_iter_centroids(): + import pyclesperanto_prototype as cle + + labels = cle.asarray([ + [0, 0, 0, 0, 0], + [0, 1, 0, 3, 0], + [0, 0, 0, 0, 0], + [0, 0, 2, 0, 0], + [0, 0, 0, 0, 0], + ]) + + centroids = cle.centroids_of_labels(labels) + + print(centroids) + + for i, j in zip(centroids[0], centroids[1]): + print(i, j) +