8 #ifndef OPENFPM_DATA_SRC_SPACE_SHAPE_POINT_OPERATORS_FUNCTIONS_HPP_
9 #define OPENFPM_DATA_SRC_SPACE_SHAPE_POINT_OPERATORS_FUNCTIONS_HPP_
11 #define CREATE_ARG_FUNC_CLASS(fun_base,fun_name,OP_ID) \
13 template <typename orig, typename exp1, typename exp2>\
14 class point_expression_op<orig,exp1,exp2, OP_ID >\
18 mutable typename std::remove_const<typename orig::coord_type>::type scal;\
22 typedef orig orig_type;\
24 typedef int is_expression;\
26 typedef int has_init;\
28 typedef typename orig::coord_type return_type;\
30 static const unsigned int nvals = exp1::nvals;\
32 inline point_expression_op(const exp1 & o1)\
36 inline void init() const\
41 template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const\
43 return fun_base(o1.value(k));\
46 template <typename T>operator T() const\
49 return fun_base(o1.value(0));\
59 #define CREATE_ARG_FUNC(fun_base,fun_name,OP_ID) \
61 template<typename orig,typename exp1, typename exp_2, unsigned int op1>\
62 inline point_expression_op<orig,point_expression_op<orig,exp1,exp_2,op1>,void, OP_ID >\
63 fun_name(const point_expression_op<orig,exp1,exp_2,op1> & va)\
65 point_expression_op<orig,point_expression_op<orig,exp1,exp_2,op1>,void,OP_ID> exp_sum(va);\
71 template<unsigned int dim, typename T>\
72 inline point_expression_op<Point<dim,T>,Point<dim,T>,void, OP_ID >\
73 fun_name(const Point<dim,T> & va)\
75 point_expression_op<Point<dim,T>,Point<dim,T>,void,OP_ID> exp_sum(va);\
89 template <
typename orig,
typename exp1,
typename exp2>
95 mutable typename std::remove_const<typename orig::coord_type>::type
scal;
112 static const unsigned int nvals = 1;
128 for (
size_t i = 0 ; i < orig::dims ; i++)
129 scal += o1.value(i) * o1.value(i);
141 template<
typename r_type=
typename std::remove_reference<decltype(o1.value(0))>::type >
inline r_type
value(
size_t k)
const
146 template <
typename T>
operator T()
const
161 template <
typename orig,
typename exp1,
typename exp2>
168 mutable typename std::remove_const<typename orig::coord_type>::type
scal;
172 typedef orig orig_type;
184 static const unsigned int nvals = 1;
200 for (
size_t i = 0 ; i < orig::dims ; i++)
201 scal += o1.value(i) * o1.value(i);
211 template<
typename r_type=
typename std::remove_reference<decltype(o1.value(0))>::type >
inline r_type
value(
size_t k)
const
217 template <
typename T>
operator T()
const
225 CREATE_ARG_FUNC_CLASS(std::abs,abs,POINT_ABS)
226 CREATE_ARG_FUNC_CLASS(std::exp,exp,POINT_EXP)
227 CREATE_ARG_FUNC_CLASS(std::exp2,exp2,POINT_EXP2)
228 CREATE_ARG_FUNC_CLASS(std::expm1,expm1,POINT_EXPM1)
229 CREATE_ARG_FUNC_CLASS(std::log,log,POINT_LOG)
230 CREATE_ARG_FUNC_CLASS(std::log10,log10,POINT_LOG10)
231 CREATE_ARG_FUNC_CLASS(std::log2,log2,POINT_LOG2)
232 CREATE_ARG_FUNC_CLASS(std::log1p,log1p,POINT_LOG1P)
233 CREATE_ARG_FUNC_CLASS(std::sqrt,sqrt,POINT_SQRT)
234 CREATE_ARG_FUNC_CLASS(std::cbrt,cbrt,POINT_CBRT)
235 CREATE_ARG_FUNC_CLASS(std::sin,sin,POINT_SIN)
236 CREATE_ARG_FUNC_CLASS(std::cos,cos,POINT_COS)
237 CREATE_ARG_FUNC_CLASS(std::tan,tan,POINT_TAN)
238 CREATE_ARG_FUNC_CLASS(std::asin,asin,POINT_ASIN)
239 CREATE_ARG_FUNC_CLASS(std::acos,acos,POINT_ACOS)
240 CREATE_ARG_FUNC_CLASS(std::atan,atan,POINT_ATAN)
241 CREATE_ARG_FUNC_CLASS(std::sinh,sinh,POINT_SINH)
242 CREATE_ARG_FUNC_CLASS(std::cosh,cosh,POINT_COSH)
243 CREATE_ARG_FUNC_CLASS(std::tanh,tanh,POINT_TANH)
244 CREATE_ARG_FUNC_CLASS(std::asinh,asinh,POINT_ASINH)
245 CREATE_ARG_FUNC_CLASS(std::acosh,acosh,POINT_ACOSH)
246 CREATE_ARG_FUNC_CLASS(std::atanh,atanh,POINT_ATANH)
247 CREATE_ARG_FUNC_CLASS(std::erf,erf,POINT_ERF)
248 CREATE_ARG_FUNC_CLASS(std::erfc,erfc,POINT_ERFC)
249 CREATE_ARG_FUNC_CLASS(std::tgamma,tgamma,POINT_TGAMMA)
250 CREATE_ARG_FUNC_CLASS(std::lgamma,lgamma,POINT_LGAMMA)
251 CREATE_ARG_FUNC_CLASS(std::ceil,ceil,POINT_CEIL)
252 CREATE_ARG_FUNC_CLASS(std::floor,floor,POINT_FLOOR)
253 CREATE_ARG_FUNC_CLASS(std::trunc,trunc,POINT_TRUNC)
254 CREATE_ARG_FUNC_CLASS(std::round,round,POINT_ROUND)
255 CREATE_ARG_FUNC_CLASS(std::nearbyint,nearbyint,POINT_NEARBYINT)
256 CREATE_ARG_FUNC_CLASS(std::rint,rint,POINT_RINT)
267 template<typename orig,typename exp1, typename exp2,
unsigned int op1>
284 template <
typename T>T norm(T d)
297 template<
unsigned int dim,
typename T>
301 point_expression_op<Point<dim,T>,point_expression<T[dim]>,void,POINT_NORM> exp_sum( (
point_expression<T[dim]>(d)) );
315 template<
unsigned int dim,
typename T>
316 inline point_expression_op<Point<dim,T>,
Point<dim,T>,void,POINT_NORM>
317 norm(
const Point<dim,T> & va)
319 point_expression_op<Point<dim,T>,Point<dim,T>,void,POINT_NORM> exp_sum(va);
334 template<
typename orig,
typename exp1,
typename exp2,
unsigned int op1>
338 point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,void,POINT_NORM2> exp_sum(va);
351 template <
typename T>T norm2(T d)
364 template<
unsigned int dim,
typename T>
365 inline point_expression_op<Point<dim,T>,point_expression<T[dim]>,void,POINT_NORM2>
368 point_expression_op<Point<dim,T>,point_expression<T[dim]>,void,POINT_NORM2> exp_sum( (
point_expression<T[dim]>(d)) );
382 template<
unsigned int dim,
typename T>
383 inline point_expression_op<Point<dim,T>,Point<dim,T>,void,POINT_NORM2>
384 norm2(
const Point<dim,T> & va)
386 point_expression_op<Point<dim,T>,Point<dim,T>,void,POINT_NORM2> exp_sum(va);
396 template <
typename T,
typename P>
auto distance(T exp1,
P exp2) -> decltype(norm(exp1 - exp2))
398 return norm(exp1 - exp2);
404 CREATE_ARG_FUNC(std::abs,abs,POINT_ABS)
405 CREATE_ARG_FUNC(std::exp,exp,POINT_EXP)
406 CREATE_ARG_FUNC(std::exp2,exp2,POINT_EXP2)
407 CREATE_ARG_FUNC(std::expm1,expm1,POINT_EXPM1)
408 CREATE_ARG_FUNC(std::log,log,POINT_LOG)
409 CREATE_ARG_FUNC(std::log10,log10,POINT_LOG10)
410 CREATE_ARG_FUNC(std::log2,log2,POINT_LOG2)
411 CREATE_ARG_FUNC(std::log1p,log1p,POINT_LOG1P)
412 CREATE_ARG_FUNC(std::sqrt,sqrt,POINT_SQRT)
413 CREATE_ARG_FUNC(std::cbrt,cbrt,POINT_CBRT)
414 CREATE_ARG_FUNC(std::sin,sin,POINT_SIN)
415 CREATE_ARG_FUNC(std::cos,cos,POINT_COS)
416 CREATE_ARG_FUNC(std::tan,tan,POINT_TAN)
417 CREATE_ARG_FUNC(std::asin,asin,POINT_ASIN)
418 CREATE_ARG_FUNC(std::acos,acos,POINT_ACOS)
419 CREATE_ARG_FUNC(std::atan,atan,POINT_ATAN)
420 CREATE_ARG_FUNC(std::sinh,sinh,POINT_SINH)
421 CREATE_ARG_FUNC(std::cosh,cosh,POINT_COSH)
422 CREATE_ARG_FUNC(std::tanh,tanh,POINT_TANH)
423 CREATE_ARG_FUNC(std::asinh,asinh,POINT_ASINH)
424 CREATE_ARG_FUNC(std::acosh,acosh,POINT_ACOSH)
425 CREATE_ARG_FUNC(std::atanh,atanh,POINT_ATANH)
426 CREATE_ARG_FUNC(std::erf,erf,POINT_ERF)
427 CREATE_ARG_FUNC(std::erfc,erfc,POINT_ERFC)
428 CREATE_ARG_FUNC(std::tgamma,tgamma,POINT_TGAMMA)
429 CREATE_ARG_FUNC(std::lgamma,lgamma,POINT_LGAMMA)
430 CREATE_ARG_FUNC(std::ceil,ceil,POINT_CEIL)
431 CREATE_ARG_FUNC(std::floor,floor,POINT_FLOOR)
432 CREATE_ARG_FUNC(std::trunc,trunc,POINT_TRUNC)
433 CREATE_ARG_FUNC(std::round,round,POINT_ROUND)
434 CREATE_ARG_FUNC(std::nearbyint,nearbyint,POINT_NEARBYINT)
435 CREATE_ARG_FUNC(std::rint,rint,POINT_RINT)
void init() const
This function must be called before value.
point_expression_op(const exp1 &o1)
Constructor from expression.
int is_expression
indicate that this class encapsulate an expression
orig::coord_type return_type
return type of the expression
Specialization for an array of dimension dim as expression.
orig::coord_type return_type
return type of the expression
Unknown operation specialization.
This class implement the point shape in an N-dimensional space.
Main class that encapsulate a constant number used in a point expression.
int has_init
indicate that init must be called before value
orig orig_type
Origin type.
int is_expression
indicate that this class encapsulate an expression
std::remove_const< typename orig::coord_type >::type scal
result of the expression
void init() const
This function must be called before value.
r_type value(size_t k) const
Evaluate the expression.
r_type value(size_t k) const
Evaluate the expression.
Point square norm operation.
int has_init
indicate that init must be called before value
Test structure used for several test.
std::remove_const< typename orig::coord_type >::type scal
Scalar value.
point_expression_op(const exp1 &o1)
constructor from an expression