Skip to content

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

@vlad-perevezentsev

Description

@vlad-perevezentsev

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])

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions