From c89dffd2f33a51905ba79ba175b0449e038562f7 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Mon, 18 Sep 2023 13:50:05 -0500 Subject: [PATCH 1/3] Fix gh-1539 --- dpnp/dpnp_iface_mathematical.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 4fad31bf9ee3..a9d832a8e5de 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -2382,9 +2382,21 @@ def sum( elif where is not True: pass else: - if len(x.shape) == 2 and ( - (axis == (0,) and x.flags.c_contiguous) - or (axis == (1,) and x.flags.f_contiguous) + if ( + len(x.shape) == 2 + and x.itemsize == 4 + and ( + ( + axis == (0,) + and x.flags.c_contiguous + and 32 <= x.shape[1] <= 512 + ) + or ( + axis == (1,) + and x.flags.f_contiguous + and 32 <= x.shape[0] <= 512 + ) + ) ): from dpctl.tensor._reduction import _default_reduction_dtype From 68d7e19a98a03d596b7a8e870b9fbb08cd338103 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Mon, 18 Sep 2023 14:40:38 -0500 Subject: [PATCH 2/3] Update dpnp.sum function --- dpnp/dpnp_iface_mathematical.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index a9d832a8e5de..e0ab8b34df5b 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -2389,12 +2389,14 @@ def sum( ( axis == (0,) and x.flags.c_contiguous - and 32 <= x.shape[1] <= 512 + and 32 <= x.shape[1] <= 1024 + and x.shape[0] > x.shape[1] ) or ( axis == (1,) and x.flags.f_contiguous - and 32 <= x.shape[0] <= 512 + and 32 <= x.shape[0] <= 1024 + and x.shape[1] > x.shape[0] ) ) ): From 863fd480eb3c4196f2fbc2d67d9407d4a19e4d43 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Tue, 19 Sep 2023 13:53:03 -0500 Subject: [PATCH 3/3] Added tests for dpnp.sum function --- tests/test_mathematical.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index adb556fb79c7..1e4bac64d8ae 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -1196,15 +1196,18 @@ def test_sum_empty_out(dtype): (0, 6), (10, 1), (1, 10), + (35, 40), + (40, 35), ], ) @pytest.mark.parametrize("dtype_in", get_all_dtypes()) @pytest.mark.parametrize("dtype_out", get_all_dtypes()) @pytest.mark.parametrize("transpose", [True, False]) @pytest.mark.parametrize("keepdims", [True, False]) -def test_sum(shape, dtype_in, dtype_out, transpose, keepdims): +@pytest.mark.parametrize("order", ["C", "F"]) +def test_sum(shape, dtype_in, dtype_out, transpose, keepdims, order): size = numpy.prod(shape) - a_np = numpy.arange(size).astype(dtype_in).reshape(shape) + a_np = numpy.arange(size).astype(dtype_in).reshape(shape, order=order) a = dpnp.asarray(a_np) if transpose: