-
Notifications
You must be signed in to change notification settings - Fork 23
Implement dpnp.isin
#2595
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
base: master
Are you sure you want to change the base?
Implement dpnp.isin
#2595
Conversation
de4e3bb
to
df81181
Compare
View rendered docs @ https://intelpython.github.io/dpnp/pull/2595/index.html |
Array API standard conformance tests for dpnp=0.19.0dev6=py313h509198e_5 ran successfully. |
return a.flags.fnc | ||
|
||
|
||
def isin(element, test_elements, assume_unique=False, invert=False): |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For full documentation refer to :obj:`numpy.isin`. | |
Parameters | ||
---------- | ||
element : {array_like, dpnp.ndarray, usm_ndarray} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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))``. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default: ``False``. | |
If True, the values in the returned array are inverted, as if | ||
calculating `element not in test_elements`. Default is False. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
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
assume_unique=assume_unique, |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
This PR leverages the recently-added
dpctl.tensor.isin
to implementdpnp.isin