33 #ifndef REMORA_CPU_TRAITS_HPP 34 #define REMORA_CPU_TRAITS_HPP 36 #include "../expression_types.hpp" 42 template<
class Device>
46 struct device_traits<cpu_tag>{
50 static queue_type& default_queue(){
51 static queue_type queue;
56 static std::size_t index_add(std::size_t i, std::size_t j){
61 static typename E::reference linearized_matrix_element(matrix_expression<E, cpu_tag>
const& e, std::size_t i){
62 std::size_t leading_dimension = E::orientation::index_m(e().size1(), e().size2());
63 std::size_t i1 = i / leading_dimension;
64 std::size_t i2 = i % leading_dimension;
65 return e()(E::orientation::index_M(i1,i2), E::orientation::index_m(i1,i2));
68 template <
class Iterator,
class Functor>
69 struct transform_iterator{
70 typedef iterators::transform_iterator<Iterator, Functor> type;
73 template <
class Iterator>
74 struct subrange_iterator{
75 typedef iterators::subrange_iterator<Iterator> type;
78 template <
class Iterator1,
class Iterator2,
class Functor>
79 struct binary_transform_iterator{
80 typedef iterators::binary_transform_iterator<Iterator1,Iterator2, Functor> type;
84 struct constant_iterator{
85 typedef iterators::constant_iterator<T> type;
89 struct one_hot_iterator{
90 typedef iterators::one_hot_iterator<T> type;
93 template<
class Closure>
94 struct indexed_iterator{
95 typedef iterators::indexed_iterator<Closure> type;
101 static const bool left_zero_remains =
false;
102 static const bool right_zero_remains =
false;
103 static const bool right_zero_identity =
true;
104 static const bool left_zero_identity =
false;
105 typedef T result_type;
106 T operator()(T x, T y)
const{
112 static const bool left_zero_remains =
false;
113 static const bool right_zero_remains =
false;
114 static const bool right_zero_identity =
true;
115 static const bool left_zero_identity =
false;
116 typedef T result_type;
117 T operator()(T x, T y)
const{
124 static const bool left_zero_remains =
true;
125 static const bool right_zero_remains =
true;
126 static const bool right_zero_identity =
false;
127 static const bool left_zero_identity =
true;
128 typedef T result_type;
129 T operator()(T x, T y)
const{
136 static const bool left_zero_remains =
true;
137 static const bool right_zero_remains =
false;
138 static const bool right_zero_identity =
false;
139 static const bool left_zero_identity =
true;
140 typedef T result_type;
141 T operator()(T x, T y)
const{
147 struct multiply_and_add{
148 static const bool left_zero_remains =
false;
149 static const bool right_zero_remains =
false;
150 static const bool right_zero_identity =
true;
151 static const bool left_zero_identity =
false;
152 typedef T result_type;
153 multiply_and_add(T scalar):scalar(scalar){}
154 T operator()(T x, T y)
const{
161 struct multiply_assign{
162 static const bool left_zero_remains =
false;
163 static const bool right_zero_remains =
false;
164 static const bool right_zero_identity =
true;
165 static const bool left_zero_identity =
false;
166 typedef T result_type;
167 multiply_assign(T scalar):scalar(scalar){}
168 T operator()(T, T y)
const{
176 static const bool left_zero_remains =
false;
177 static const bool right_zero_remains =
false;
178 typedef T result_type;
179 T operator()(T x, T y)
const {
185 struct multiply_scalar{
186 static const bool zero_identity =
true;
187 typedef T result_type;
188 multiply_scalar(T scalar):m_scalar(scalar){}
189 T operator()(T x)
const{
197 static const bool left_zero_remains =
true;
198 static const bool right_zero_remains =
false;
199 safe_divide(T defaultValue):m_defaultValue(defaultValue) {}
200 typedef T result_type;
201 T operator()(T x, T y)
const{
202 return y == T()? m_defaultValue : x/y;
209 #define REMORA_STD_UNARY_FUNCTION(func, id)\ 212 static const bool zero_identity = id;\ 213 typedef T result_type;\ 214 T operator()(T x)const {\ 215 return std::func(x);\ 241 #undef REMORA_STD_UNARY_FUNCTION 245 static const bool zero_identity =
false;
246 typedef T result_type;
247 T operator()(T x)
const {
249 return (tanh(x/T(2)) + T(1))/T(2);
254 static const bool zero_identity =
false;
255 typedef T result_type;
256 T operator()(T x)
const {
263 return std::log(1+std::exp(x));
269 static const bool zero_identity =
false;
270 typedef T result_type;
271 T operator()(T x)
const {
277 static const bool zero_identity =
true;
278 typedef T result_type;
279 T operator()(T x)
const {
288 static const bool left_zero_remains =
false;
289 static const bool right_zero_remains =
false;
290 typedef T result_type;
291 T operator()(T x, T y)
const{
292 return std::min(x,y);
298 static const bool left_zero_remains =
false;
299 static const bool right_zero_remains =
false;
300 typedef T result_type;
301 T operator()(T x, T y)
const{
302 return std::max(x,y);
310 static const bool left_zero_remains =
false;
311 static const bool right_zero_remains =
false;
312 typedef int result_type;
313 int operator()(T x1, T x2)
const {
319 static const bool left_zero_remains =
false;
320 static const bool right_zero_remains =
false;
321 typedef int result_type;
322 int operator()(T x1, T x2)
const {
329 static const bool left_zero_remains =
false;
330 static const bool right_zero_remains =
false;
331 typedef int result_type;
332 int operator()(T x1, T x2)
const {
338 struct greater_equal{
339 static const bool left_zero_remains =
false;
340 static const bool right_zero_remains =
false;
341 typedef int result_type;
342 int operator()(T x1, T x2)
const {
349 static const bool left_zero_remains =
false;
350 static const bool right_zero_remains =
false;
351 typedef int result_type;
352 int operator()(T x1, T x2)
const {
359 static const bool left_zero_remains =
false;
360 static const bool right_zero_remains =
false;
361 typedef int result_type;
362 int operator()(T x1, T x2)
const {