Skip to content

Commit

Permalink
Merge pull request #291 from clEsperanto/enumerate_1D_issue
Browse files Browse the repository at this point in the history
fix issue with enumerate and zip
  • Loading branch information
haesleinhuepf authored Mar 24, 2023
2 parents ea84c9f + 4d4158e commit c1403ef
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyclesperanto_prototype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
from ._tier10 import *
from ._tier11 import *

__version__ = "0.23.3"
__version__ = "0.23.4"
__common_alias__ = "cle"
4 changes: 2 additions & 2 deletions pyclesperanto_prototype/_tier0/_array_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions tests/test_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c1403ef

Please sign in to comment.