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

dpct.tensor.take does not disable negative indexing #1129

Closed
vlad-perevezentsev opened this issue Mar 17, 2023 · 0 comments · Fixed by #1132
Closed

dpct.tensor.take does not disable negative indexing #1129

vlad-perevezentsev opened this issue Mar 17, 2023 · 0 comments · Fixed by #1132
Assignees
Labels
bug Something isn't working

Comments

@vlad-perevezentsev
Copy link
Collaborator

When we pass negative indexes to dpctl.take with clip mod (default), it returns different array elements depending on the negative index.
This is the wrong behavior.
clip mode means that all indices that are too large are replaced by the index that addresses the last element along that axis.
Note that this disables indexing with negative numbers.

#NUMPY
np_arr = np.arange(1,6)
np_ind = np.array([-1,-2,-3,-4,-5])

#DPT
dpt_arr = dpt.asarray(np_arr)
dpt_ind = dpt.asarray(np_ind)


np.take(np_arr,np_ind,mode='clip')
>> array([1, 1, 1, 1, 1])

dpt.take(dpt_arr,dpt_ind)
>> usm_ndarray([5, 4, 3, 2, 1])

# work with positive over indexes
dpt_ind = dpt.asarray([5,6,7,8,9])
dpt.take(dpt_arr,dpt_ind)
>> usm_ndarray([5, 5, 5, 5, 5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants