IntelPython / dpctl

Python SYCL bindings and SYCL-based Python Array API library
https://intelpython.github.io/dpctl/
Apache License 2.0
99 stars 29 forks source link

tensor.clip throws ValueError on input generated by array API test #1742

Open oleksandr-pavlyk opened 1 month ago

oleksandr-pavlyk commented 1 month ago

The input is

import dpctl.tensor as dpt
val = dpt.zeros(2, dtype="u1")
max = dpt.zeros(tuple(), dtype="i1")
dpt.clip(val, min=None, max=max)

Raises ValueError: function 'clip' does not support input types (uint8, int8), and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''..

This causes failure in array_api_tests/test_operators_and_elementwise_functions.py::test_clip.

The issue is to investigate the failure and either fix or file an issue with array_api_tests

ndgrigorian commented 1 month ago

It is tough to say what the correct behavior should be with this edge case.

The array API demands output array has the same dtype as input. It could be possible to implement something like comparisons for unsigned and signed integer.

But Numpy does not permit this case either (when restricting out dtype to input dtype).

Numpy also has an open issue on the topic of not permitting promotion in the output like array API encourages https://github.com/numpy/numpy/issues/24976

Whatever decision dpctl makes, I feel that this test should be filed as an issue with array_api_tests regardless. Per the spec:

If x and either min or max have different data type kinds (e.g., integer versus floating-point), behavior is unspecified and thus implementation-dependent.

uint and int are different kinds, and therefore, this is an unspecified case.