Skip to content

BUG: Return correctly shaped inverse indices in array_api set functions #20791

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

Merged
merged 2 commits into from
Jan 13, 2022

Conversation

honno
Copy link
Contributor

@honno honno commented Jan 11, 2022

As inverse indices from np.unique() are flattened when axis=None (the default), the related array_api set functions (xp.unique_inverse/xp.unique_all) don't return shape-sharing indices as the Array API specifies. This PR fixes this by internally reshaping the inverse indices.

Tested in array-api-tests , specifically https://github.com/data-apis/array-api-tests/blob/master/array_api_tests/test_set_functions.py. Note these tests will fail due to unrelated NaN-uniqueness issues.

Related #20638

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Jan 11, 2022
@charris charris added this to the 1.22.1 release milestone Jan 11, 2022
@charris
Copy link
Member

charris commented Jan 12, 2022

If there is a test for this, could you add it here?

@honno honno force-pushed the xp-inverse-indices branch from 5420bb2 to ccc1091 Compare January 13, 2022 10:04
@honno
Copy link
Contributor Author

honno commented Jan 13, 2022

If there is a test for this, could you add it here?

Done! Like with #20788, I've added a test which just hones in on the diverging behaviour from NumPy proper here i.e. inverse indices sharing the input array shape.

Hope that's okay—the tests in array-api-tests do a lot and so are probably inappropriate for the NumPy CI. Quoting @asmeurer from #18585 (comment)

We have to test suite to test for spec compliance, and I think we should mainly keep to that as far as that goes

@charris charris merged commit 7191d9a into numpy:main Jan 13, 2022
@charris charris added component: numpy.array_api and removed 09 - Backport-Candidate PRs tagged should be backported labels Jan 13, 2022
@charris charris removed this from the 1.22.1 release milestone Jan 13, 2022
@charris
Copy link
Member

charris commented Jan 13, 2022

Thanks @honno .

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

Successfully merging this pull request may close these issues.

2 participants