diff --git a/dpctl/tensor/libtensor/source/boolean_reductions.hpp b/dpctl/tensor/libtensor/source/boolean_reductions.hpp index 7b00932a8c..e6d14c8d47 100644 --- a/dpctl/tensor/libtensor/source/boolean_reductions.hpp +++ b/dpctl/tensor/libtensor/source/boolean_reductions.hpp @@ -235,7 +235,8 @@ py_boolean_reduction(dpctl::tensor::usm_ndarray src, std::get<2>(iter_red_metadata_packing_triple_); py::ssize_t *iter_shape_and_strides = packed_shapes_and_strides; - py::ssize_t *red_shape_stride = packed_shapes_and_strides + (3 * iter_nd); + py::ssize_t *red_shape_stride = + packed_shapes_and_strides + 3 * simplified_iter_shape.size(); std::vector all_deps; all_deps.reserve(depends.size() + 1); @@ -244,7 +245,7 @@ py_boolean_reduction(dpctl::tensor::usm_ndarray src, all_deps.push_back(copy_metadata_ev); auto red_ev = - fn(exec_q, dst_nelems, red_nelems, src_data, dst_data, dst_nd, + fn(exec_q, dst_nelems, red_nelems, src_data, dst_data, iter_nd, iter_shape_and_strides, iter_src_offset, iter_dst_offset, simplified_red_nd, red_shape_stride, red_src_offset, all_deps); diff --git a/dpctl/tests/test_usm_ndarray_utility_functions.py b/dpctl/tests/test_usm_ndarray_utility_functions.py index f99517daef..97b3319b6f 100644 --- a/dpctl/tests/test_usm_ndarray_utility_functions.py +++ b/dpctl/tests/test_usm_ndarray_utility_functions.py @@ -148,3 +148,20 @@ def test_arg_validation_boolean_reductions(func): func(d) with pytest.raises(AxisError): func(x, axis=-3) + + +def test_boolean_reductions_3d_gh_1327(): + get_queue_or_skip() + + size = 24 + x = dpt.reshape(dpt.arange(-10, size - 10, 1, dtype="i4"), (2, 3, 4)) + res = dpt.all(x, axis=0) + res_np = np.full(res.shape, True, dtype="?") + res_np[2, 2] = False + + assert (dpt.asnumpy(res) == res_np).all() + + x = dpt.ones((2, 3, 4, 5), dtype="i4") + res = dpt.any(x, axis=0) + + assert (dpt.asnumpy(res) == np.full(res.shape, True, dtype="?")).all()