IntelPython / dpctl

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

full and full_like do not work for `fill_value=dpt.nan` #1314

Closed ndgrigorian closed 1 year ago

ndgrigorian commented 1 year ago

When calling full or full_like with fill_value=dpt.nan or fill_value=np.nan, an array filled with -1. is returned instead.

See here:

In [2]: dpt.full(10, fill_value=dpt.nan)
Out[2]: usm_ndarray([-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.])

In [3]: dpt.full_like(dpt.empty(10), fill_value=dpt.nan)
Out[3]: usm_ndarray([-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.])

Notably, the following works:

In [2]: v = dpt.asarray(dpt.nan)

In [3]: dpt.full(10, fill_value=v, dtype="f8")
Out[3]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

In [4]: dpt.full_like(dpt.empty(10), fill_value=v)
Out[4]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])
oleksandr-pavlyk commented 1 year ago

Seems to only afflict double precision floating point numbers. CPU is the only device that supports float64 on my system:

In [7]: dpt.full(10, fill_value=dpt.nan, device='cpu', dtype=dpt.float64)
Out[7]: usm_ndarray([-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.])

In [8]: dpt.full(10, fill_value=dpt.nan, device='cpu', dtype=dpt.float32)
Out[8]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], dtype=float32)

In [9]: dpt.full(10, fill_value=dpt.nan)
Out[9]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], dtype=float32)