Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_Functional.hpp
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 2.0
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef KOKKOS_FUNCTIONAL_HPP
43 #define KOKKOS_FUNCTIONAL_HPP
44 
45 #include <Kokkos_Macros.hpp>
46 #include <impl/Kokkos_Functional_impl.hpp>
47 
48 namespace Kokkos {
49 
50 // These should work for most types
51 
52 template <typename T>
53 struct pod_hash
54 {
55  typedef T argument_type;
56  typedef T first_argument_type;
57  typedef uint32_t second_argument_type;
58  typedef uint32_t result_type;
59 
60  KOKKOS_FORCEINLINE_FUNCTION
61  uint32_t operator()(T const & t) const
62  { return Impl::MurmurHash3_x86_32( &t, sizeof(T), 0); }
63 
64  KOKKOS_FORCEINLINE_FUNCTION
65  uint32_t operator()(T const & t, uint32_t seed) const
66  { return Impl::MurmurHash3_x86_32( &t, sizeof(T), seed); }
67 };
68 
69 template <typename T>
70 struct pod_equal_to
71 {
72  typedef T first_argument_type;
73  typedef T second_argument_type;
74  typedef bool result_type;
75 
76  KOKKOS_FORCEINLINE_FUNCTION
77  bool operator()(T const & a, T const & b) const
78  { return Impl::bitwise_equal(&a,&b); }
79 };
80 
81 template <typename T>
82 struct pod_not_equal_to
83 {
84  typedef T first_argument_type;
85  typedef T second_argument_type;
86  typedef bool result_type;
87 
88  KOKKOS_FORCEINLINE_FUNCTION
89  bool operator()(T const & a, T const & b) const
90  { return !Impl::bitwise_equal(&a,&b); }
91 };
92 
93 template <typename T>
94 struct equal_to
95 {
96  typedef T first_argument_type;
97  typedef T second_argument_type;
98  typedef bool result_type;
99 
100  KOKKOS_FORCEINLINE_FUNCTION
101  bool operator()(T const & a, T const & b) const
102  { return a == b; }
103 };
104 
105 template <typename T>
106 struct not_equal_to
107 {
108  typedef T first_argument_type;
109  typedef T second_argument_type;
110  typedef bool result_type;
111 
112  KOKKOS_FORCEINLINE_FUNCTION
113  bool operator()(T const & a, T const & b) const
114  { return a != b; }
115 };
116 
117 
118 template <typename T>
119 struct greater
120 {
121  typedef T first_argument_type;
122  typedef T second_argument_type;
123  typedef bool result_type;
124 
125  KOKKOS_FORCEINLINE_FUNCTION
126  bool operator()(T const & a, T const & b) const
127  { return a > b; }
128 };
129 
130 
131 template <typename T>
132 struct less
133 {
134  typedef T first_argument_type;
135  typedef T second_argument_type;
136  typedef bool result_type;
137 
138  KOKKOS_FORCEINLINE_FUNCTION
139  bool operator()(T const & a, T const & b) const
140  { return a < b; }
141 };
142 
143 template <typename T>
144 struct greater_equal
145 {
146  typedef T first_argument_type;
147  typedef T second_argument_type;
148  typedef bool result_type;
149 
150  KOKKOS_FORCEINLINE_FUNCTION
151  bool operator()(T const & a, T const & b) const
152  { return a >= b; }
153 };
154 
155 
156 template <typename T>
157 struct less_equal
158 {
159  typedef T first_argument_type;
160  typedef T second_argument_type;
161  typedef bool result_type;
162 
163  KOKKOS_FORCEINLINE_FUNCTION
164  bool operator()(T const & a, T const & b) const
165  { return a <= b; }
166 };
167 
168 } // namespace Kokkos
169 
170 
171 #endif //KOKKOS_FUNCTIONAL_HPP
172