|
21 | 21 |
|
22 | 22 | import dpctl
|
23 | 23 | import dpctl.tensor as dpt
|
| 24 | +from dpctl.tensor._tensor_elementwise_impl import _divide_by_scalar |
24 | 25 | from dpctl.tensor._type_utils import _can_cast
|
25 | 26 | from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
|
| 27 | +from dpctl.utils import SequentialOrderManager |
26 | 28 |
|
27 | 29 | from .utils import (
|
28 | 30 | _all_dtypes,
|
@@ -271,3 +273,26 @@ def test_divide_gh_1711():
|
271 | 273 | assert isinstance(res, dpt.usm_ndarray)
|
272 | 274 | assert res.dtype.kind == "f"
|
273 | 275 | assert dpt.allclose(res, dpt.asarray(3, dtype="i4") / -2)
|
| 276 | + |
| 277 | + |
| 278 | +# don't test for overflowing double as Python won't cast |
| 279 | +# an Python integer of that size to a Python float |
| 280 | +@pytest.mark.parametrize("fp_dt", [dpt.float16, dpt.float32]) |
| 281 | +def test_divide_by_scalar_overflow(fp_dt): |
| 282 | + q = get_queue_or_skip() |
| 283 | + skip_if_dtype_not_supported(fp_dt, q) |
| 284 | + |
| 285 | + x = dpt.ones(10, dtype=fp_dt, sycl_queue=q) |
| 286 | + out = dpt.empty_like(x) |
| 287 | + |
| 288 | + max_exp = np.finfo(fp_dt).maxexp |
| 289 | + sca = 2**max_exp |
| 290 | + |
| 291 | + _manager = SequentialOrderManager[q] |
| 292 | + dep_evs = _manager.submitted_events |
| 293 | + _, ev = _divide_by_scalar( |
| 294 | + src=x, scalar=sca, dst=out, sycl_queue=q, depends=dep_evs |
| 295 | + ) |
| 296 | + ev.wait() |
| 297 | + |
| 298 | + assert dpt.all(out == 0) |
0 commit comments