Skip to content

Conversation

ndgrigorian
Copy link
Collaborator

This PR leverages the recently-added dpctl.tensor.isin to implement dpnp.isin

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

Copy link
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/2595/index.html

Copy link
Contributor

Array API standard conformance tests for dpnp=0.19.0dev6=py313h509198e_5 ran successfully.
Passed: 1227
Failed: 0
Skipped: 9

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 71.968% (-0.03%) from 71.998%
when pulling df81181 on reuse-tensor-isin
into 8906b0e on master.

@antonwolfy antonwolfy added this to the 0.20.0 release milestone Oct 7, 2025
return a.flags.fnc


def isin(element, test_elements, assume_unique=False, invert=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

NumPy supports also kind keyword, but we can limit it with only None and 'sort' values and state a limitation that 'table' is not supported

Suggested change
def isin(element, test_elements, assume_unique=False, invert=False):
def isin(element, test_elements, assume_unique=False, invert=False, *, kind=None):

def isin(element, test_elements, assume_unique=False, invert=False):
"""
Calculates ``element in test_elements``, broadcasting over `element` only.
Returns a boolean array of the same shape as `element` that is True
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Returns a boolean array of the same shape as `element` that is True
Returns a boolean array of the same shape as `element` that is ``True``

"""
Calculates ``element in test_elements``, broadcasting over `element` only.
Returns a boolean array of the same shape as `element` that is True
where an element of `element` is in `test_elements` and False otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
where an element of `element` is in `test_elements` and False otherwise.
where an element of `element` is in `test_elements` and ``False`` otherwise.

Calculates ``element in test_elements``, broadcasting over `element` only.
Returns a boolean array of the same shape as `element` that is True
where an element of `element` is in `test_elements` and False otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
For full documentation refer to :obj:`numpy.isin`.

Parameters
----------
element : {array_like, dpnp.ndarray, usm_ndarray}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
element : {array_like, dpnp.ndarray, usm_ndarray}
element : {dpnp.ndarray, usm_ndarray, scalar}

This argument is flattened if it is an array or array_like.
See notes for behavior with non-array-like parameters.
assume_unique : bool, optional
Ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be great to add more words

calculating `element not in test_elements`. Default is False.
``dpnp.isin(a, b, invert=True)`` is equivalent to (but faster
than) ``dpnp.invert(dpnp.isin(a, b))``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Default: ``False``.

Comment on lines +1136 to +1137
If True, the values in the returned array are inverted, as if
calculating `element not in test_elements`. Default is False.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If True, the values in the returned array are inverted, as if
calculating `element not in test_elements`. Default is False.
If ``True``, the values in the returned array are inverted, as if
calculating `element not in test_elements`.

dpt.isin(
usm_element,
usm_test,
assume_unique=assume_unique,
Copy link
Contributor

Choose a reason for hiding this comment

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

dpctl does not have that keyword

Suggested change
assume_unique=assume_unique,

Comment on lines +1181 to +1197
if dpnp.isscalar(element):
usm_element = dpt.asarray(
element,
sycl_queue=test_elements.sycl_queue,
usm_type=test_elements.usm_type,
)
usm_test = dpnp.get_usm_ndarray(test_elements)
elif dpnp.isscalar(test_elements):
usm_test = dpt.asarray(
test_elements,
sycl_queue=element.sycl_queue,
usm_type=element.usm_type,
)
usm_element = dpnp.get_usm_ndarray(element)
else:
usm_element = dpnp.get_usm_ndarray(element)
usm_test = dpnp.get_usm_ndarray(test_elements)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if dpnp.isscalar(element):
usm_element = dpt.asarray(
element,
sycl_queue=test_elements.sycl_queue,
usm_type=test_elements.usm_type,
)
usm_test = dpnp.get_usm_ndarray(test_elements)
elif dpnp.isscalar(test_elements):
usm_test = dpt.asarray(
test_elements,
sycl_queue=element.sycl_queue,
usm_type=element.usm_type,
)
usm_element = dpnp.get_usm_ndarray(element)
else:
usm_element = dpnp.get_usm_ndarray(element)
usm_test = dpnp.get_usm_ndarray(test_elements)
usm_element = dpnp.as_usm_ndarray(element, usm_type=test_elements.usm_type, sycl_queue=test_elements.sycl_queue)
usm_test = dpnp.as_usm_ndarray(test_elements, usm_type=element.usm_type, sycl_queue=element.sycl_queue)

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.

3 participants