DDC 0.1.0
Loading...
Searching...
No Matches
reducer.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <utility>
8
9#include <Kokkos_Macros.hpp>
10
11namespace ddc::reducer {
12
13template <class T>
14struct sum
15{
16 using value_type = T;
17
18 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
19 const noexcept
20 {
21 return lhs + rhs;
22 }
23};
24
25template <class T>
26struct prod
27{
28 using value_type = T;
29
30 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
31 const noexcept
32 {
33 return lhs * rhs;
34 }
35};
36
37template <class T>
38struct land
39{
40 using value_type = T;
41
42 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
43 const noexcept
44 {
45 return lhs && rhs;
46 }
47};
48
49template <class T>
50struct lor
51{
52 using value_type = T;
53
54 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
55 const noexcept
56 {
57 return lhs || rhs;
58 }
59};
60
61template <class T>
62struct band
63{
64 using value_type = T;
65
66 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
67 const noexcept
68 {
69 return lhs & rhs;
70 }
71};
72
73template <class T>
74struct bor
75{
76 using value_type = T;
77
78 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
79 const noexcept
80 {
81 return lhs | rhs;
82 }
83};
84
85template <class T>
86struct bxor
87{
88 using value_type = T;
89
90 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
91 const noexcept
92 {
93 return lhs ^ rhs;
94 }
95};
96
97template <class T>
98struct min
99{
100 using value_type = T;
101
102 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
103 const noexcept
104 {
105 return lhs < rhs ? lhs : rhs;
106 }
107};
108
109template <class T>
110struct max
111{
112 using value_type = T;
113
114 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
115 const noexcept
116 {
117 return lhs > rhs ? lhs : rhs;
118 }
119};
120
121template <class T>
122struct minmax
123{
124 using value_type = std::pair<T, T>;
125
126 KOKKOS_FUNCTION constexpr value_type operator()(value_type const& lhs, value_type const& rhs)
127 const noexcept
128 {
129 return value_type(
130 lhs.first < rhs.first ? lhs.first : rhs.first,
131 lhs.second > rhs.second ? lhs.second : rhs.second);
132 }
133};
134
135} // namespace ddc::reducer
The top-level namespace of DDC.
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:66
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:78
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:90
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:42
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:54
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:114
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:102
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:126
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:30
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:18