Skip to content

Fix boolean reductions for #1327 #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dpctl/tensor/libtensor/source/boolean_reductions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sycl::event> all_deps;
all_deps.reserve(depends.size() + 1);
Expand All @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions dpctl/tests/test_usm_ndarray_utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()