Skip to content

Shift tuple support when axis=None for dpctl.tensor.roll #1341

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

Closed

Conversation

vlad-perevezentsev
Copy link
Collaborator

This PR suggests adding support for the case when shift is tuple and axis=None for dpctl.tensor.roll .
The previous implementation raised TypeError exception cause copy_usm_ndarray_for_reshape expects shift as an integer.

import dpctl.tensor as dpt

a = dpt.ones((5,2))
dpt.roll(a,shift=(1,2))

TypeError: _copy_usm_ndarray_for_reshape(): incompatible function arguments. The following argument types are supported:
    1. (src: dpctl::tensor::usm_ndarray, dst: dpctl::tensor::usm_ndarray, shift: int, sycl_queue: dpctl.SyclQueue, depends: List[dpctl.SyclEvent] = []) -> Tuple[dpctl.SyclEvent, dpctl.SyclEvent]

Additionally, the PR adds a check for the equality of the source and destination parameters to return the input array X without having to move its axes in dpctl.tensor.moveaxis.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an 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 opening the PR as a draft?

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 84.959% (+0.009%) from 84.95% when pulling 1370835 on vlad-perevezentsev:fix_roll into 50f1074 on IntelPython:master.

@oleksandr-pavlyk
Copy link
Contributor

Array API spec for xp.roll stipulates that

If shift is a tuple, then axis must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in shift.

I realize that implemented behavior aligns with how NumPy currently behaves, but dpnp.roll could implement that convenience at its end.

Comment on lines +430 to +431
if type(shift) is tuple:
shift = sum(shift)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am afraid this is the right implementation. Providing correct implementation requires writing a new kernel.

@antonwolfy
Copy link
Collaborator

antonwolfy commented Aug 16, 2023

Array API spec for xp.roll stipulates that

If shift is a tuple, then axis must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in shift.

I realize that implemented behavior aligns with how NumPy currently behaves, but dpnp.roll could implement that convenience at its end.

Probably dpctl has to raise an exception here then, since currently it tries to call copy function and as the result will fail inside _copy_usm_ndarray_for_reshape.

@oleksandr-pavlyk oleksandr-pavlyk changed the title Shift tuple support when axis=0 for dpctl.tensor.roll Shift tuple support when axis=None for dpctl.tensor.roll Aug 17, 2023
@oleksandr-pavlyk oleksandr-pavlyk mentioned this pull request Aug 30, 2023
6 tasks
@oleksandr-pavlyk
Copy link
Contributor

Superseded by gh-1380

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.

4 participants