ndimage.label - howto force SWIG to use int32 - even on 64bit Linux ?
Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system . BTW, could this be considered a bug ? Now, if I use the typemaps of numpy.i I can choose between NPY_LONG and NPY_INT. But those are sometimes 32 sometimes 64 bit, depending on the system. Any ideas ... ? Thanks, Sebastian Haase
(2nd try to get this post into the mailing list archive...) Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system . BTW, could this be considered a bug ? Now, if I use the typemaps of numpy.i I can choose between NPY_LONG and NPY_INT. But those are sometimes 32 sometimes 64 bit, depending on the system. Any ideas ... ? Thanks, Sebastian Haase
On Tue, Apr 27, 2010 at 2:27 AM, Sebastian Haase <seb.haase@gmail.com>wrote:
Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system .
BTW, could this be considered a bug ?
Likely.
Now, if I use the typemaps of numpy.i I can choose between NPY_LONG and NPY_INT. But those are sometimes 32 sometimes 64 bit, depending on the system.
Any ideas ... ?
npy_intp. Chuck
Both types of typemaps are enabled, so you just need to do you %apply directives correctly: %apply (npy_intp* IN_ARRAY1, int DIM1) {(npy_intp* seq, int n)}; etc.... SWIG should be able to figure it out from there. On Apr 28, 2010, at 12:58 PM, Charles R Harris wrote:
On Tue, Apr 27, 2010 at 2:27 AM, Sebastian Haase <seb.haase@gmail.com> wrote: Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system .
BTW, could this be considered a bug ?
Likely.
Now, if I use the typemaps of numpy.i I can choose between NPY_LONG and NPY_INT. But those are sometimes 32 sometimes 64 bit, depending on the system.
Any ideas ... ?
npy_intp.
Chuck
** Bill Spotz ** ** Sandia National Laboratories Voice: (505)845-0170 ** ** P.O. Box 5800 Fax: (505)284-0154 ** ** Albuquerque, NM 87185-0370 Email: wfspotz@sandia.gov **
Thanks for those replies. But isn't npy_intp about pointers ? I would need something like npy_int32 . But does that exist ? Where is the list of types that numpy.i supports ? Also, BTW, is there code duplication if numpy.i supports (let's say) both npy_int and npy_int32 on a machine, where "int" is already 32 bits by default !? (I'm talking about the size of the resulting object file, I guess...) Thanks again for your help, Sebastian On Wed, Apr 28, 2010 at 11:51 PM, Bill Spotz <wfspotz@sandia.gov> wrote:
Both types of typemaps are enabled, so you just need to do you %apply directives correctly:
%apply (npy_intp* IN_ARRAY1, int DIM1) {(npy_intp* seq, int n)}; etc....
SWIG should be able to figure it out from there.
On Apr 28, 2010, at 12:58 PM, Charles R Harris wrote:
On Tue, Apr 27, 2010 at 2:27 AM, Sebastian Haase <seb.haase@gmail.com> wrote: Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system .
BTW, could this be considered a bug ?
Likely.
Now, if I use the typemaps of numpy.i I can choose between NPY_LONG and NPY_INT. But those are sometimes 32 sometimes 64 bit, depending on the system.
Any ideas ... ?
npy_intp.
Chuck
** Bill Spotz ** ** Sandia National Laboratories Voice: (505)845-0170 ** ** P.O. Box 5800 Fax: (505)284-0154 ** ** Albuquerque, NM 87185-0370 Email: wfspotz@sandia.gov **
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Thu, Apr 29, 2010 at 1:52 AM, Sebastian Haase <seb.haase@gmail.com>wrote:
Thanks for those replies. But isn't npy_intp about pointers ?
At one point perhaps, but how it is used is to get 32 bits on 32 OS's and 64 bits on 64 bit OS's, For the common architectures int will always be 32 bits regardless, it is the long type that moves around depending on both bits and os.
I would need something like npy_int32 . But does that exist ? Where is the list of types that numpy.i supports ? Also, BTW, is there code duplication if numpy.i supports (let's say) both npy_int and npy_int32 on a machine, where "int" is already 32 bits by default !? (I'm talking about the size of the resulting object file, I guess...)
Chuck
Hello everyone, Is there a 'numpy' efficient way to do the following loop: for i, v in indices, values: total[ i ] += v The behaviour is like numpy.put, but instead of overwriting the array element, it is incremented. Currently I have a little C extension which does the job, but I'm lazy to fix it up for all the various dtypes etc. Am I missing a more general way? I have repeated values in indices, so that: total[indices]+=values ... does not give the result I'm after. Thanks Jon
On Thu, Apr 29, 2010 at 03:28, Jon Wright <wright@esrf.fr> wrote:
Hello everyone,
Is there a 'numpy' efficient way to do the following loop:
for i, v in indices, values: total[ i ] += v
The behaviour is like numpy.put, but instead of overwriting the array element, it is incremented. Currently I have a little C extension which does the job, but I'm lazy to fix it up for all the various dtypes etc. Am I missing a more general way?
total = np.bincount(indices, values) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Hi Sebastian On 27 April 2010 10:27, Sebastian Haase <seb.haase@gmail.com> wrote:
Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system .
I've merged Thouis's patch to implement scikits.image.measurements in pure Python. Would you please try the SVN version and see if it solves your problem, and also whether it performs to your satisfaction? Regards Stéfan
Hi Stéfan, I have actually not been using scikits.image so far. Maybe I should give it a try. Are you saying that scikits.image.measurements has its own implementation of ndimage.label !? My original post was actually referring to a C++ function I wrote to calculate 2nd-order moments of labeled objects. I have that restricted to 3D contiguous data. scikits.image might already have had this function implementer in a general way ;-) Regards, Sebastian 2010/5/1 Stéfan van der Walt <stefan@sun.ac.za>:
Hi Sebastian
On 27 April 2010 10:27, Sebastian Haase <seb.haase@gmail.com> wrote:
Hi, I wanted to write some C code to accept labels as they come from ndimage.label. For some reason ndimage.label produces its output as an int32 array - even on my 64bit system .
I've merged Thouis's patch to implement scikits.image.measurements in pure Python. Would you please try the SVN version and see if it solves your problem, and also whether it performs to your satisfaction?
Regards Stéfan _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Hi Sebastian On 3 May 2010 09:55, Sebastian Haase <seb.haase@gmail.com> wrote:
I have actually not been using scikits.image so far. Maybe I should give it a try. Are you saying that scikits.image.measurements has its own implementation of ndimage.label !?
Sorry, I wasn't focusing: I merged his patch into scipy.ndimage. Regards Stéfan
participants (6)
-
Bill Spotz
-
Charles R Harris
-
Jon Wright
-
Robert Kern
-
Sebastian Haase
-
Stéfan van der Walt