|
| 1 | +import dpctl |
1 | 2 | import numpy
|
2 | 3 | import pytest
|
3 | 4 | from numpy.testing import (
|
@@ -283,6 +284,18 @@ def test_invalid_range(self, xp):
|
283 | 284 | with assert_raises_regex(ValueError, "max must be larger than"):
|
284 | 285 | xp.histogram(vals, range=[0.1, 0.01])
|
285 | 286 |
|
| 287 | + @pytest.mark.parametrize("xp", [numpy, dpnp]) |
| 288 | + @pytest.mark.parametrize("inf_val", [-numpy.inf, numpy.inf]) |
| 289 | + def test_infinite_edge(self, xp, inf_val): |
| 290 | + v = xp.array([0.5, 1.5, inf_val]) |
| 291 | + min, max = v.min(), v.max() |
| 292 | + |
| 293 | + # both first and last ranges must be finite |
| 294 | + with assert_raises_regex( |
| 295 | + ValueError, f"autodetected range of \[{min}, {max}\] is not finite" |
| 296 | + ): |
| 297 | + xp.histogram(v) |
| 298 | + |
286 | 299 | def test_bin_edge_cases(self):
|
287 | 300 | v = dpnp.array([337, 404, 739, 806, 1007, 1811, 2012])
|
288 | 301 |
|
@@ -322,7 +335,7 @@ def test_unsigned_monotonicity_check(self, xp):
|
322 | 335 | arr = xp.array([2])
|
323 | 336 | bins = xp.array([1, 3, 1], dtype="uint64")
|
324 | 337 | with assert_raises(ValueError):
|
325 |
| - _, _ = xp.histogram(arr, bins=bins) |
| 338 | + xp.histogram(arr, bins=bins) |
326 | 339 |
|
327 | 340 | def test_nan_values(self):
|
328 | 341 | one_nan = numpy.array([0, 1, numpy.nan])
|
@@ -356,3 +369,23 @@ def test_signed_overflow_bounds(self, dtype):
|
356 | 369 | result_hist, result_edges = dpnp.histogram(iv, bins=2)
|
357 | 370 | assert_array_equal(result_hist, expected_hist)
|
358 | 371 | assert_allclose(result_edges, expected_edges)
|
| 372 | + |
| 373 | + def test_string_bins_not_implemented(self): |
| 374 | + v = dpnp.arange(5) |
| 375 | + |
| 376 | + # numpy support string bins, but not dpnp |
| 377 | + _, _ = numpy.histogram(v.asnumpy(), bins="auto") |
| 378 | + with assert_raises(NotImplementedError): |
| 379 | + dpnp.histogram(v, bins="auto") |
| 380 | + |
| 381 | + def test_bins_another_sycl_queue(self): |
| 382 | + v = dpnp.arange(7, 12, sycl_queue=dpctl.SyclQueue()) |
| 383 | + bins = dpnp.arange(4, sycl_queue=dpctl.SyclQueue()) |
| 384 | + with assert_raises(ValueError): |
| 385 | + dpnp.histogram(v, bins=bins) |
| 386 | + |
| 387 | + def test_weights_another_sycl_queue(self): |
| 388 | + v = dpnp.arange(5, sycl_queue=dpctl.SyclQueue()) |
| 389 | + w = dpnp.arange(7, 12, sycl_queue=dpctl.SyclQueue()) |
| 390 | + with assert_raises(ValueError): |
| 391 | + dpnp.histogram(v, weights=w) |
0 commit comments