Skip to content

Missing a boundary check for sorter argument in dpctl.tensor.searchsorted #1599

@antonwolfy

Description

@antonwolfy

In below example sorter has an index which is out of the range of input array a, but no validation exception raised by dpctl:

a = dpt.asarray([5, 2, 1, 3, 4])
v = dpt.asarray(4)
sorter = dpt.asarray([0, 1, 2, 3, 5])

dpt.searchsorted(a, v, sorter=sorter)
# Out: usm_ndarray(4)

a = numpy.asarray([5, 2, 1, 3, 4])
v = numpy.asarray(4)
sorter = numpy.asarray([0, 1, 2, 3, 5])
numpy.searchsorted(a, v, sorter=sorter)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[10], line 1
----> 1 numpy.searchsorted(a, v, sorter=sorter)

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/numpy/core/fromnumeric.py:1400, in searchsorted(a, v, side, sorter)
   1332 @array_function_dispatch(_searchsorted_dispatcher)
   1333 def searchsorted(a, v, side='left', sorter=None):
   1334     """
   1335     Find indices where elements should be inserted to maintain order.
   1336
   (...)
   1398
   1399     """
-> 1400     return _wrapfunc(a, 'searchsorted', v, side=side, sorter=sorter)

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/numpy/core/fromnumeric.py:59, in _wrapfunc(obj, method, *args, **kwds)
     56     return _wrapit(obj, method, *args, **kwds)
     58 try:
---> 59     return bound(*args, **kwds)
     60 except TypeError:
     61     # A TypeError occurs if the object does have such a method in its
     62     # class, but its signature is not identical to that of NumPy's. This
   (...)
     66     # Call _wrapit from within the except clause to ensure a potential
     67     # exception has a traceback chain.
     68     return _wrapit(obj, method, *args, **kwds)

ValueError: Sorter index out of range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions