<br><br><div class="gmail_quote">On Mon, Apr 21, 2008 at 9:09 PM, Travis E. Oliphant <<a href="mailto:oliphant@enthought.com">oliphant@enthought.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Charles R Harris wrote:<br>
><br>
><br>
> On Mon, Apr 21, 2008 at 8:53 PM, Charles R Harris<br>
</div><div class="Ih2E3d">> <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a> <mailto:<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>>> wrote:<br>
><br>
><br>
><br>
>     On Mon, Apr 21, 2008 at 8:28 PM, Travis E. Oliphant<br>
</div><div><div></div><div class="Wj3C7c">>     <<a href="mailto:oliphant@enthought.com">oliphant@enthought.com</a> <mailto:<a href="mailto:oliphant@enthought.com">oliphant@enthought.com</a>>> wrote:<br>
><br>
>         Charles R Harris wrote:<br>
>         > I've gotten my own python class with a logical_not method to<br>
>         work<br>
>         > correctly if I goto<br>
>         numpy/core/code_generators/generate_umath.py and<br>
>         > change<br>
>         I need more context for this.   Why does the umath generator<br>
>         matter for<br>
>         your python class?<br>
>         ><br>
>         > 'logical_not' :<br>
>         >     Ufunc(1, 1, None,<br>
>         >           'returns not x elementwise.',<br>
>         >           TD(noobj, out='?'),<br>
>         >           TD(M, f='logical_not', out='?'),<br>
>         >           ),<br>
>         ><br>
>         > to<br>
>         ><br>
>         > 'logical_not' :<br>
>         >     Ufunc(1, 1, None,<br>
>         >           'returns not x elementwise.',<br>
>         >           TD(noobj, out='?'),<br>
>         >           TD(M, f='logical_not'),<br>
>         >           ),<br>
>         ><br>
>         Why is this an error?   Is the difference only removing the out<br>
>         variable?  It's been a while since I reviewed this code, so<br>
>         what does<br>
>         removing the out variable do functionally (What is the<br>
>         difference in the<br>
>         ufunc that is generated)?<br>
><br>
><br>
>     The way it is, it passes a boolean array to the PyUFunc_O_O_method<br>
>     loop where the loop is expecting an object array. I checked the<br>
>     step size to see this, and that's also how the generated signature<br>
>     reads. Consequently, when the reference count is decremented bad<br>
>     things happen. I suspect this hasn't been seen before because it<br>
>     hadn't been tried. I wrote loop tests before cleaning up the loop<br>
>     code and the bug turned up then.<br>
><br>
>     My guess is that here M means object called through non-Python<br>
>     method (logical_not), and omitting out means the output type is<br>
>     the same as the input. I suspect that '?' should do the same thing<br>
>     and that there might be a bug in the function dispatcher or the<br>
>     signature generator, but I'm not clear on that yet.<br>
><br>
><br>
> If out is omitted, the output types matches the input types. Here's<br>
> where the output types are generated:<br>
><br>
>     def finish_signature(self, nin, nout):<br>
>         if self.in_ is None:<br>
>             self.in_ = self.type * nin<br>
>         assert len(self.in_) == nin<br>
>         if self.out is None:<br>
>             self.out = self.type * nout<br>
>         assert len(self.out) == nout<br>
><br>
> So that seems like the right thing to do. I still don't know what  '?'<br>
> means, though.<br>
<br>
</div></div>Thanks Chuck,<br>
<br>
I get it now (I should have spent a minute looking at the code).  The<br>
'?' is the character code for "boolean"<br>
<br>
So, I think you are right about the bug.<br>
<div><div></div><div class="Wj3C7c"></div></div></blockquote><div><br>I note that other logical operators, <, ==, do in fact return booleans when operating on objects. So another fix is to write special case loops for logical_{not, or, and, xor} that do the same. Perhaps a ticket for an enhancement should be opened.<br>
<br>Chuck <br></div><br></div><br>