17 #ifndef KOKKOS_MIN_MAX_HPP
18 #define KOKKOS_MIN_MAX_HPP
20 #include <Kokkos_Macros.hpp>
23 #include <initializer_list>
29 constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b) {
30 return (a < b) ? b : a;
33 template <
class T,
class ComparatorType>
34 constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b,
35 ComparatorType comp) {
36 return comp(a, b) ? b : a;
40 KOKKOS_INLINE_FUNCTION constexpr T max(std::initializer_list<T> ilist) {
41 auto first = ilist.begin();
42 auto const last = ilist.end();
44 if (first == last)
return result;
45 while (++first != last) {
46 if (result < *first) result = *first;
51 template <
class T,
class Compare>
52 KOKKOS_INLINE_FUNCTION constexpr T max(std::initializer_list<T> ilist,
54 auto first = ilist.begin();
55 auto const last = ilist.end();
57 if (first == last)
return result;
58 while (++first != last) {
59 if (comp(result, *first)) result = *first;
66 constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b) {
67 return (b < a) ? b : a;
70 template <
class T,
class ComparatorType>
71 constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b,
72 ComparatorType comp) {
73 return comp(b, a) ? b : a;
77 KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist) {
78 auto first = ilist.begin();
79 auto const last = ilist.end();
81 if (first == last)
return result;
82 while (++first != last) {
83 if (*first < result) result = *first;
88 template <
class T,
class Compare>
89 KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist,
91 auto first = ilist.begin();
92 auto const last = ilist.end();
94 if (first == last)
return result;
95 while (++first != last) {
96 if (comp(*first, result)) result = *first;
103 constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b) {
105 return (b < a) ? return_t{b, a} : return_t{a, b};
108 template <
class T,
class ComparatorType>
109 constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b,
110 ComparatorType comp) {
112 return comp(b, a) ? return_t{b, a} : return_t{a, b};
117 std::initializer_list<T> ilist) {
118 auto first = ilist.begin();
119 auto const last = ilist.end();
122 if (first == last || ++next == last)
return result;
124 result.
first = *next;
126 result.second = *next;
128 while (++first != last) {
129 if (++next == last) {
130 if (*first < result.first)
131 result.first = *first;
132 else if (!(*first < result.second))
133 result.second = *first;
136 if (*next < *first) {
137 if (*next < result.first) result.first = *next;
138 if (!(*first < result.second)) result.second = *first;
140 if (*first < result.first) result.first = *first;
141 if (!(*next < result.second)) result.second = *next;
148 template <
class T,
class Compare>
150 std::initializer_list<T> ilist, Compare comp) {
151 auto first = ilist.begin();
152 auto const last = ilist.end();
155 if (first == last || ++next == last)
return result;
156 if (comp(*next, *first))
157 result.
first = *next;
159 result.second = *next;
161 while (++first != last) {
162 if (++next == last) {
163 if (comp(*first, result.first))
164 result.first = *first;
165 else if (!comp(*first, result.second))
166 result.second = *first;
169 if (comp(*next, *first)) {
170 if (comp(*next, result.first)) result.first = *next;
171 if (!comp(*first, result.second)) result.second = *first;
173 if (comp(*first, result.first)) result.first = *first;
174 if (!comp(*next, result.second)) result.second = *next;
Declaration and definition of Kokkos::pair.
Replacement for std::pair that works on CUDA devices.
first_type first
The first element of the pair.