dpctl icon indicating copy to clipboard operation
dpctl copied to clipboard

less_equal returns incorrect result

Open antonwolfy opened this issue 1 year ago • 2 comments

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.

antonwolfy avatar Jun 15 '23 09:06 antonwolfy

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.

ndgrigorian avatar Jun 15 '23 18:06 ndgrigorian

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.

ndgrigorian avatar Apr 29 '24 17:04 ndgrigorian

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)

ndgrigorian avatar Sep 10 '24 16:09 ndgrigorian