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

Numpy 2.0.0 breaks ismember #5

Open
leuraph opened this issue Jun 17, 2024 · 2 comments
Open

Numpy 2.0.0 breaks ismember #5

leuraph opened this issue Jun 17, 2024 · 2 comments

Comments

@leuraph
Copy link
Contributor

leuraph commented Jun 17, 2024

What has changed

From Numpy's 2.0.0 release notes, we know that

When multi-dimensional inputs are passed to np.unique with return_inverse=True, the unique_inverse output is now shaped such that the input can be reconstructed directly using np.take(unique, unique_inverse) when axis=None, and np.take_along_axis(unique, unique_inverse, axis=axis) otherwise.

Breaking Example

In practice, this means that the unit tests of ismember fail and, e.g. the following code breaks when switching from numpy==1.26.0 to numpy==2.0.0:

boundaries = np.array([
    [1,2],
    [3,4],
    [6,7],
    [10,11]
])
local_edges = np.array([
    [6,7],
    [3,4],
    [12,3]
])
is_local_boundary = ismember.is_row_in(
    boundaries, local_edges)
print(is_local_boundary.shape)
local_boundaries = boundaries[is_local_boundary]
IndexError: boolean index did not match indexed array along axis 1; size of axis is 2 but size of corresponding boolean axis is 1

Explanation

  • numpy==2.0.0: is_local_boundary has shape (4,1)
  • numpy==1.26.0: is_local_boundary has shape (4,)
@leuraph
Copy link
Contributor Author

leuraph commented Jun 17, 2024

@erdogant Do you have any suggestions/ideas on how to handle the situation? In case you do not have time but would appreciate someone looking into it, just let me know and I'll try my best :) For now, I will force usage of numpy<2.0.0 by hand whenever I use ismember.

@erdogant
Copy link
Owner

thank you for posting this issue. For now, I restricted installation < 2.0.0. I will look into this at a later moment.

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

No branches or pull requests

2 participants