dpctl
dpctl copied to clipboard
less_equal returns incorrect result
The code below works incorrectly in dpctl:
import numpy, dpctl, dpctl.tensor as dpt
dpt.less_equal(dpt.asarray(2, dtype=numpy.int32), numpy.iinfo(numpy.uint32).max)
Out: usm_ndarray(False)
numpy.less_equal(numpy.asarray(2, dtype=numpy.int32), numpy.iinfo(numpy.uint32).max)
Out: True
It looks like dpctl always casts a scalar to the same type as incoming usm_ndarray has, which might cause wrong result.
According to NEP-50, which has been the guideline for our binary operation type promotion, this case should probably raise an exception, since it's a Python scalar that's too large for the array type.
According to NEP-50, which has been the guideline for our binary operation type promotion, this case should probably raise an exception, since it's a Python scalar that's too large for the array type.
There have been developments in this since last year! NEP-50 has been clarified to focus on result types, so Numpy 2 now permits (and correctly calculates) this edge case.
Enhancements to dpctl will be made to support this.
Various changes to dpctl element-wise comparisons have been made to enable this edge case. It now works as expected.
In [3]: dpt.less_equal(dpt.asarray(2, dtype=np.int32), np.iinfo(np.uint32).max)
Out[3]: usm_ndarray(True)