Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nth_element, added unary_nor #568

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/compute/algorithm/detail/radix_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ inline void radix_sort_impl(const buffer_iterator<T> 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<T2>() +"\n"+radix_sort_source, context
);

kernel count_kernel(radix_sort_program, "count");
Expand Down
3 changes: 1 addition & 2 deletions include/boost/compute/algorithm/nth_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions include/boost/compute/detail/meta_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@ inline meta_kernel& operator<<(meta_kernel &kernel,
return kernel << "!(" << expr.pred()(expr.expr()) << ')';
}

template<class Predicate1,class Predicate2, class Arg>
inline meta_kernel& operator<<(meta_kernel &kernel,
const invoked_unary_nor_function<Predicate1,Predicate2,
Arg> &expr)
{
return kernel << "!((" << expr.pred1()(expr.expr1()) <<")||("<<expr.pred2()(expr.expr2())<< "))";
}

template<class Predicate, class Arg1, class Arg2>
inline meta_kernel& operator<<(meta_kernel &kernel,
const invoked_binary_negate_function<Predicate,
Expand Down
81 changes: 81 additions & 0 deletions include/boost/compute/functional/logical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,47 @@ class invoked_unary_negate_function
Predicate m_pred;
Expr m_expr;
};

template<class Predicate1,class Predicate2, class Expr>
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 Predicate, class Expr1, class Expr2>
class invoked_binary_negate_function
Expand Down Expand Up @@ -134,6 +175,34 @@ class unary_negate : public unary_function<void, int>
private:
Predicate m_pred;
};

/// The unary_nor function adaptor nor 2 unary function.
///
/// \see nor1()
template<class Predicate1,class Predicate2>
class unary_nor : public unary_function<void, int>
{
public:
explicit unary_nor(Predicate1 pred1,Predicate2 pred2)
: m_pred1(pred1),m_pred2(pred2)
{
}

/// \internal_
template<class Arg>
detail::invoked_unary_nor_function<Predicate1,Predicate2, Arg>
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.
///
Expand Down Expand Up @@ -174,6 +243,18 @@ inline unary_negate<Predicate> not1(const Predicate &predicate)
return unary_negate<Predicate>(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<class Predicate1,class Predicate2>
inline unary_nor<Predicate1,Predicate2> nor1(const Predicate1 &predicate1,const Predicate2 &predicate2)
{
return unary_nor<Predicate1,Predicate2>(predicate1,predicate2);
}

/// Returns a binary_negate adaptor around \p predicate.
///
/// \param predicate the binary function to wrap
Expand Down