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

Fix clip for Numpy 2.0 #1744

Closed
ndgrigorian opened this issue Jul 19, 2024 · 0 comments · Fixed by #1759
Closed

Fix clip for Numpy 2.0 #1744

ndgrigorian opened this issue Jul 19, 2024 · 0 comments · Fixed by #1759

Comments

@ndgrigorian
Copy link
Collaborator

clip currently fails for out-of-bounds Python integers due to Numpy 2.0 changes:

In [21]: dpt.clip(dpt.asarray([0, 255], dtype=dpt.uint8), 0, 4550)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Cell In[21], line 1
----> 1 dpt.clip(dpt.asarray([0, 255], dtype=dpt.uint8), 0, 4550)

File ~/repos/dpctl/dpctl/tensor/_clip.py:634, in clip(x, min, max, out, order)
    632     a_max = max
    633 else:
--> 634     a_max = dpt.asarray(max, dtype=max_dtype, sycl_queue=exec_q)
    636 if order == "A":
    637     order = (
    638         "F"
    639         if all(
   (...)
    647         else "C"
    648     )

File ~/repos/dpctl/dpctl/tensor/_ctors.py:649, in asarray(obj, dtype, device, copy, usm_type, sycl_queue, order)
    644     raise ValueError(
    645         f"Converting {type(obj)} to usm_ndarray requires a copy"
    646     )
    647 # obj is a scalar, create 0d array
    648 return _asarray_from_numpy_ndarray(
--> 649     np.asarray(obj, dtype=dtype),
    650     dtype=dtype,
    651     usm_type=usm_type,
    652     sycl_queue=sycl_queue,
    653     order="C",
    654 )

OverflowError: Python integer 4550 out of bounds for uint8

Numpy has been doing the same and has changed this in numpy/numpy#26892

dpctl should implement a similar work-around

oleksandr-pavlyk added a commit that referenced this issue Jul 25, 2024
Add test to verify that Python scalars used for min/max
which are out of bound for array integral data type get
handled as None (no bounds).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant