From 0cdd79e7cfb7b4bf9d6f4053ee9ca83fea1d0dcc Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 16 Sep 2024 12:55:26 -0500 Subject: [PATCH 1/2] Throw exception in py_sort if inputs are not C-contiguous --- dpctl/tensor/libtensor/source/sorting/sort.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dpctl/tensor/libtensor/source/sorting/sort.cpp b/dpctl/tensor/libtensor/source/sorting/sort.cpp index aafc531eff..7da5e7ab69 100644 --- a/dpctl/tensor/libtensor/source/sorting/sort.cpp +++ b/dpctl/tensor/libtensor/source/sorting/sort.cpp @@ -144,7 +144,8 @@ py_sort(const dpctl::tensor::usm_ndarray &src, return std::make_pair(keep_args_alive_ev, comp_ev); } - return std::make_pair(sycl::event(), sycl::event()); + throw py::value_error( + "Both source and destination arrays must be C-contiguous"); } using dpctl::tensor::kernels::sort_contig_fn_ptr_t; From 85d5cb92c1276178eedb3d894a340fe704ab11d1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 16 Sep 2024 13:18:31 -0500 Subject: [PATCH 2/2] Add throw py::value_error in argsort too Also deleted inaccurate comments. --- dpctl/tensor/libtensor/source/sorting/argsort.cpp | 4 ++-- dpctl/tensor/libtensor/source/sorting/sort.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dpctl/tensor/libtensor/source/sorting/argsort.cpp b/dpctl/tensor/libtensor/source/sorting/argsort.cpp index 36701eee67..0bd998e90b 100644 --- a/dpctl/tensor/libtensor/source/sorting/argsort.cpp +++ b/dpctl/tensor/libtensor/source/sorting/argsort.cpp @@ -125,7 +125,6 @@ py_argsort(const dpctl::tensor::usm_ndarray &src, "Output index array must have data type int32 or int64"); } - // handle special case when both reduction and iteration are 1D contiguous bool is_src_c_contig = src.is_c_contiguous(); bool is_dst_c_contig = dst.is_c_contiguous(); @@ -150,7 +149,8 @@ py_argsort(const dpctl::tensor::usm_ndarray &src, return std::make_pair(keep_args_alive_ev, comp_ev); } - return std::make_pair(sycl::event(), sycl::event()); + throw py::value_error( + "Both source and destination arrays must be C-contiguous"); } using dpctl::tensor::kernels::sort_contig_fn_ptr_t; diff --git a/dpctl/tensor/libtensor/source/sorting/sort.cpp b/dpctl/tensor/libtensor/source/sorting/sort.cpp index 7da5e7ab69..756e60bdf1 100644 --- a/dpctl/tensor/libtensor/source/sorting/sort.cpp +++ b/dpctl/tensor/libtensor/source/sorting/sort.cpp @@ -123,7 +123,6 @@ py_sort(const dpctl::tensor::usm_ndarray &src, "the same value data type"); } - // handle special case when both reduction and iteration are 1D contiguous bool is_src_c_contig = src.is_c_contiguous(); bool is_dst_c_contig = dst.is_c_contiguous();