ISAAC
Overview :: Library Doc :: Server Doc :: JSON Commands

In Situ Animation of Accelerated Computations

isaac_functors.hpp
Go to the documentation of this file.
1 /* This file is part of ISAAC.
2  *
3  * ISAAC is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * ISAAC is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with ISAAC. If not, see <www.gnu.org/licenses/>. */
15 
16 #pragma once
17 
18 #include "isaac_types.hpp"
19 #include <boost/mpl/list.hpp>
20 #include <boost/mpl/int.hpp>
21 
22 #ifndef ISAAC_FUNCTOR_LENGTH_ENABLED
23  #define ISAAC_FUNCTOR_LENGTH_ENABLED 1
24 #endif
25 #ifndef ISAAC_FUNCTOR_MUL_ENABLED
26  #define ISAAC_FUNCTOR_MUL_ENABLED 1
27 #endif
28 #ifndef ISAAC_FUNCTOR_ADD_ENABLED
29  #define ISAAC_FUNCTOR_ADD_ENABLED 1
30 #endif
31 #ifndef ISAAC_FUNCTOR_POW_ENABLED
32  #define ISAAC_FUNCTOR_POW_ENABLED 1
33 #endif
34 #ifndef ISAAC_FUNCTOR_SUM_ENABLED
35  #define ISAAC_FUNCTOR_SUM_ENABLED 1
36 #endif
37 
38 namespace isaac
39 {
40 
41 namespace fus = boost::fusion;
42 namespace mpl = boost::mpl;
43 
45 {
46  static const bool uses_parameter = false;
47  static const std::string name;
48  static const std::string description;
50  static isaac_float_dim<4> call( const isaac_float_dim<4> v, const isaac_float4& p)
51  {
52  return v;
53  }
55  static isaac_float_dim<3> call( const isaac_float_dim<3> v, const isaac_float4& p)
56  {
57  return v;
58  }
60  static isaac_float_dim<2> call( const isaac_float_dim<2> v, const isaac_float4& p)
61  {
62  return v;
63  }
65  static isaac_float_dim<1> call( const isaac_float_dim<1> v, const isaac_float4& p)
66  {
67  return v;
68  }
70  static std::string getName()
71  {
72  return std::string("idem");
73  }
75  static std::string getDescription()
76  {
77  return std::string("Does nothing. Keeps the feature dimension.");
78  }
79 };
80 
81 #if ISAAC_FUNCTOR_LENGTH_ENABLED == 1
83 {
84  static const bool uses_parameter = false;
85  static const std::string name;
86  static const std::string description;
87 
88  //Against annoying double->float casting warning with gcc5
89  #pragma GCC diagnostic push
90  #pragma GCC diagnostic ignored "-Wnarrowing"
91 
93  static isaac_float_dim<1> call( const isaac_float_dim<4> v, const isaac_float4& p)
94  {
95  isaac_float_dim<1> result =
96  {
97  sqrt(
98  v.value.x * v.value.x +
99  v.value.y * v.value.y +
100  v.value.z * v.value.z +
101  v.value.w * v.value.w
102  )
103  };
104  return result;
105  }
107  static isaac_float_dim<1> call( const isaac_float_dim<3> v, const isaac_float4& p)
108  {
109  isaac_float_dim<1> result =
110  {
111  sqrt(
112  v.value.x * v.value.x +
113  v.value.y * v.value.y +
114  v.value.z * v.value.z
115  )
116  };
117  return result;
118  }
120  static isaac_float_dim<1> call( const isaac_float_dim<2> v, const isaac_float4& p)
121  {
122  isaac_float_dim<1> result =
123  {
124  sqrt(
125  v.value.x * v.value.x +
126  v.value.y * v.value.y
127  )
128  };
129  return result;
130  }
132  static isaac_float_dim<1> call( const isaac_float_dim<1> v, const isaac_float4& p)
133  {
134  isaac_float_dim<1> result = { fabs( v.value.x ) };
135  return result;
136  }
137 
138  #pragma GCC diagnostics pop
139 
141  static std::string getName()
142  {
143  return std::string("length");
144  }
146  static std::string getDescription()
147  {
148  return std::string("Calculates the length of an input. Reduces the feature dimension to 1.");
149  }
150 };
151 #endif
152 
153 #if ISAAC_FUNCTOR_MUL_ENABLED == 1
155 {
156  static const bool uses_parameter = true;
157  static const std::string name;
158  static const std::string description;
160  static isaac_float_dim<4> call( const isaac_float_dim<4> v, const isaac_float4& p)
161  {
162  isaac_float_dim<4> result = { v.value * p };
163  return result;
164  }
166  static isaac_float_dim<3> call( const isaac_float_dim<3> v, const isaac_float4& p)
167  {
168  isaac_float_dim<3> result =
169  {
170  v.value.x * p.x,
171  v.value.y * p.y,
172  v.value.z * p.z
173  };
174  return result;
175  }
177  static isaac_float_dim<2> call( const isaac_float_dim<2> v, const isaac_float4& p)
178  {
179  isaac_float_dim<2> result =
180  {
181  v.value.x * p.x,
182  v.value.y * p.y
183  };
184  return result;
185  }
187  static isaac_float_dim<1> call( const isaac_float_dim<1> v, const isaac_float4& p)
188  {
189  isaac_float_dim<1> result = { v.value.x * p.x };
190  return result;
191  }
193  static std::string getName()
194  {
195  return std::string("mul");
196  }
198  static std::string getDescription()
199  {
200  return std::string("Multiplies the input with a constant parameter. Keeps the feature dimension.");
201  }
202 };
203 #endif
204 
205 #if ISAAC_FUNCTOR_ADD_ENABLED == 1
207 {
208  static const bool uses_parameter = true;
209  static const std::string name;
210  static const std::string description;
212  static isaac_float_dim<4> call( const isaac_float_dim<4> v, const isaac_float4& p)
213  {
214  isaac_float_dim<4> result = { v.value + p };
215  return result;
216  }
218  static isaac_float_dim<3> call( const isaac_float_dim<3> v, const isaac_float4& p)
219  {
220  isaac_float_dim<3> result =
221  {
222  v.value.x + p.x,
223  v.value.y + p.y,
224  v.value.z + p.z
225  };
226  return result;
227  }
229  static isaac_float_dim<2> call( const isaac_float_dim<2> v, const isaac_float4& p)
230  {
231  isaac_float_dim<2> result =
232  {
233  v.value.x + p.x,
234  v.value.y + p.y
235  };
236  return result;
237  }
239  static isaac_float_dim<1> call( const isaac_float_dim<1> v, const isaac_float4& p)
240  {
241  isaac_float_dim<1> result = { v.value.x + p.x };
242  return result;
243  }
245  static std::string getName()
246  {
247  return std::string("add");
248  }
250  static std::string getDescription()
251  {
252  return std::string("Summarizes the input with a constant parameter. Keeps the feature dimension.");
253  }
254 };
255 #endif
256 
257 #if ISAAC_FUNCTOR_POW_ENABLED == 1
259 {
260  static const bool uses_parameter = true;
261  static const std::string name;
262  static const std::string description;
264  static isaac_float_dim<4> call( const isaac_float_dim<4> v, const isaac_float4& p)
265  {
266  isaac_float_dim<4> result =
267  {
268  pow( v.value.x, p.x ),
269  pow( v.value.y, p.y ),
270  pow( v.value.z, p.z ),
271  pow( v.value.w, p.w )
272  };
273  return result;
274  }
276  static isaac_float_dim<3> call( const isaac_float_dim<3> v, const isaac_float4& p)
277  {
278  isaac_float_dim<3> result =
279  {
280  pow( v.value.x, p.x ),
281  pow( v.value.y, p.y ),
282  pow( v.value.z, p.z )
283  };
284  return result;
285  }
287  static isaac_float_dim<2> call( const isaac_float_dim<2> v, const isaac_float4& p)
288  {
289  isaac_float_dim<2> result =
290  {
291  pow( v.value.x, p.x ),
292  pow( v.value.y, p.y )
293  };
294  return result;
295  }
297  static isaac_float_dim<1> call( const isaac_float_dim<1> v, const isaac_float4& p)
298  {
299  isaac_float_dim<1> result = { pow( v.value.x, p.x ) };
300  return result;
301  }
303  static std::string getName()
304  {
305  return std::string("pow");
306  }
308  static std::string getDescription()
309  {
310  return std::string("Calculates the power of the input with a constant exponent. Keeps the feature dimension.");
311  }
312 };
313 #endif
314 
315 #if ISAAC_FUNCTOR_SUM_ENABLED == 1
317 {
318  static const bool uses_parameter = false;
319  static const std::string name;
320  static const std::string description;
322  static isaac_float_dim<1> call( const isaac_float_dim<4> v, const isaac_float4& p)
323  {
324  isaac_float_dim<1> result =
325  {
326  v.value.x +
327  v.value.y +
328  v.value.z +
329  v.value.w
330  };
331  return result;
332  }
334  static isaac_float_dim<1> call( const isaac_float_dim<3> v, const isaac_float4& p)
335  {
336  isaac_float_dim<1> result =
337  {
338  v.value.x +
339  v.value.y +
340  v.value.z
341  };
342  return result;
343  }
345  static isaac_float_dim<1> call( const isaac_float_dim<2> v, const isaac_float4& p)
346  {
347  isaac_float_dim<1> result =
348  {
349  v.value.x +
350  v.value.y
351  };
352  return result;
353  }
355  static isaac_float_dim<1> call( const isaac_float_dim<1> v, const isaac_float4& p)
356  {
357  isaac_float_dim<1> result = { v.value.x };
358  return result;
359  }
361  static std::string getName()
362  {
363  return std::string("sum");
364  }
366  static std::string getDescription()
367  {
368  return std::string("Calculates the sum of all components. Reduces the feature dimension to 1.");
369  }
370 };
371 #endif
372 
373 typedef fus::list <
375 #if ISAAC_FUNCTOR_ADD_ENABLED == 1
377 #endif
378 #if ISAAC_FUNCTOR_MUL_ENABLED == 1
380 #endif
381 #if ISAAC_FUNCTOR_LENGTH_ENABLED == 1
383 #endif
384 #if ISAAC_FUNCTOR_POW_ENABLED == 1
386 #endif
387 #if ISAAC_FUNCTOR_SUM_ENABLED == 1
389 #endif
391 
392 #define ISAAC_FUNCTOR_COUNT \
393  BOOST_PP_ADD( BOOST_PP_IF( ISAAC_FUNCTOR_ADD_ENABLED, 1, 0 ), \
394  BOOST_PP_ADD( BOOST_PP_IF( ISAAC_FUNCTOR_MUL_ENABLED, 1, 0 ), \
395  BOOST_PP_ADD( BOOST_PP_IF( ISAAC_FUNCTOR_LENGTH_ENABLED, 1, 0 ), \
396  BOOST_PP_ADD( BOOST_PP_IF( ISAAC_FUNCTOR_POW_ENABLED, 1, 0 ), \
397  BOOST_PP_ADD( BOOST_PP_IF( ISAAC_FUNCTOR_SUM_ENABLED, 1, 0 ), \
398  1 ) ) ) ) )
399 
400 } //namespace isaac;
#define ISAAC_HOST_INLINE
static const std::string name
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 3 > call(const isaac_float_dim< 3 > v, const isaac_float4 &p)
static ISAAC_HOST_INLINE std::string getName()
static ISAAC_HOST_INLINE std::string getName()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 4 > call(const isaac_float_dim< 4 > v, const isaac_float4 &p)
Definition: isaac.hpp:60
static ISAAC_HOST_INLINE std::string getName()
static const std::string description
static const std::string description
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 1 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 4 > call(const isaac_float_dim< 4 > v, const isaac_float4 &p)
static const std::string name
static const std::string name
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 1 > v, const isaac_float4 &p)
static const bool uses_parameter
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 2 > call(const isaac_float_dim< 2 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 1 > v, const isaac_float4 &p)
fus::list< IsaacFunctorIdem,IsaacFunctorAdd,IsaacFunctorMul,IsaacFunctorLength,IsaacFunctorPow,IsaacFunctorSum > IsaacFunctorPool
static ISAAC_HOST_INLINE std::string getDescription()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 3 > call(const isaac_float_dim< 3 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 2 > call(const isaac_float_dim< 2 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 4 > v, const isaac_float4 &p)
static ISAAC_HOST_INLINE std::string getDescription()
static ISAAC_HOST_INLINE std::string getName()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 2 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 3 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 4 > v, const isaac_float4 &p)
static const std::string description
#define ISAAC_HOST_DEVICE_INLINE
static ISAAC_HOST_INLINE std::string getName()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 3 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 2 > v, const isaac_float4 &p)
static const std::string description
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 1 > v, const isaac_float4 &p)
static const std::string description
static const std::string name
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 2 > call(const isaac_float_dim< 2 > v, const isaac_float4 &p)
static const std::string description
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 1 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 4 > call(const isaac_float_dim< 4 > v, const isaac_float4 &p)
static const std::string name
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 3 > call(const isaac_float_dim< 3 > v, const isaac_float4 &p)
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 3 > call(const isaac_float_dim< 3 > v, const isaac_float4 &p)
static ISAAC_HOST_INLINE std::string getDescription()
static const std::string name
static ISAAC_HOST_INLINE std::string getName()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 1 > call(const isaac_float_dim< 1 > v, const isaac_float4 &p)
static ISAAC_HOST_INLINE std::string getDescription()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 4 > call(const isaac_float_dim< 4 > v, const isaac_float4 &p)
static ISAAC_HOST_INLINE std::string getDescription()
static ISAAC_HOST_INLINE std::string getDescription()
static ISAAC_HOST_DEVICE_INLINE isaac_float_dim< 2 > call(const isaac_float_dim< 2 > v, const isaac_float4 &p)