Commit 0ea7818a authored by Xuan Thang Nguyen's avatar Xuan Thang Nguyen
Browse files

fix sort checking

parent d451ce6d
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -5,9 +5,10 @@
template <typename Value, typename Function>
bool is_sorted(TNL::Containers::ArrayView<Value, TNL::Devices::Cuda> arr, const Function &Cmp)
{
    if(arr.getSize() <= 1) return true;
    if (arr.getSize() <= 1)
        return true;

    auto fetch = [=] __cuda_callable__(int i) { return Cmp(arr[i - 1], arr[i]); };
    auto fetch = [=] __cuda_callable__(int i) { return !Cmp(arr[i], arr[i - 1]); };
    auto reduction = [] __cuda_callable__(bool a, bool b) { return a && b; };
    return TNL::Algorithms::Reduction<TNL::Devices::Cuda>::reduce(1, arr.getSize(), fetch, reduction, true);
}
@@ -15,5 +16,5 @@ bool is_sorted(TNL::Containers::ArrayView<Value, TNL::Devices::Cuda> arr, const
template <typename Value>
bool is_sorted(TNL::Containers::ArrayView<Value, TNL::Devices::Cuda> arr)
{
    return is_sorted(arr, [] __cuda_callable__(const Value &a, const Value &b) { return a <= b; });
    return is_sorted(arr, [] __cuda_callable__(const Value &a, const Value &b) { return a < b; });
}