Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add implementation of dpnp.unique#1972

Merged
antonwolfy merged 13 commits intomasterIntelPython/dpnp:masterfrom
impl_uniqueIntelPython/dpnp:impl_uniqueCopy head branch name to clipboard
Aug 16, 2024
Merged

Add implementation of dpnp.unique#1972
antonwolfy merged 13 commits intomasterIntelPython/dpnp:masterfrom
impl_uniqueIntelPython/dpnp:impl_uniqueCopy head branch name to clipboard

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
@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2024

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

Copy link
Contributor

@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
@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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.