Skip to content

Commit da2bd58

Browse files
authored
add unique function (#797)
* add unique function
1 parent 80d497d commit da2bd58

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"stack",
6868
"swapaxes",
6969
"transpose",
70+
"unique",
7071
"vstack"
7172
]
7273

@@ -619,6 +620,25 @@ def transpose(x1, axes=None):
619620
return call_origin(numpy.transpose, x1, axes=axes)
620621

621622

623+
def unique(x1, **kwargs):
624+
"""
625+
Find the unique elements of an array.
626+
627+
For full documentation refer to :obj:`numpy.unique`.
628+
629+
Examples
630+
--------
631+
>>> import dpnp as np
632+
>>> x = np.array([1, 1, 2, 2, 3, 3])
633+
>>> res = np.unique(x)
634+
>>> print(res)
635+
[1, 2, 3]
636+
637+
"""
638+
639+
return call_origin(numpy.unique, x1, **kwargs)
640+
641+
622642
def vstack(tup):
623643
"""
624644
Stack arrays in sequence vertically (row wise).

tests/test_manipulation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,21 @@ def test_repeat(arr):
3232
expected = numpy.repeat(a, 2)
3333
result = dpnp.repeat(dpnp_a, 2)
3434
numpy.testing.assert_array_equal(expected, result)
35+
36+
37+
@pytest.mark.parametrize("array",
38+
[[1, 2, 3],
39+
[1, 2, 2, 1, 2, 4],
40+
[2, 2, 2, 2],
41+
[]],
42+
ids=['[1, 2, 3]',
43+
'[1, 2, 2, 1, 2, 4]',
44+
'[2, 2, 2, 2]',
45+
'[]'])
46+
def test_unique(array):
47+
np_a = numpy.array(array)
48+
dpnp_a = dpnp.array(array)
49+
50+
expected = numpy.unique(np_a)
51+
result = dpnp.unique(dpnp_a)
52+
numpy.testing.assert_array_equal(expected, result)

0 commit comments

Comments
 (0)