From c1ee0f8b4b78f447266cbe4ff5e295e6145c13f8 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 27 Jun 2023 21:56:07 +0200 Subject: [PATCH 1/2] Check dtype support of each array in resulting tuple in call_origin --- dpnp/dpnp_utils/dpnp_algo_utils.pyx | 6 +++++- tests/test_histograms.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index 269d21a15e2d..b69bceea9e63 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -201,7 +201,11 @@ def call_origin(function, *args, **kwargs): for res_origin in result: res = res_origin if isinstance(res_origin, numpy.ndarray): - res = dpnp_container.empty(res_origin.shape, dtype=res_origin.dtype, sycl_queue=exec_q) + if exec_q is not None: + result_dtype = map_dtype_to_device(res_origin.dtype, exec_q.sycl_device) + else: + result_dtype = res_origin.d_type + res = dpnp_container.empty(res_origin.shape, dtype=result_dtype, sycl_queue=exec_q) copy_from_origin(res, res_origin) result_list.append(res) diff --git a/tests/test_histograms.py b/tests/test_histograms.py index eeb8cbf563fe..07ae9652193c 100644 --- a/tests/test_histograms.py +++ b/tests/test_histograms.py @@ -3,6 +3,8 @@ import dpnp +from .helper import has_support_aspect64 + class TestHistogram: def setup(self): @@ -20,7 +22,14 @@ def test_simple(self): numpy.testing.assert_equal(dpnp.sum(a, axis=0), n) # check that the bin counts are evenly spaced when the data is from # a linear function - (a, b) = dpnp.histogram(numpy.linspace(0, 10, 100)) + (a, b) = dpnp.histogram( + numpy.linspace( + 0, + 10, + 100, + dtype="float64" if has_support_aspect64() else "float32", + ) + ) numpy.testing.assert_array_equal(a, 10) @pytest.mark.usefixtures("allow_fall_back_on_numpy") From 35f4a74d8a4586797ab77e55d13ec2c3916a9c94 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 28 Jun 2023 12:30:18 +0200 Subject: [PATCH 2/2] Use dpnp.linspace in test_histograms --- tests/test_histograms.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/test_histograms.py b/tests/test_histograms.py index 07ae9652193c..b62f653b0c97 100644 --- a/tests/test_histograms.py +++ b/tests/test_histograms.py @@ -3,8 +3,6 @@ import dpnp -from .helper import has_support_aspect64 - class TestHistogram: def setup(self): @@ -17,19 +15,12 @@ def teardown(self): def test_simple(self): n = 100 v = dpnp.random.rand(n) - (a, b) = dpnp.histogram(v) + a, _ = dpnp.histogram(v) # check if the sum of the bins equals the number of samples numpy.testing.assert_equal(dpnp.sum(a, axis=0), n) # check that the bin counts are evenly spaced when the data is from # a linear function - (a, b) = dpnp.histogram( - numpy.linspace( - 0, - 10, - 100, - dtype="float64" if has_support_aspect64() else "float32", - ) - ) + a, _ = dpnp.histogram(dpnp.linspace(0, 10, 100)) numpy.testing.assert_array_equal(a, 10) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -76,7 +67,7 @@ def test_density(self): # Taken from a bug report from N. Becker on the numpy-discussion # mailing list Aug. 6, 2010. - counts, dmy = dpnp.histogram( + counts, _ = dpnp.histogram( [1, 2, 3, 4], [0.5, 1.5, numpy.inf], density=True ) numpy.testing.assert_equal(counts, [0.25, 0])