Skip to content

Conversation

@OmarManzoor
Copy link
Contributor

Fixes #491

  • Adds the union1d function.

@lucascolley lucascolley added enhancement New feature or request new function labels Oct 24, 2025
@lucascolley lucascolley changed the title ENH Add union1d ENH: new function union1d Oct 24, 2025
@lucascolley lucascolley self-requested a review October 24, 2025 11:54
@lucascolley lucascolley added this to the 0.9.1 milestone Oct 28, 2025
@lucascolley
Copy link
Member

Relevant upstream context from data-apis/array-api#25 @kgryte :

NumPy includes additional set functions (e.g., in1d, intersect1d, isin, setdiff1d, union1d, setxor1d); however, these functions are not widely implemented by other analyzed array libraries ( see here) and, thus, were not included in this initial specification. Should additional set functions be necessary, they can be proposed in follow-up proposals.

Given @paddyroddy's analysis in gh-491, it looks like absence from PyTorch might still be a blocker for inclusion in the standard? If so, probably fine to proceed with this PR.

Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @OmarManzoor, looks good!

@lucascolley lucascolley requested review from lucascolley and removed request for lucascolley November 7, 2025 10:06
@lucascolley
Copy link
Member

@hameerabbasi is there an existing discussion about sparse returning NumPy arrays for functions with naturally dense return values? Blosc does a similar thing with decompressed arrays, and there was a brief discussion at data-apis/array-api#968 (reply in thread) about whether this could be more aligned with the standard.

@OmarManzoor in the meantime, would wrapping the xp.unique_values call in xp.asarray fix the tests for sparse?

@lucascolley lucascolley removed their request for review November 16, 2025 14:14
@lucascolley lucascolley modified the milestones: 0.9.1, 0.9.2 Nov 21, 2025
@OmarManzoor
Copy link
Contributor Author

OmarManzoor commented Nov 25, 2025

@lucascolley Sorry about being a bit late in updating this. I wrapped the return value in xp.asarray like you suggested and removed the skipping of sparse

@hameerabbasi
Copy link

is there an existing discussion about sparse returning NumPy arrays for functions with naturally dense return values?

I can try to dig one up, but yes, that's the policy as of right now. sparse doesn't have a "dense" format in its current form so we return NumPy arrays instead.

@lucascolley lucascolley self-requested a review November 25, 2025 09:01
Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @OmarManzoor !

Can you add this to https://github.com/data-apis/array-api-extra/blob/main/docs/api-reference.md and check that pixi run open-docs looks good?

Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @OmarManzoor !

@lucascolley lucascolley merged commit 37dcc4b into data-apis:main Nov 25, 2025
11 checks passed
@OmarManzoor OmarManzoor deleted the add_union1d branch November 25, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: add union1d

3 participants