From 030e163c64089c7cd608e73d7d68ce7144c45b48 Mon Sep 17 00:00:00 2001 From: mfrancis95 Date: Sun, 24 May 2020 00:13:14 -0400 Subject: [PATCH] Use placeholder expressions Use placeholder expression in thrust::count Use placeholder expression in thrust::find Use placeholder expression in thrust::mismatch Use placeholder expression in thrust::sequence Remove sequence_functor Use placeholder expression in thrust::remove Use placeholder expression in thrust::find Use placeholder expression in thrust::replace Use placeholder expression in thrust::replace Use placeholder expression in thrust::replace_copy Remove unneeded thrust/detail/internal_functional.h include from thrust/system/detail/generic/replace.inl --- thrust/system/cuda/detail/find.h | 4 ++- thrust/system/cuda/detail/remove.h | 5 ++-- thrust/system/cuda/detail/replace.h | 4 ++- thrust/system/detail/generic/find.inl | 5 ++-- thrust/system/detail/generic/mismatch.inl | 7 +++--- thrust/system/detail/generic/replace.inl | 12 +++++---- thrust/system/detail/generic/sequence.inl | 30 +++-------------------- 7 files changed, 26 insertions(+), 41 deletions(-) diff --git a/thrust/system/cuda/detail/find.h b/thrust/system/cuda/detail/find.h index 298be0d1a..f6a1e59d1 100644 --- a/thrust/system/cuda/detail/find.h +++ b/thrust/system/cuda/detail/find.h @@ -205,10 +205,12 @@ find(execution_policy &policy, InputIt last, T const& value) { + using thrust::placeholders::_1; + return cuda_cub::find_if(policy, first, last, - thrust::detail::equal_to_value(value)); + _1 == value); } diff --git a/thrust/system/cuda/detail/remove.h b/thrust/system/cuda/detail/remove.h index c590a1adf..700c95f23 100644 --- a/thrust/system/cuda/detail/remove.h +++ b/thrust/system/cuda/detail/remove.h @@ -74,8 +74,9 @@ remove(execution_policy &policy, InputIt last, const T & value) { - thrust::detail::equal_to_value pred(value); - return cuda_cub::remove_if(policy, first, last, pred); + using thrust::placeholders::_1; + + return cuda_cub::remove_if(policy, first, last, _1 == value); } // copy diff --git a/thrust/system/cuda/detail/replace.h b/thrust/system/cuda/detail/replace.h index d2ccb7b24..3bd685108 100644 --- a/thrust/system/cuda/detail/replace.h +++ b/thrust/system/cuda/detail/replace.h @@ -90,12 +90,14 @@ replace(execution_policy &policy, T const & old_value, T const & new_value) { + using thrust::placeholders::_1; + cuda_cub::transform_if(policy, first, last, first, __replace::constant_f(new_value), - thrust::detail::equal_to_value(old_value)); + _1 == old_value); } template &exec, InputIterator last, const T& value) { - // XXX consider a placeholder expression here - return thrust::find_if(exec, first, last, thrust::detail::equal_to_value(value)); + using thrust::placeholders::_1; + + return thrust::find_if(exec, first, last, _1 == value); } // end find() diff --git a/thrust/system/detail/generic/mismatch.inl b/thrust/system/detail/generic/mismatch.inl index d879a6e11..8348374a5 100644 --- a/thrust/system/detail/generic/mismatch.inl +++ b/thrust/system/detail/generic/mismatch.inl @@ -38,10 +38,9 @@ __host__ __device__ InputIterator1 last1, InputIterator2 first2) { - typedef typename thrust::iterator_value::type InputType1; - - // XXX use a placeholder expression here - return thrust::mismatch(exec, first1, last1, first2, thrust::detail::equal_to()); + using namespace thrust::placeholders; + + return thrust::mismatch(exec, first1, last1, first2, _1 == _2); } // end mismatch() diff --git a/thrust/system/detail/generic/replace.inl b/thrust/system/detail/generic/replace.inl index d5b6caa63..eea70ccd1 100644 --- a/thrust/system/detail/generic/replace.inl +++ b/thrust/system/detail/generic/replace.inl @@ -15,10 +15,10 @@ */ #include +#include #include #include #include -#include namespace thrust { @@ -124,8 +124,9 @@ __host__ __device__ const T &old_value, const T &new_value) { - thrust::detail::equal_to_value pred(old_value); - return thrust::replace_copy_if(exec, first, last, result, pred, new_value); + using thrust::placeholders::_1; + + return thrust::replace_copy_if(exec, first, last, result, _1 == old_value, new_value); } // end replace_copy() @@ -164,8 +165,9 @@ __host__ __device__ const T &old_value, const T &new_value) { - thrust::detail::equal_to_value pred(old_value); - return thrust::replace_if(exec, first, last, pred, new_value); + using thrust::placeholders::_1; + + return thrust::replace_if(exec, first, last, _1 == old_value, new_value); } // end replace() diff --git a/thrust/system/detail/generic/sequence.inl b/thrust/system/detail/generic/sequence.inl index 507f8b01d..16631c7f4 100644 --- a/thrust/system/detail/generic/sequence.inl +++ b/thrust/system/detail/generic/sequence.inl @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -27,30 +28,6 @@ namespace detail { namespace generic { -namespace sequence_detail -{ - - -template -struct sequence_functor -{ - T init, step; - - __host__ __device__ - sequence_functor(T init, T step) - : init(init), step(step) - {} - - template - __host__ __device__ - T operator()(Index i) const - { - return static_cast(init + step * i); - } -}; - - -} // end sequence_detail template @@ -84,8 +61,9 @@ __host__ __device__ T init, T step) { - // XXX TODO use a placeholder expression here - thrust::tabulate(exec, first, last, sequence_detail::sequence_functor(init, step)); + using thrust::placeholders::_1; + + thrust::tabulate(exec, first, last, init + step * _1); } // end sequence()