|
21 | 21 | get_array, |
22 | 22 | get_float_dtypes, |
23 | 23 | has_support_aspect64, |
| 24 | + numpy_version, |
24 | 25 | ) |
25 | 26 | from .third_party.cupy import testing |
26 | 27 |
|
@@ -264,6 +265,59 @@ def test_axis(self, axis): |
264 | 265 | func = lambda xp: xp.linspace([2, 3], [20, 15], num=10, axis=axis) |
265 | 266 | assert_allclose(func(dpnp), func(numpy)) |
266 | 267 |
|
| 268 | + @pytest.mark.parametrize("val", [numpy.inf, -numpy.inf, numpy.inf + 1j]) |
| 269 | + @pytest.mark.parametrize("num", [1, 5]) |
| 270 | + @pytest.mark.parametrize("endpoint", [True, False]) |
| 271 | + def test_inf_equal_endpoints_scalar(self, val, num, endpoint): |
| 272 | + result, step = dpnp.linspace( |
| 273 | + val, val, num, endpoint=endpoint, retstep=True |
| 274 | + ) |
| 275 | + if numpy_version() >= "2.6.0": |
| 276 | + expected, exp_step = numpy.linspace( |
| 277 | + val, val, num, endpoint=endpoint, retstep=True |
| 278 | + ) |
| 279 | + assert_dtype_allclose(step, exp_step) |
| 280 | + else: |
| 281 | + expected = numpy.full(num, val) |
| 282 | + step_val = step.asnumpy() |
| 283 | + if (num - endpoint) > 0: |
| 284 | + assert step_val == 0 |
| 285 | + else: |
| 286 | + assert numpy.isnan(step_val) |
| 287 | + assert_dtype_allclose(result, expected) |
| 288 | + |
| 289 | + def test_inf_equal_endpoints_array(self): |
| 290 | + start = numpy.array([numpy.inf, -numpy.inf, 1.0]) |
| 291 | + stop = numpy.array([numpy.inf, -numpy.inf, 1.0]) |
| 292 | + |
| 293 | + result = dpnp.linspace(start, stop, num=4) |
| 294 | + if numpy_version() >= "2.6.0": |
| 295 | + expected = numpy.linspace(start, stop, num=4) |
| 296 | + else: |
| 297 | + expected = numpy.full((4, 3), [numpy.inf, -numpy.inf, 1.0]) |
| 298 | + assert_dtype_allclose(result, expected) |
| 299 | + |
| 300 | + def test_inf_mixed_endpoints_array(self): |
| 301 | + start = numpy.array([numpy.inf, numpy.inf]) |
| 302 | + stop = numpy.array([numpy.inf, 2.0]) |
| 303 | + |
| 304 | + result = dpnp.linspace(start, stop, num=3) |
| 305 | + if numpy_version() >= "2.6.0": |
| 306 | + expected = numpy.linspace(start, stop, num=3) |
| 307 | + assert_dtype_allclose(result, expected) |
| 308 | + else: |
| 309 | + # mixed infinities still yield NaN interior; equal column stays inf |
| 310 | + res = result.asnumpy() |
| 311 | + assert res[0, 0] == numpy.inf and res[-1, 0] == numpy.inf |
| 312 | + assert numpy.isnan(res[1, 1]) |
| 313 | + assert res[-1, 1] == 2.0 |
| 314 | + |
| 315 | + @pytest.mark.parametrize("num", [1, 5]) |
| 316 | + def test_nan_endpoints(self, num): |
| 317 | + result = dpnp.linspace(numpy.nan, numpy.nan, num) |
| 318 | + expected = numpy.linspace(numpy.nan, numpy.nan, num) |
| 319 | + assert_dtype_allclose(result, expected) |
| 320 | + |
267 | 321 | @pytest.mark.parametrize("xp", [dpnp, numpy]) |
268 | 322 | def test_negative_num(self, xp): |
269 | 323 | with pytest.raises(ValueError, match="must be non-negative"): |
|
0 commit comments