Skip to content
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

BUG: ravel_multi_index does not work on 0D arrays #15690

Open
eric-wieser opened this issue Mar 3, 2020 · 3 comments
Open

BUG: ravel_multi_index does not work on 0D arrays #15690

eric-wieser opened this issue Mar 3, 2020 · 3 comments
Labels

Comments

@eric-wieser
Copy link
Member

eric-wieser commented Mar 3, 2020

Reproduction:

>>> def test(n):
...     inds = np.zeros((n, 5), dtype=np.intp)
...     return np.ravel_multi_index(inds, (1,)*n)
>>> test(2)
array([0, 0, 0, 0, 0], dtype=int64)
>>> test(1)
array([0, 0, 0, 0, 0], dtype=int64)
>>> test(0)
ValueError: At least one iterator operand must be non-NULL

The expected result is array([0, 0, 0, 0, 0], dtype=int64) for all cases.

Relates to gh-13934.

@eric-wieser eric-wieser changed the title ravel_multi_index does not work on 0D arrays BUG: ravel_multi_index does not work on 0D arrays Mar 3, 2020
@eric-wieser
Copy link
Member Author

eric-wieser commented Mar 3, 2020

Hmm, I think I've seen this before (edit: gh-580). The issue is that the signature of ravel_multi_index is really:

ravel_multi_index(multi_index: Sequence[np.ndarray], shape: tuple)

and not

ravel_multi_index(multi_index: np.ndarray, shape: tuple)

As a result, ravel_multi_index has no shape information available.

This is the reverse of the arr_0d.nonzero() problem.

@madphysicist
Copy link
Contributor

FWIW, this has the same problem:

def test(n):
    inds = np.zeros(5, dtype=np.intp)
    return np.ravel_multi_index((inds,) * n, (1,)*n)
ValueError: At least one iterator operand must be non-NULL

@madphysicist
Copy link
Contributor

I had to put in a workaround for this recently, so let me know if you start working on a solution.

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

No branches or pull requests

2 participants