8000 array.nonzero(): Inconsistent behaviour · Issue #9304 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

array.nonzero(): Inconsistent behaviour #9304

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
jalammar opened this issue Jun 26, 2017 · 8 comments · Fixed by #9310
Closed

array.nonzero(): Inconsistent behaviour #9304

jalammar opened this issue Jun 26, 2017 · 8 comments · Fixed by #9310

Comments

@jalammar
Copy link
jalammar commented Jun 26, 2017

Calling nonzero() on an array of 5 or more dimensions sometimes returns inconsistent values. The following example sometimes returns all True values, but often it doesn't.

import numpy as np 

shape = [10, 2, 3, 4, 5, 6]
np.random.seed(2)
array = np.random.rand(*shape)

for i in range(10):
    benchmark = array.nonzero()
    result = array.nonzero()
    print(np.array_equal(benchmark, result))

Output:

False
True
True
False
False
True
True
False
False
True
@eric-wieser
Copy link
Member

Ouch, that is nasty. On my machine, that prints alternating True and False. Seems that the original array is not being mutated either

@pv
Copy link
Member
pv commented Jun 27, 2017 via email

@seberg seberg added this to the 1.13.1 release milestone Jun 27, 2017
@seberg
Copy link
Member
seberg commented Jun 27, 2017

Added 13.1 milestone if this really is a regression in 13.0 we might want to try to address it, but will leave for chuck to decide on the schedule.

@seberg
Copy link
Member
seberg commented Jun 27, 2017

In case it might help:

In [2]: benchmark = array.nonzero()
==10887== Invalid read of size 8
==10887==    at 0xB476B9C: PyArray_Nonzero (item_selection.c:2334)

@juliantaylor
Copy link
Contributor

yeah there is a bug using the wrong dimension there, fix should be simple

@pv
Copy link
Member
pv commented Jun 27, 2017 via email

@juliantaylor
Copy link
Contributor

it is a related one, the is_empty loop checks the wrong dimension

@juliantaylor
Copy link
Contributor

fix in gh-9310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
0