diff --git a/include/boost/compute/algorithm/detail/radix_sort.hpp b/include/boost/compute/algorithm/detail/radix_sort.hpp index 1ff3aee6c..3c31cee50 100644 --- a/include/boost/compute/algorithm/detail/radix_sort.hpp +++ b/include/boost/compute/algorithm/detail/radix_sort.hpp @@ -281,7 +281,7 @@ inline void radix_sort_impl(const buffer_iterator first, // load radix sort program program radix_sort_program = cache->get_or_build( - cache_key, options.str(), radix_sort_source, context + cache_key, options.str(), boost::compute::type_definition() +"\n"+radix_sort_source, context ); kernel count_kernel(radix_sort_program, "count"); diff --git a/include/boost/compute/algorithm/nth_element.hpp b/include/boost/compute/algorithm/nth_element.hpp index 68f7a3dbc..94b631033 100644 --- a/include/boost/compute/algorithm/nth_element.hpp +++ b/include/boost/compute/algorithm/nth_element.hpp @@ -43,8 +43,7 @@ inline void nth_element(Iterator first, first, last, ::boost::compute::bind(compare, _1, value), queue ); - Iterator old_nth = find(new_nth, last, value, queue); - + Iterator old_nth = find_if(new_nth,last,nor1(boost::compute::bind(compare, _1, value),boost::compute::bind(compare, value, _1)),queue); value_type new_value = new_nth.read(queue); fill_n(new_nth, 1, value, queue); diff --git a/include/boost/compute/detail/meta_kernel.hpp b/include/boost/compute/detail/meta_kernel.hpp index 7be778b02..524c2f05c 100644 --- a/include/boost/compute/detail/meta_kernel.hpp +++ b/include/boost/compute/detail/meta_kernel.hpp @@ -968,6 +968,14 @@ inline meta_kernel& operator<<(meta_kernel &kernel, return kernel << "!(" << expr.pred()(expr.expr()) << ')'; } +template +inline meta_kernel& operator<<(meta_kernel &kernel, + const invoked_unary_nor_function &expr) +{ + return kernel << "!((" << expr.pred1()(expr.expr1()) <<")||("< inline meta_kernel& operator<<(meta_kernel &kernel, const invoked_binary_negate_function +class invoked_unary_nor_function +{ +public: + typedef int result_type; + + invoked_unary_nor_function(const Predicate1 &pred1, + const Expr &expr1, + const Predicate2 &pred2, + const Expr &expr2) + : m_pred1(pred1), + m_expr1(expr1), + m_pred2(pred2), + m_expr2(expr2) + { + } + + Predicate1 pred1() const + { + return m_pred1; + } + + Expr expr1() const + { + return m_expr1; + } + Predicate2 pred2() const + { + return m_pred2; + } + + Expr expr2() const + { + return m_expr2; + } +private: + Predicate1 m_pred1; + Predicate2 m_pred2; + Expr m_expr1,m_expr2; +}; template class invoked_binary_negate_function @@ -134,6 +175,34 @@ class unary_negate : public unary_function private: Predicate m_pred; }; + +/// The unary_nor function adaptor nor 2 unary function. +/// +/// \see nor1() +template +class unary_nor : public unary_function +{ +public: + explicit unary_nor(Predicate1 pred1,Predicate2 pred2) + : m_pred1(pred1),m_pred2(pred2) + { + } + + /// \internal_ + template + detail::invoked_unary_nor_function + operator()(const Arg &arg) const + { + return detail::invoked_unary_nor_function< + Predicate1,Predicate2, + Arg + >(m_pred1, arg,m_pred2,arg); + } + +private: + Predicate1 m_pred1; + Predicate2 m_pred2; +}; /// The binnary_negate function adaptor negates a binary function. /// @@ -174,6 +243,18 @@ inline unary_negate not1(const Predicate &predicate) return unary_negate(predicate); } +/// Returns a unary_nor adaptor around \p predicates. +/// +/// \param predicate the unary function to wrap +/// \param predicate the unary function to wrap +/// +/// \return a unary_nor wrapper around \p predicates +template +inline unary_nor nor1(const Predicate1 &predicate1,const Predicate2 &predicate2) +{ + return unary_nor(predicate1,predicate2); +} + /// Returns a binary_negate adaptor around \p predicate. /// /// \param predicate the binary function to wrap