Skip to content

Conversation

@emekaokoli19
Copy link
Contributor

Description

This PR updates the Unique operator to correctly follow the new NumPy 2.0 semantics for the return_inverse output.

NumPy 2.0 changed the shape of the inverse array:

When axis=None: inverse has the same shape as the input.

When axis=i: inverse has shape (input.shape[i],) instead of always being 1D and flattened.

PyTensor’s infer_shape() and perform() were updated for NumPy 2.0 behavior, but make_node() still declared the return_inverse output as a fixed 1D tensor shape=(None,), causing shape inference inconsistencies and failing tests.

This PR fixes the bug by updating make_node() to construct the return_inverse output with the correct shape based on NumPy 2.0 rules. After this change, the behaviour of make_node, infer_shape, and NumPy’s runtime is fully aligned, and all Unique shape inference tests pass.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@emekaokoli19
Copy link
Contributor Author

@ricardoV94 whenever free please take a look

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

Successfully merging this pull request may close these issues.

Switch Unique behavior from numpy < 2.0 to numpy >= 2.0

1 participant