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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dpctl/tensor/_manipulation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ def roll(X, shift, axis=None):
if not isinstance(X, dpt.usm_ndarray):
raise TypeError(f"Expected usm_ndarray type, got {type(X)}.")
if axis is None:
# get the combined shift value for all axes
if type(shift) is tuple:
shift = sum(shift)
Comment on lines +430 to +431
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.

res = dpt.empty(
X.shape, dtype=X.dtype, usm_type=X.usm_type, sycl_queue=X.sycl_queue
)
Expand Down Expand Up @@ -882,6 +885,9 @@ def moveaxis(X, source, destination):
"the same number of elements"
)

if source == destination:
return X

ind = [n for n in range(X.ndim) if n not in source]

for src, dst in sorted(zip(destination, source)):
Expand Down
4 changes: 4 additions & 0 deletions dpctl/tests/test_usm_ndarray_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ def test_roll_empty():
"data",
[
[2, None],
[(0, 1), None],
[(-1, 0), None],
[-2, None],
[2, 0],
[-2, 0],
Expand Down Expand Up @@ -617,6 +619,8 @@ def test_roll_1d(data):
"data",
[
[1, None],
[(2, 1), None],
[(-1, 2), None],
[1, 0],
[1, 1],
[1, ()],
Expand Down