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!

xp_assert_equal(res, expected)


@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="unique_values returns arrays")
Copy link
Member

Choose a reason for hiding this comment

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

what is the problem here?

Comment on lines +1544 to +1546
expected = xp.asarray([-2, -1, 0, 1, 2])
res = union1d(a, b)
xp_assert_equal(res, expected)
Copy link
Member

Choose a reason for hiding this comment

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

do we need to be checking that the array is sorted? Or would it be sufficient to check that xp.sort(res) matches expected here?

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

2 participants