From 201f4861637cd42a11030a15e467843fd591a5fe Mon Sep 17 00:00:00 2001 From: koosha94 Date: Mon, 7 Mar 2016 22:31:35 -0500 Subject: [PATCH 1/4] added support for unary nor --- include/boost/compute/detail/meta_kernel.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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 Date: Mon, 7 Mar 2016 22:32:51 -0500 Subject: [PATCH 2/4] support for unary nor --- include/boost/compute/functional/logical.hpp | 81 ++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/include/boost/compute/functional/logical.hpp b/include/boost/compute/functional/logical.hpp index 2e2c7518b..a58bce547 100644 --- a/include/boost/compute/functional/logical.hpp +++ b/include/boost/compute/functional/logical.hpp @@ -42,6 +42,47 @@ class invoked_unary_negate_function Predicate m_pred; Expr m_expr; }; + +template +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 From 622c192613b40ab9065963c5850a9777104a744e Mon Sep 17 00:00:00 2001 From: koosha94 Date: Mon, 7 Mar 2016 22:34:52 -0500 Subject: [PATCH 3/4] fixed nth_element issue with user defined types --- include/boost/compute/algorithm/nth_element.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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); From f9fc93febbbe3e94a2d8d2c4ab0a552000ffc8e9 Mon Sep 17 00:00:00 2001 From: koosha94 Date: Tue, 8 Mar 2016 19:50:29 -0500 Subject: [PATCH 4/4] This fix #570 --- include/boost/compute/algorithm/detail/radix_sort.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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");