Skip to content

Improper handling of key as a tuple in dpnp_array.__getitem__() #1361

Closed
@antonwolfy

Description

@antonwolfy

The below code caused a fault in dpnp:

# import dpnp

# x = dpnp.ones((4, 5))
# mask = dpnp.full(x.shape[1], True)
# x[:, mask]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 x[:, mask]

File /localdisk/work/antonvol/code/dpnp_dev/dpnp/dpnp/dpnp_array.py:182, in dpnp_array.__getitem__(self, key)
    179 if isinstance(key, dpnp_array):
    180     key = key.get_array()
--> 182 item = self._array_obj.__getitem__(key)
    183 if not isinstance(item, dpt.usm_ndarray):
    184     raise RuntimeError(
    185         "Expected dpctl.tensor.usm_ndarray, got {}"
    186         "".format(type(item)))

File dpctl/tensor/_usmarray.pyx:716, in dpctl.tensor._usmarray.usm_ndarray.__getitem__()

File dpctl/tensor/_slicing.pxi:171, in dpctl.tensor._usmarray._basic_slice_meta()

File dpctl/tensor/_slicing.pxi:63, in dpctl.tensor._usmarray._is_integral()

File /localdisk/work/antonvol/code/dpnp_dev/dpnp/dpnp/dpnp_array.py:217, in dpnp_array.__index__(self)
    216 def __index__(self):
--> 217     return self._array_obj.__index__()

File dpctl/tensor/_usmarray.pyx:888, in dpctl.tensor._usmarray.usm_ndarray.__index__()

IndexError: only integer arrays are valid indices

It looks dpnp wrongly handles indexing use cases when key is a tuple.

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