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

Update dpnp.diagonal() #1817

Merged
merged 15 commits into from
May 11, 2024
Merged

Update dpnp.diagonal() #1817

merged 15 commits into from
May 11, 2024

Conversation

vlad-perevezentsev
Copy link
Collaborator

@vlad-perevezentsev vlad-perevezentsev commented May 9, 2024

This PR suggests an updated implementation of dpnp.diagonal() including support for axis1, axis2 and negative offset parameters.

The new implementation shows performance improvements over the old implementation:

In [1]: import dpnp
 
In [2]: import numpy
 
In [3]: na = numpy.random.randint(-10**4, 10**4, size=(4096,4096))
 
In [4]: a = numpy.array(na,dtype='int32')
 
In [5]: a_dp = dpnp.array(a)
 
In [6]: res_dp = dpnp.diagonal(a_dp)
 
In [7]: %timeit -n 10 res_dp = dpnp.diagonal(a_dp)
16.9 ms ± 1.59 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
 
In [8]: %timeit -n 10 res_dp = dpnp.diagonal(a_dp,new=True)
17.8 µs ± 6.47 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
 
In [9]: a = numpy.array(na,dtype='float32')
 
In [10]: a_dp = dpnp.array(a)
 
In [11]: res_dp = dpnp.diagonal(a_dp)
 
In [12]: %timeit -n 10 res_dp = dpnp.diagonal(a_dp)
18 ms ± 1.21 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
 
In [13]: %timeit -n 10 res_dp = dpnp.diagonal(a_dp,new=True)
17.2 µs ± 4.5 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)


The backend implementation (dpnp_diagonal) is not removed due to the fact that dpnp_trace uses it

Additionally updating dpnp.diagonal() will allow to update dpnp.diag() function via reusing dpnp.diagonal()

  • 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?

Copy link
Contributor

github-actions bot commented May 9, 2024

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

dpnp/dpnp_iface_indexing.py Show resolved Hide resolved
dpnp/dpnp_iface_indexing.py Show resolved Hide resolved
dpnp/dpnp_iface_indexing.py Outdated Show resolved Hide resolved
dpnp/dpnp_iface_indexing.py Outdated Show resolved Hide resolved
dpnp/dpnp_iface_indexing.py Outdated Show resolved Hide resolved
dpnp/dpnp_iface_indexing.py Outdated Show resolved Hide resolved
dpnp/dpnp_iface_indexing.py Outdated Show resolved Hide resolved
tests/test_sycl_queue.py Outdated Show resolved Hide resolved
tests/test_usm_type.py Outdated Show resolved Hide resolved
Copy link
Contributor

@antonwolfy antonwolfy left a comment

Choose a reason for hiding this comment

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

@antonwolfy antonwolfy merged commit 05af730 into master May 11, 2024
55 of 56 checks passed
@antonwolfy antonwolfy deleted the update_dpnp_diagonal branch May 11, 2024 12:29
github-actions bot added a commit that referenced this pull request May 11, 2024
* Update dpnp.diagonal to support offset and axes

* Update cupy tests for dpnp.diagonal()

* Update dpnp tests for dpnp.diagonal()

* Remove pytest.skip for a closed issue

* Extend test cases in test_diagonal_errors

* Update dpnp.ndarray.diagonal

* Update docstrings for dpnp.diagonal

* Address remarks

* Simplify getting axes_order

* Add cupy test_indexing.py to test scope

* Remove TODO from dpnp_det/dpnp_slogdet

* Improve test coverage

* Update the calculation of result parameters 05af730
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