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

[SYCLomatic] Introduce dpct::argmax and dpct::argmin functors #2032

Merged
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
34 changes: 34 additions & 0 deletions clang/runtime/dpct-rt/include/dpct/dpl_extras/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,40 @@ template <typename _Op> struct mark_functor_const {
}
};

// Forward declare key_value_pair to avoid creating cyclic dependency between
// iterators.h and functional.h.
template <typename _KeyTp, typename _ValueTp> class key_value_pair;

// Returns the smaller of two key_value_pair objects based on their value
// member. If value elements compare equal, then the pair with the lower key is
// returned.
struct argmin {
template <typename _ValueTp, typename _KeyTp>
key_value_pair<_KeyTp, _ValueTp>
operator()(const key_value_pair<_KeyTp, _ValueTp> &lhs,
const key_value_pair<_KeyTp, _ValueTp> &rhs) const {
return (lhs.value < rhs.value) ||
(lhs.value == rhs.value && lhs.key < rhs.key)
? lhs
: rhs;
}
};

// Returns the larger of two key_value_pair objects based on their value member.
// If value elements compare equal, then the pair with the lower key is
// returned.
struct argmax {
template <typename _ValueTp, typename _KeyTp>
key_value_pair<_KeyTp, _ValueTp>
operator()(const key_value_pair<_KeyTp, _ValueTp> &lhs,
const key_value_pair<_KeyTp, _ValueTp> &rhs) const {
return (lhs.value > rhs.value) ||
(lhs.value == rhs.value && lhs.key < rhs.key)
? lhs
: rhs;
}
};

namespace internal {

template <class _ExecPolicy, class _T>
Expand Down
Loading