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) {
33 return (a < b) ? b : a;
36 template <
class T,
class ComparatorType>
37 constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b,
38 ComparatorType comp) {
42 return comp(a, b) ? b : a;
46 KOKKOS_INLINE_FUNCTION constexpr T max(std::initializer_list<T> ilist) {
47 auto first = ilist.begin();
48 auto const last = ilist.end();
50 if (first == last)
return result;
51 while (++first != last) {
52 if (result < *first) result = *first;
57 template <
class T,
class Compare>
58 KOKKOS_INLINE_FUNCTION constexpr T max(std::initializer_list<T> ilist,
60 auto first = ilist.begin();
61 auto const last = ilist.end();
63 if (first == last)
return result;
64 while (++first != last) {
65 if (comp(result, *first)) result = *first;
72 constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b) {
76 return (b < a) ? b : a;
79 template <
class T,
class ComparatorType>
80 constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b,
81 ComparatorType comp) {
85 return comp(b, a) ? b : a;
89 KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist) {
90 auto first = ilist.begin();
91 auto const last = ilist.end();
93 if (first == last)
return result;
94 while (++first != last) {
95 if (*first < result) result = *first;
100 template <
class T,
class Compare>
101 KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist,
103 auto first = ilist.begin();
104 auto const last = ilist.end();
105 auto result = *first;
106 if (first == last)
return result;
107 while (++first != last) {
108 if (comp(*first, result)) result = *first;
115 constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b) {
117 return (b < a) ? return_t{b, a} : return_t{a, b};
120 template <
class T,
class ComparatorType>
121 constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b,
122 ComparatorType comp) {
124 return comp(b, a) ? return_t{b, a} : return_t{a, b};
129 std::initializer_list<T> ilist) {
130 auto first = ilist.begin();
131 auto const last = ilist.end();
134 if (first == last || ++next == last)
return result;
136 result.
first = *next;
138 result.second = *next;
140 while (++first != last) {
141 if (++next == last) {
142 if (*first < result.first)
143 result.first = *first;
144 else if (!(*first < result.second))
145 result.second = *first;
148 if (*next < *first) {
149 if (*next < result.first) result.first = *next;
150 if (!(*first < result.second)) result.second = *first;
152 if (*first < result.first) result.first = *first;
153 if (!(*next < result.second)) result.second = *next;
160 template <
class T,
class Compare>
162 std::initializer_list<T> ilist, Compare comp) {
163 auto first = ilist.begin();
164 auto const last = ilist.end();
167 if (first == last || ++next == last)
return result;
168 if (comp(*next, *first))
169 result.
first = *next;
171 result.second = *next;
173 while (++first != last) {
174 if (++next == last) {
175 if (comp(*first, result.first))
176 result.first = *first;
177 else if (!comp(*first, result.second))
178 result.second = *first;
181 if (comp(*next, *first)) {
182 if (comp(*next, result.first)) result.first = *next;
183 if (!comp(*first, result.second)) result.second = *first;
185 if (comp(*first, result.first)) result.first = *first;
186 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.