From e53aa0c18d77f263ed6aa058dff87d3a6dd43590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Akif=20=C3=87=C3=96RD=C3=9CK?= Date: Tue, 19 Mar 2024 15:26:15 +0100 Subject: [PATCH] Fix bug in blockRankedReduce (#2226) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a bug appearing for negative floating point numbers with a max reduce operation. The `std::numeric_limits::min()` is greater than the negative floating point values whereas we want it to be smaller than all representable values. This PR replaces the `min` with the `lowest`. Authors: - Akif ÇÖRDÜK (https://github.com/akifcorduk) - Tamas Bela Feher (https://github.com/tfeher) Approvers: - Bradley Dice (https://github.com/bdice) - Tamas Bela Feher (https://github.com/tfeher) URL: https://github.com/rapidsai/raft/pull/2226 --- cpp/include/raft/util/reduction.cuh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cpp/include/raft/util/reduction.cuh b/cpp/include/raft/util/reduction.cuh index 7e897e67f5..2c2b1aa228 100644 --- a/cpp/include/raft/util/reduction.cuh +++ b/cpp/include/raft/util/reduction.cuh @@ -157,11 +157,10 @@ DI std::pair blockRankedReduce(T val, val = values[lane]; idx = indices[lane]; } else { - // get the min if it is a max op, get the max if it is a min op - val = reduce_op(std::numeric_limits::min(), std::numeric_limits::max()) == - std::numeric_limits::min() - ? std::numeric_limits::max() - : std::numeric_limits::min(); + // get the lower_bound of the type if it is a max op, + // get the upper bound of the type if it is a min op + val = reduce_op(lower_bound(), upper_bound()) == lower_bound() ? upper_bound() + : lower_bound(); idx = -1; } __syncthreads();