diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d01978e60df..7dee9a8a90e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ This release is compatible with NumPy 2.5. * Fixed `dpnp.interp` returning `nan` when querying at an exact knot point whose adjacent `fp` value is `inf` [#2986](https://github.com/IntelPython/dpnp/pull/2986) * Fixed missing strides validation in `dpnp.tensor.usm_ndarray` constructor when allocating new memory [#2927](https://github.com/IntelPython/dpnp/pull/2927) * Fixed `dpnp.bincount` raising a `ValueError` on an empty input array instead of returning an empty `intp` array [#3018](https://github.com/IntelPython/dpnp/pull/3018) +* Fixed `dpnp.tensor.top_k` aborting for `k=0` by returning empty result arrays without launching a zero-sized kernel [#3022](https://github.com/IntelPython/dpnp/pull/3022) ### Security diff --git a/dpnp/tensor/libtensor/source/sorting/topk.cpp b/dpnp/tensor/libtensor/source/sorting/topk.cpp index 0103839f3004..db4b99ab879b 100644 --- a/dpnp/tensor/libtensor/source/sorting/topk.cpp +++ b/dpnp/tensor/libtensor/source/sorting/topk.cpp @@ -219,7 +219,7 @@ std::pair dpnp::tensor::validation::CheckWritable::throw_if_not_writable(vals); dpnp::tensor::validation::CheckWritable::throw_if_not_writable(inds); - if ((iter_nelems == 0) || (axis_nelems == 0)) { + if ((iter_nelems == 0) || (axis_nelems == 0) || (k == 0)) { // Nothing to do return std::make_pair(sycl::event(), sycl::event()); }