Skip to content
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

Add implementation of dpnp.unique #1972

Merged
merged 13 commits into from
Aug 16, 2024
Merged

Add implementation of dpnp.unique #1972

merged 13 commits into from
Aug 16, 2024

Conversation

antonwolfy
Copy link
Contributor

@antonwolfy antonwolfy commented Aug 6, 2024

The PR adds implementation of dpnp.unique function.

The implementation leverages on dpctl.tensor implementation when axis is None. Otherwise it is implemented through python calls. The functionality is covered by new tests and enabled third party tests.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to 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?
  • If this PR is a work in progress, are you filing the PR as a draft?

@antonwolfy antonwolfy self-assigned this Aug 6, 2024
Copy link
Contributor

github-actions bot commented Aug 6, 2024

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

Copy link
Collaborator

@vtavana vtavana left a comment

Choose a reason for hiding this comment

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

When axis is given NumPy list all rows with NaN at the bottom while dpnp does not.

import dpnp, numpy
import numpy as np

a = numpy.array([[1, 0, 0], [1, 0, 0], [np.nan, np.nan, np.nan], [2, 3, 4], [1, 0, 1], [np.nan, np.nan, np.nan]])
numpy.unique(a, axis=0)
# array([[ 1.,  0.,  0.],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#       [nan, nan, nan],
#       [nan, nan, nan]])

dpnp.unique(dpnp.asarray(a), axis=0)
#array([[ 1.,  0.,  0.],
#       [nan, nan, nan],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#      [nan, nan, nan]])

In addition equal_nan=True is not working as expected when axis is given for both NumPy and dpnp. Is it the way it should be?

import dpnp, numpy
import numpy as np

a = numpy.array([[1, 0, 0], [1, 0, 0], [np.nan, np.nan, np.nan], [2, 3, 4], [1, 0, 1], [np.nan, np.nan, np.nan]])
numpy.unique(a, axis=0, equal_nan=True)
# array([[ 1.,  0.,  0.],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#       [nan, nan, nan],
#       [nan, nan, nan]])

dpnp.unique(dpnp.asarray(a), axis=0, equal_nan=True)
#array([[ 1.,  0.,  0.],
#       [nan, nan, nan],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#      [nan, nan, nan]])

dpnp/dpnp_iface_manipulation.py Show resolved Hide resolved
dpnp/dpnp_iface_manipulation.py Show resolved Hide resolved
@antonwolfy antonwolfy merged commit 82cb5ec into master Aug 16, 2024
8 of 9 checks passed
@antonwolfy antonwolfy deleted the impl_unique branch August 16, 2024 09:35
@antonwolfy
Copy link
Contributor Author

antonwolfy commented Aug 16, 2024

When axis is given NumPy list all rows with NaN at the bottom while dpnp does not.

import dpnp, numpy
import numpy as np

a = numpy.array([[1, 0, 0], [1, 0, 0], [np.nan, np.nan, np.nan], [2, 3, 4], [1, 0, 1], [np.nan, np.nan, np.nan]])
numpy.unique(a, axis=0)
# array([[ 1.,  0.,  0.],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#       [nan, nan, nan],
#       [nan, nan, nan]])

dpnp.unique(dpnp.asarray(a), axis=0)
#array([[ 1.,  0.,  0.],
#       [nan, nan, nan],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#      [nan, nan, nan]])

In addition equal_nan=True is not working as expected when axis is given for both NumPy and dpnp. Is it the way it should be?

import dpnp, numpy
import numpy as np

a = numpy.array([[1, 0, 0], [1, 0, 0], [np.nan, np.nan, np.nan], [2, 3, 4], [1, 0, 1], [np.nan, np.nan, np.nan]])
numpy.unique(a, axis=0, equal_nan=True)
# array([[ 1.,  0.,  0.],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#       [nan, nan, nan],
#       [nan, nan, nan]])

dpnp.unique(dpnp.asarray(a), axis=0, equal_nan=True)
#array([[ 1.,  0.,  0.],
#       [nan, nan, nan],
#       [ 1.,  0.,  1.],
#       [ 2.,  3.,  4.],
#      [nan, nan, nan]])

Thank you for noticing that.
I will handle the comment by separate PR if you don't mind.

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.

2 participants