[Numpy-discussion] I've just commited a fast-clip function

Stefan van der Walt stefan@sun.ac...
Fri Mar 30 08:02:48 CDT 2007


Hi Travis

On Thu, Mar 29, 2007 at 11:21:07PM -0600, Travis Oliphant wrote:
> I've just committed a revision of ticket #425 to speed up clipping in 
> the scalar case.  I also altered the PyArray_Conjugate function (called 
> by the conjugate method) to use the ufunc for complex data. 
> 
> These were some relatively largish changes to the source code (all 
> behind the scences and no interface changes) --- enough to make me want 
> to see some more testing. 
>  
> I would appreciate it, if people could test out the new clip function 
> and conjugate method to make sure they are working well.  All tests 
> pass, but there are some things we are not testing for.  I need to still 
> add the clip tests from ticket #425 --- unless somebody beats me to
> it.

While writing some tests, I saw that the comparitor operators are now
less than happy:

import numpy as N
x = (N.random.random(2000)*1024).astype(N.float32)
x.clip(0.,0.,x)
N.all(x <= 0.)
N.all(x >= 0.)

causes errors like these:

==26879== Invalid read of size 4
==26879==    at 0x46219C3: PyArray_IterNew (arrayobject.c:8791)
==26879==    by 0x467B7B6: construct_loop (ufuncobject.c:1222)
==26879==    by 0x467C872: PyUFunc_GenericFunction (ufuncobject.c:1751)
==26879==    by 0x467D9AA: ufunc_generic_call (ufuncobject.c:3064)
==26879==    by 0x805B22C: (within /usr/bin/python2.5)
==26879==    by 0x805E7DE: _PyObject_CallFunction_SizeT (in /usr/bin/python2.5)
==26879==    by 0x461F49F: PyArray_GenericBinaryFunction (arrayobject.c:3362)
==26879==    by 0x464F2B8: array_richcompare (arrayobject.c:4639)
==26879==    by 0x808634F: (within /usr/bin/python2.5)
==26879==    by 0x8087E64: PyObject_RichCompare (in /usr/bin/python2.5)

==26879== Invalid read of size 4
==26879==    at 0x463B0D2: PyArray_FromArray (arrayobject.c:7947)
==26879==    by 0x4631345: PyArray_FromAny (arrayobject.c:8368)
==26879==    by 0x467B302: construct_loop (ufuncobject.c:1147)
==26879==    by 0x467C872: PyUFunc_GenericFunction (ufuncobject.c:1751)
==26879==    by 0x467D9AA: ufunc_generic_call (ufuncobject.c:3064)
==26879==    by 0x805B22C: (within /usr/bin/python2.5)
==26879==    by 0x805E7DE: _PyObject_CallFunction_SizeT (in /usr/bin/python2.5)
==26879==    by 0x461F49F: PyArray_GenericBinaryFunction (arrayobject.c:3362)
==26879==    by 0x464F2B8: array_richcompare (arrayobject.c:4639)
==26879==    by 0x808634F: (within /usr/bin/python2.5)

Cheers
Stéfan


More information about the Numpy-discussion mailing list