Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"iscomplexobj",
"isfinite",
"isfortran",
"isin",
"isinf",
"isnan",
"isneginf",
Expand Down Expand Up @@ -1115,6 +1116,95 @@ def isfortran(a):
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):

"""
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``

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.


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}

Input array.
test_elements : {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
test_elements : {array_like, dpnp.ndarray, usm_ndarray}
test_elements : {dpnp.ndarray, usm_ndarray, scalar}

The values against which to test each value of `element`.
This argument is flattened if it is an array or array_like.
See notes for behavior with non-array-like parameters.
Comment on lines +1131 to +1132
Copy link
Contributor

Choose a reason for hiding this comment

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

no notes provided below, so the reference on it can be removed

Suggested change
This argument is flattened if it is an array or array_like.
See notes for behavior with non-array-like parameters.
This argument is flattened if it is an array.

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

invert : bool, optional
If True, the values in the returned array are inverted, as if
calculating `element not in test_elements`. Default is False.
Comment on lines +1136 to +1137
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`.

``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``.


Returns
-------
isin : dpnp.ndarray of bool dtype
Has the same shape as `element`. The values `element[isin]`
are in `test_elements`.


Examples
--------
>>> import dpnp as np
>>> element = 2*np.arange(4).reshape((2, 2))
>>> element
array([[0, 2],
[4, 6]])
>>> test_elements = [1, 2, 4, 8]
>>> mask = np.isin(element, test_elements)
>>> mask
array([[False, True],
[ True, False]])
>>> element[mask]
array([2, 4])

The indices of the matched values can be obtained with `nonzero`:

>>> np.nonzero(mask)
(array([0, 1]), array([1, 0]))

The test can also be inverted:

>>> mask = np.isin(element, test_elements, invert=True)
>>> mask
array([[ True, False],
[False, True]])
>>> element[mask]
array([0, 6])

"""

dpnp.check_supported_arrays_type(element, test_elements, scalar_type=True)
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)
Comment on lines +1181 to +1197
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)

return dpnp.get_result_array(
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,

invert=invert,
)
)


_ISINF_DOCSTRING = """
Tests each element :math:`x_i` of the input array `x` to determine if equal to
positive or negative infinity.
Expand Down
Loading