clEsperanto / pyclesperanto_prototype

GPU-accelerated bio-image analysis focusing on 3D+t microscopy image data
http://clesperanto.net
BSD 3-Clause "New" or "Revised" License
208 stars 44 forks source link

in v0.23.3 calling enumerate and zip on arrays created with cle.create() throws ValueError: Only 2D or 3D array are supported. #290

Closed thawn closed 1 year ago

thawn commented 1 year ago

I am trying to run the following code (well actually, I am trying to work with the output of cle.centroids_of_labels(), but the error is the same):

import pyclesperanto_prototype as cle

cle_array = cle.create((2, 10))

for i, y in enumerate(cle_array[0]):
    print(i, y)

for x, y in zip(cle_array[0], cle_array[1]):
    print(x, y)

With v 0.22.0, the code works as expected.

with v 0.23.3, I get the following error:

ValueError                                Traceback (most recent call last)
Cell In[5], line 1
----> 1 for i, y in enumerate(cle_array[0]):
      2     print(i, y)

File /opt/homebrew/Caskroom/mambaforge/base/envs/mic-gym-env/lib/python3.9/site-packages/pyclesperanto_prototype/_tier0/_array_operators.py:386, in ArrayOperators.__iter__.<locals>.MyIterator.__next__(self)
    384     result = copy_slice(self.image, output, self._iter_index)
    385 else:
--> 386     raise ValueError("Only 2D or 3D array are supported.")
    388 self._iter_index = self._iter_index + 1
    389 return result

ValueError: Only 2D or 3D array are supported.

Here is a notebook with a minimal example

haesleinhuepf commented 1 year ago

Hey @thawn ,

thanks for reporting this!

I just fixed it and released 0.23.4 to pypi. Conda follows in about 24h. Please give it a try and let me know if any issues remain. I also added a test for iterating over centroids here. If any issues persist, feel free to use it as a starting point.

Thanks again! Robert