     const KeyValuePair<int, double> &a,
     const KeyValuePair<int, double> &b) const
 {
-    if (cupy_isnan(a.value))
-        return a;
-    else if (cupy_isnan(b.value))
+    if (isnan(a.value))
+        return a;
+    else if (isnan(b.value))
         return b;
     else if ((b.value < a.value) || ((a.value == b.value) && (b.key < a.key)))
         return b;

    const KeyValuePair<int, float> &a,
    const KeyValuePair<int, float> &b) const
{
    if (cupy_isnan(a.value))
        return a;
    else if (cupy_isnan(b.value))
        return b;
    else if ((b.value < a.value) || ((a.value == b.value) && (b.key < a.key)))
        return b;

__host__ __device__ __forceinline__ float Min::operator()(const float &a, const float &b) const
{
    // NumPy behavior: NaN is always chosen!
    if (isnan(a)) {return a;}
    else if (isnan(b)) {return b;}
    else {return CUB_MIN(a, b);}
}

