Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix up Nan handling for max/amax/argmax/fmac + min/sort equivalent (Trac #1035) #1633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thouis opened this issue Oct 19, 2012 · 10 comments
Closed
Labels
00 - Bug component: numpy._core Priority: high High priority, also add milestones for urgent issues
Milestone

Comments

@thouis
Copy link
Contributor

thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1035 on 2009-03-03 by @cournape, assigned to @cournape.

This is a meta issue:

Extensive discussions on the ML:

http://mail.scipy.org/pipermail/numpy-discussion/2008-September/037413.html

Also some other issues:
#1518, #1484, #1307, #1392,

@numpy-gitbot
Copy link

Milestone changed to 1.4.0 by @cournape on 2009-11-25

@numpy-gitbot
Copy link

@charris wrote on 2010-01-05

I think this ticket is pretty much done.

sorts:

sort/argsort - sorts nans to end
searchsorted - works with sorted arrays containing nans

max/min:

max, amax, min, amin - propagate nans
argmax, argmin - non-propagating nans
fmax, fmin - non-propagating nans
fmax.reduce, fmin.reduce - non-propagating nans versions of maximum/minimum

max/argmax, min/argmin have incompatible behaviour, this needs a decision.

@numpy-gitbot
Copy link

@charris wrote on 2010-01-05

Reformat

  • sorts
    • sort/argsort - sorts nans to end
    • searchsorted - works with sorted arrays containing nans
  • max/min
    • max, amax, min, amin - propagate nans
    • argmax, argmin - non-propagating nans
    • fmax, fmin - non-propagating nans
    • fmax.reduce, fmin.reduce - non-propagating nans versions of maximum/minimum

max/argmax, min/argmin have incompatible behaviour, this needs a decision.

@numpy-gitbot
Copy link

@rgommers wrote on 2010-07-18

The priority of this is set as blocker, considering Charles comments I'm assuming that's no longer the case?

@numpy-gitbot
Copy link

@pv wrote on 2010-07-18

Let's try to nevertheless address the comparison-related issues for 1.5.0.

The argmin and argmax behavior should be harmonized by r8509, they now propagate nans. The previous behavior was actually undefined (cf. #2027), not non-propagating, so I think we can just change it as any code relying on the previous behavior is invalid.

***

The last question is what should be done with complex nans. I think they should be defined as

  • (z, nan), (nan, z), (nan, nan), where z is any fp value, are all equivalent representations of "cnan", as far as comparisons, sort order, etc are concerned.
  • The ordering between (z, nan), (nan, z), (nan, nan) is undefined. This means e.g. that maximum([cnan_1, cnan_2]) can return either cnan_1 or cnan_2 if both are some cnans.

I didn't check if sort handles cnans this way, but the other parts should be in place.

I changed the comparison operations to treat cnans according to the above way in r8508, since I don't think it makes sense for us to have

>>> np.complex64(complex(1,np.nan)) < np.complex64(complex(2,0))
True

This change also fixes a bug where maximum/minimum were not propagating complex nans properly.

@numpy-gitbot
Copy link

Milestone changed to 1.5.0 by @pv on 2010-07-18

@numpy-gitbot
Copy link

@charris wrote on 2010-07-18

Sorts and searchsorted don't handle cnans that way. They use the following comparison:

NPY_INLINE static int
@TYPE@_LT(@type@ a, @type@ b)
{
    int ret;

    if (a.real < b.real) {
        ret = a.imag == a.imag || b.imag != b.imag;
    }
    else if (a.real > b.real) {
        ret = b.imag != b.imag && a.imag == a.imag;
    }
    else if (a.real == b.real || (a.real != a.real && b.real != b.real)) {
        ret =  a.imag < b.imag || (b.imag != b.imag && a.imag == a.imag);
    }
    else {
        ret = b.real != b.real;
    }

    return ret;
}

So that (z,z), (z, nan), (nan, z), (nan, nan) are in order. See the release notes for 1.4.0.

@numpy-gitbot
Copy link

@mwiebe wrote on 2011-03-24

This looks like it's been dealt with.

@numpy-gitbot
Copy link

Milestone changed to Unscheduled by @mwiebe on 2011-03-24

@numpy-gitbot
Copy link

Milestone changed to 1.6.0 by @mwiebe on 2011-05-31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug component: numpy._core Priority: high High priority, also add milestones for urgent issues
Projects
None yet
Development

No branches or pull requests

2 participants