17 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18 #include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22 #ifndef KOKKOS_MIN_MAX_CLAMP_HPP
23 #define KOKKOS_MIN_MAX_CLAMP_HPP
25 #include <Kokkos_Macros.hpp>
28 #include <initializer_list>
34 constexpr KOKKOS_INLINE_FUNCTION
const T& clamp(
const T& value,
const T& lo,
36 KOKKOS_EXPECTS(!(hi < lo));
37 return (value < lo) ? lo : (hi < value) ? hi : value;
40 template <
class T,
class ComparatorType>
41 constexpr KOKKOS_INLINE_FUNCTION
const T& clamp(
const T& value,
const T& lo,
43 ComparatorType comp) {
44 KOKKOS_EXPECTS(!comp(hi, lo));
45 return comp(value, lo) ? lo : comp(hi, value) ? hi : value;
50 constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b) {
51 return (a < b) ? b : a;
54 template <
class T,
class ComparatorType>
55 constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b,
56 ComparatorType comp) {
57 return comp(a, b) ? b : a;
61 KOKKOS_INLINE_FUNCTION constexpr T max(std::initializer_list<T> ilist) {
62 auto first = ilist.begin();
63 auto const last = ilist.end();
65 if (first == last)
return result;
66 while (++first != last) {
67 if (result < *first) result = *first;
72 template <
class T,
class Compare>
73 KOKKOS_INLINE_FUNCTION constexpr T max(std::initializer_list<T> ilist,
75 auto first = ilist.begin();
76 auto const last = ilist.end();
78 if (first == last)
return result;
79 while (++first != last) {
80 if (comp(result, *first)) result = *first;
87 constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b) {
88 return (b < a) ? b : a;
91 template <
class T,
class ComparatorType>
92 constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b,
93 ComparatorType comp) {
94 return comp(b, a) ? b : a;
98 KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist) {
99 auto first = ilist.begin();
100 auto const last = ilist.end();
101 auto result = *first;
102 if (first == last)
return result;
103 while (++first != last) {
104 if (*first < result) result = *first;
109 template <
class T,
class Compare>
110 KOKKOS_INLINE_FUNCTION constexpr T min(std::initializer_list<T> ilist,
112 auto first = ilist.begin();
113 auto const last = ilist.end();
114 auto result = *first;
115 if (first == last)
return result;
116 while (++first != last) {
117 if (comp(*first, result)) result = *first;
124 constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b) {
126 return (b < a) ? return_t{b, a} : return_t{a, b};
129 template <
class T,
class ComparatorType>
130 constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b,
131 ComparatorType comp) {
133 return comp(b, a) ? return_t{b, a} : return_t{a, b};
138 std::initializer_list<T> ilist) {
139 auto first = ilist.begin();
140 auto const last = ilist.end();
143 if (first == last || ++next == last)
return result;
145 result.
first = *next;
147 result.second = *next;
149 while (++first != last) {
150 if (++next == last) {
151 if (*first < result.first)
152 result.first = *first;
153 else if (!(*first < result.second))
154 result.second = *first;
157 if (*next < *first) {
158 if (*next < result.first) result.first = *next;
159 if (!(*first < result.second)) result.second = *first;
161 if (*first < result.first) result.first = *first;
162 if (!(*next < result.second)) result.second = *next;
169 template <
class T,
class Compare>
171 std::initializer_list<T> ilist, Compare comp) {
172 auto first = ilist.begin();
173 auto const last = ilist.end();
176 if (first == last || ++next == last)
return result;
177 if (comp(*next, *first))
178 result.
first = *next;
180 result.second = *next;
182 while (++first != last) {
183 if (++next == last) {
184 if (comp(*first, result.first))
185 result.first = *first;
186 else if (!comp(*first, result.second))
187 result.second = *first;
190 if (comp(*next, *first)) {
191 if (comp(*next, result.first)) result.first = *next;
192 if (!comp(*first, result.second)) result.second = *first;
194 if (comp(*first, result.first)) result.first = *first;
195 if (!comp(*next, result.second)) result.second = *next;
202 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
203 namespace Experimental {
204 using ::Kokkos::clamp;
207 using ::Kokkos::minmax;
Declaration and definition of Kokkos::pair.
Replacement for std::pair that works on CUDA devices.
first_type first
The first element of the pair.