[Numpy-discussion] Code generator bug and fix?

Charles R Harris charlesr.harris@gmail....
Mon Apr 21 21:53:20 CDT 2008


On Mon, Apr 21, 2008 at 8:28 PM, Travis E. Oliphant <oliphant@enthought.com>
wrote:

> Charles R Harris wrote:
> > I've gotten my own python class with a logical_not method to work
> > correctly if I goto numpy/core/code_generators/generate_umath.py and
> > change
> I need more context for this.   Why does the umath generator matter for
> your python class?
> >
> > 'logical_not' :
> >     Ufunc(1, 1, None,
> >           'returns not x elementwise.',
> >           TD(noobj, out='?'),
> >           TD(M, f='logical_not', out='?'),
> >           ),
> >
> > to
> >
> > 'logical_not' :
> >     Ufunc(1, 1, None,
> >           'returns not x elementwise.',
> >           TD(noobj, out='?'),
> >           TD(M, f='logical_not'),
> >           ),
> >
> Why is this an error?   Is the difference only removing the out
> variable?  It's been a while since I reviewed this code, so what does
> removing the out variable do functionally (What is the difference in the
> ufunc that is generated)?
>

The way it is, it passes a boolean array to the PyUFunc_O_O_method loop
where the loop is expecting an object array. I checked the step size to see
this, and that's also how the generated signature reads. Consequently, when
the reference count is decremented bad things happen. I suspect this hasn't
been seen before because it hadn't been tried. I wrote loop tests before
cleaning up the loop code and the bug turned up then.

My guess is that here M means object called through non-Python method
(logical_not), and omitting out means the output type is the same as the
input. I suspect that '?' should do the same thing and that there might be a
bug in the function dispatcher or the signature generator, but I'm not clear
on that yet.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080421/b6ed7b3e/attachment-0001.html 


More information about the Numpy-discussion mailing list