[SciPy-dev] Should ndimage.measurements.* should return lists if index is a list?

josef.pktd at gmail.com josef.pktd at gmail.com
Sun Apr 19 12:24:14 EDT 2009


On Sun, Apr 19, 2009 at 10:31 AM, Thouis (Ray) Jones <thouis at broad.mit.edu>
wrote:
> On Sun, Apr 19, 2009 at 09:55, Zachary Pincus <zachary.pincus at yale.edu>
wrote:
>>> I don't believe so.  I considered that, but there have to be some
>>> changes made to the C code to handle empty lists and better error
>>> checking, so figured I'd keep most of the changes in the same file.
>>
>> I figured the wrapper could could just not even bother calling into C
>> in the case of an empty list? But in any case, additional error
>> checking is good.
>
>
> I'll take a deeper look at the whole thing, and write up a new patch.
> You can probably hold off reviewing the old one, Zach.  I will
> probably move the index/result agreement to python, as long as I'm
> making significant changes.
>
> I don't think the label & index arguments need to handle arbitrary
> types (so no complex, object, or string arrays).  However, the code
> could be written to do so.  Opinions?

The main person that has an opinion about ndimage is Stefan.

The long term intention is to rewrite ndimage in cython, but I don't think
this will happen anytime soon.

Since I'm not used to reading python interface code in c, I never looked at
the details of ticket 412.

My opinion is that it is easy to convert labels and index to integers, so if
ndimage only handles index of type long (and makes a type check) this should
be enough.

However, as ticket 412 indicates, if the generality of types is already in
labels, then index could just match the type restriction of labels. I tried
out some types, see below.  labels can be floating point, but not string or
complex. There was a question recently on the mailing list asking for a
function, where he could have used ndimage.measurements if it supported
floats.

So, if you are able to allow for floating point index, same as for labels,
then this looks to me like a clean solution, that just extends the current
functionality in a consistent way.

Josef


import numpy as np
from scipy import ndimage

input_ =  [0,1,2,3]
labels = [1,1,2,2]
print ndimage.sum(input_, labels, index=[1,2])

# these raises runtime error data type not supported
#print ndimage.sum(np.array(input_).astype(str), labels, index=[1,2])
#print ndimage.sum(input_, np.array(labels).astype(str))
# this works
print ndimage.sum(input_, np.array(labels).astype(float))
# this works
print ndimage.sum(input_, np.array(labels).astype(float),
                 np.array(np.unique(labels)))
print ndimage.sum(input_, np.array(labels).astype('float64'))
# these raises runtime error data type not supported
#print ndimage.sum(input_, np.array(labels).astype('complex64'))

# this segfaults:
#print ndimage.sum(input_, np.array(labels).astype(float),
#                          np.array(np.unique(labels)).astype(float))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20090419/0338679c/attachment.html>


More information about the SciPy-Dev mailing list