numpy.sign(numpy.nan)?????

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

numpy.sign(numpy.nan)?????

Stuart Brorson
Hi guys,

Just a quick note.  I've been playing with NumPy again, looking at
corner cases of function evaluation.  I noticed this:

In [66]: numpy.sign(numpy.nan)
Out[66]: 0.0

IMO, the output should be NaN, not zero.

If you agree, then I'll be happy to file a bug in the NumPy tracker.
Or if somebody feels like pointing me to the place where this is
implemented, I can submit a patch.  (I grepped through the source for
"sign" to see if I could figure it out, but it occurs so frequently
that it will take longer than 5 min to sort it all out.)

Before I did anything, however, I thought I would solicit the opinions
of other folks in the NumPy community about the proper behavior of
numpy.sign(numpy.nan).


Cheers,

Stuart Brorson
Interactive Supercomputing, inc.
135 Beaver Street | Waltham | MA | 02452 | USA
http://www.interactivesupercomputing.com/
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy.sign(numpy.nan)?????

Robert Kern-2
On Fri, May 16, 2008 at 11:23 AM, Stuart Brorson <[hidden email]> wrote:

> Hi guys,
>
> Just a quick note.  I've been playing with NumPy again, looking at
> corner cases of function evaluation.  I noticed this:
>
> In [66]: numpy.sign(numpy.nan)
> Out[66]: 0.0
>
> IMO, the output should be NaN, not zero.
>
> If you agree, then I'll be happy to file a bug in the NumPy tracker.
> Or if somebody feels like pointing me to the place where this is
> implemented, I can submit a patch.  (I grepped through the source for
> "sign" to see if I could figure it out, but it occurs so frequently
> that it will take longer than 5 min to sort it all out.)
>
> Before I did anything, however, I thought I would solicit the opinions
> of other folks in the NumPy community about the proper behavior of
> numpy.sign(numpy.nan).

You're probably right. I would like to see what other systems do
before changing it, though.

The implementation is actually in a #define macro in
umathmodule.c.src. Look for _SIGN1 (and _SIGNC if you want to clean up
the complex versions, too).

--
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
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy.sign(numpy.nan)?????

Keith Goodman
On Fri, May 16, 2008 at 11:23 AM, Robert Kern <[hidden email]> wrote:
> On Fri, May 16, 2008 at 11:23 AM, Stuart Brorson <[hidden email]> wrote:
>> In [66]: numpy.sign(numpy.nan)
>> Out[66]: 0.0
>>
>> IMO, the output should be NaN, not zero.
>
> You're probably right. I would like to see what other systems do
> before changing it, though.

octave:1> sign(nan)
ans = NaN
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy.sign(numpy.nan)?????

Robert Kern-2
On Fri, May 16, 2008 at 2:27 PM, Keith Goodman <[hidden email]> wrote:

> On Fri, May 16, 2008 at 11:23 AM, Robert Kern <[hidden email]> wrote:
>> On Fri, May 16, 2008 at 11:23 AM, Stuart Brorson <[hidden email]> wrote:
>>> In [66]: numpy.sign(numpy.nan)
>>> Out[66]: 0.0
>>>
>>> IMO, the output should be NaN, not zero.
>>
>> You're probably right. I would like to see what other systems do
>> before changing it, though.
>
> octave:1> sign(nan)
> ans = NaN

Works for me.

--
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
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy.sign(numpy.nan)?????

Stuart Brorson
In reply to this post by Robert Kern-2
Hi --

>> In [66]: numpy.sign(numpy.nan)
>> Out[66]: 0.0
>>
>> IMO, the output should be NaN, not zero.

> You're probably right. I would like to see what other systems do
> before changing it, though.

Here's what Matlab does:

>> A = nan

A =

    NaN

>> sign(A)

ans =

    NaN

>> B = [1, nan]

B =

      1   NaN

>> sign(B)

ans =

      1   NaN


Cheers,

Stuart Brorson
Interactive Supercomputing, inc.
135 Beaver Street | Waltham | MA | 02452 | USA
http://www.interactivesupercomputing.com/

_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy.sign(numpy.nan)?????

Stuart Brorson
In reply to this post by Robert Kern-2
>> In [66]: numpy.sign(numpy.nan)
>> Out[66]: 0.0
>>
>> IMO, the output should be NaN, not zero.

> The implementation is actually in a #define macro in
> umathmodule.c.src. Look for _SIGN1 (and _SIGNC if you want to clean up
> the complex versions, too).

OK, I submitted a patch.  #794 in the tracker.

Stuart Brorson
Interactive Supercomputing, inc.
135 Beaver Street | Waltham | MA | 02452 | USA
http://www.interactivesupercomputing.com
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy.sign(numpy.nan)?????

Charles R Harris


On Sat, May 17, 2008 at 5:55 AM, Stuart Brorson <[hidden email]> wrote:
>> In [66]: numpy.sign(numpy.nan)
>> Out[66]: 0.0
>>
>> IMO, the output should be NaN, not zero.

> The implementation is actually in a #define macro in
> umathmodule.c.src. Look for _SIGN1 (and _SIGNC if you want to clean up
> the complex versions, too).

OK, I submitted a patch.  #794 in the tracker.

Let's wait until the 1.2 branch opens so as to avoid merge collisions. I'll fix these things up at that point.

Chuck



_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion