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) \
13template <typename orig, typename exp1, typename exp2>\
14class 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 typedef typename first_or_second_pt<has_coordtype<exp1>::value,exp1,exp2>::coord_type coord_type;\
35 __device__ __host__ inline explicit point_expression_op(const exp1 & o1)\
39 __device__ __host__ inline void init() const\
44 template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > __device__ __host__ inline r_type value(size_t k) const\
46 return fun_base(o1.value(k));\
49 template <typename T> __device__ __host__ operator T() const\
52 return fun_base(o1.value(0));\
62#define CREATE_ARG_FUNC(fun_base,fun_name,OP_ID) \
64template<typename orig,typename exp1, typename exp_2, unsigned int op1>\
65__device__ __host__ inline point_expression_op<orig,point_expression_op<orig,exp1,exp_2,op1>,void, OP_ID >\
66fun_name(const point_expression_op<orig,exp1,exp_2,op1> & va)\
68 point_expression_op<orig,point_expression_op<orig,exp1,exp_2,op1>,void,OP_ID> exp_sum(va);\
74template<unsigned int dim, typename T>\
75__device__ __host__ inline point_expression_op<Point<dim,T>,Point<dim,T>,void, OP_ID >\
76fun_name(const Point<dim,T> & va)\
78 point_expression_op<Point<dim,T>,Point<dim,T>,void,OP_ID> exp_sum(va);\
91template <
typename orig,
typename exp1,
typename exp2>
97 mutable typename std::remove_const<typename orig::coord_type>::type
scal;
114 static const unsigned int nvals = 1;
116 typedef typename exp1::coord_type coord_type;
128 __device__ __host__
inline void init()
const
132 for (
size_t i = 0 ; i < orig::dims ; i++) {
133 if (fabs(o1.value(i)) > scal) {
134 scal=fabs(o1.value(i));
149 template<
typename r_type=
typename std::remove_reference<
decltype(o1.value(0))>::type > __device__ __host__
inline r_type
value(
size_t k)
const
154 template <
typename T>__device__ __host__
operator T()
const
170template <
typename orig,
typename exp1,
typename exp2>
176 mutable typename std::remove_const<typename orig::coord_type>::type
scal;
193 static const unsigned int nvals = 1;
195 typedef typename exp1::coord_type coord_type;
207 __device__ __host__
inline void init()
const
211 for (
size_t i = 0 ; i < orig::dims ; i++)
212 scal += o1.value(i) * o1.value(i);
224 template<
typename r_type=
typename std::remove_reference<
decltype(o1.value(0))>::type > __device__ __host__
inline r_type
value(
size_t k)
const
229 template <
typename T>__device__ __host__
operator T()
const
244template <
typename orig,
typename exp1,
typename exp2>
251 mutable typename std::remove_const<typename orig::coord_type>::type
scal;
255 typedef orig orig_type;
267 static const unsigned int nvals = 1;
269 typedef typename exp1::coord_type coord_type;
281 __device__ __host__
inline void init()
const
285 for (
size_t i = 0 ; i < orig::dims ; i++)
286 scal += o1.value(i) * o1.value(i);
296 template<
typename r_type=
typename std::remove_reference<
decltype(o1.value(0))>::type > __device__ __host__
inline r_type
value(
size_t k)
const
302 template <
typename T> __device__ __host__
operator T()
const
310CREATE_ARG_FUNC_CLASS(std::abs,abs,POINT_ABS)
311CREATE_ARG_FUNC_CLASS(std::exp,exp,POINT_EXP)
312CREATE_ARG_FUNC_CLASS(std::exp2,exp2,POINT_EXP2)
313CREATE_ARG_FUNC_CLASS(std::expm1,expm1,POINT_EXPM1)
314CREATE_ARG_FUNC_CLASS(std::log,log,POINT_LOG)
315CREATE_ARG_FUNC_CLASS(std::log10,log10,POINT_LOG10)
316CREATE_ARG_FUNC_CLASS(std::log2,log2,POINT_LOG2)
317CREATE_ARG_FUNC_CLASS(std::log1p,log1p,POINT_LOG1P)
318CREATE_ARG_FUNC_CLASS(std::sqrt,sqrt,POINT_SQRT)
319CREATE_ARG_FUNC_CLASS(std::cbrt,cbrt,POINT_CBRT)
320CREATE_ARG_FUNC_CLASS(std::sin,sin,POINT_SIN)
321CREATE_ARG_FUNC_CLASS(std::cos,cos,POINT_COS)
322CREATE_ARG_FUNC_CLASS(std::tan,tan,POINT_TAN)
323CREATE_ARG_FUNC_CLASS(std::asin,asin,POINT_ASIN)
324CREATE_ARG_FUNC_CLASS(std::acos,acos,POINT_ACOS)
325CREATE_ARG_FUNC_CLASS(std::atan,atan,POINT_ATAN)
326CREATE_ARG_FUNC_CLASS(std::sinh,sinh,POINT_SINH)
327CREATE_ARG_FUNC_CLASS(std::cosh,cosh,POINT_COSH)
328CREATE_ARG_FUNC_CLASS(std::tanh,tanh,POINT_TANH)
329CREATE_ARG_FUNC_CLASS(std::asinh,asinh,POINT_ASINH)
330CREATE_ARG_FUNC_CLASS(std::acosh,acosh,POINT_ACOSH)
331CREATE_ARG_FUNC_CLASS(std::atanh,atanh,POINT_ATANH)
332CREATE_ARG_FUNC_CLASS(std::erf,erf,POINT_ERF)
333CREATE_ARG_FUNC_CLASS(std::erfc,erfc,POINT_ERFC)
334CREATE_ARG_FUNC_CLASS(std::tgamma,tgamma,POINT_TGAMMA)
335CREATE_ARG_FUNC_CLASS(std::lgamma,lgamma,POINT_LGAMMA)
336CREATE_ARG_FUNC_CLASS(std::ceil,ceil,POINT_CEIL)
337CREATE_ARG_FUNC_CLASS(std::floor,floor,POINT_FLOOR)
338CREATE_ARG_FUNC_CLASS(std::trunc,trunc,POINT_TRUNC)
339CREATE_ARG_FUNC_CLASS(std::round,round,POINT_ROUND)
340CREATE_ARG_FUNC_CLASS(std::nearbyint,nearbyint,POINT_NEARBYINT)
341CREATE_ARG_FUNC_CLASS(std::rint,rint,POINT_RINT)
352template<
typename orig,
typename exp1,
typename exp2,
unsigned int op1>
370__device__ __host__ T norm(T d)
382template<
typename T,
typename vmpl>
404template<
unsigned int dim,
typename T>
422template<
unsigned int dim,
typename T>
441template<
typename orig,
typename exp1,
typename exp2,
unsigned int op1>
458template <
typename T>__device__ __host__ T norm2(T d)
471template<
unsigned int dim,
typename T>
489template<
unsigned int dim,
typename T>
503template <
typename T,
typename P> __device__ __host__
auto distance(T exp1,
P exp2) ->
decltype(norm(exp1 - exp2))
505 return norm(exp1 - exp2);
519template<
typename orig,
typename exp1,
typename exp2,
unsigned int op1>
536template <
typename T>__device__ __host__ T norm_inf(T d)
549template<
unsigned int dim,
typename T>
567template<
unsigned int dim,
typename T>
581template <
typename T,
typename P> __device__ __host__
auto distance_inf(T exp1,
P exp2) ->
decltype(norm_inf(exp1 - exp2))
583 return norm_inf(exp1 - exp2);
589CREATE_ARG_FUNC(std::abs,abs,POINT_ABS)
590CREATE_ARG_FUNC(std::exp,exp,POINT_EXP)
591CREATE_ARG_FUNC(std::exp2,exp2,POINT_EXP2)
592CREATE_ARG_FUNC(std::expm1,expm1,POINT_EXPM1)
593CREATE_ARG_FUNC(std::log,log,POINT_LOG)
594CREATE_ARG_FUNC(std::log10,log10,POINT_LOG10)
595CREATE_ARG_FUNC(std::log2,log2,POINT_LOG2)
596CREATE_ARG_FUNC(std::log1p,log1p,POINT_LOG1P)
597CREATE_ARG_FUNC(std::sqrt,sqrt,POINT_SQRT)
598CREATE_ARG_FUNC(std::cbrt,cbrt,POINT_CBRT)
599CREATE_ARG_FUNC(std::sin,sin,POINT_SIN)
600CREATE_ARG_FUNC(std::cos,cos,POINT_COS)
601CREATE_ARG_FUNC(std::tan,tan,POINT_TAN)
602CREATE_ARG_FUNC(std::asin,asin,POINT_ASIN)
603CREATE_ARG_FUNC(std::acos,acos,POINT_ACOS)
604CREATE_ARG_FUNC(std::atan,atan,POINT_ATAN)
605CREATE_ARG_FUNC(std::sinh,sinh,POINT_SINH)
606CREATE_ARG_FUNC(std::cosh,cosh,POINT_COSH)
607CREATE_ARG_FUNC(std::tanh,tanh,POINT_TANH)
608CREATE_ARG_FUNC(std::asinh,asinh,POINT_ASINH)
609CREATE_ARG_FUNC(std::acosh,acosh,POINT_ACOSH)
610CREATE_ARG_FUNC(std::atanh,atanh,POINT_ATANH)
611CREATE_ARG_FUNC(std::erf,erf,POINT_ERF)
612CREATE_ARG_FUNC(std::erfc,erfc,POINT_ERFC)
613CREATE_ARG_FUNC(std::tgamma,tgamma,POINT_TGAMMA)
614CREATE_ARG_FUNC(std::lgamma,lgamma,POINT_LGAMMA)
615CREATE_ARG_FUNC(std::ceil,ceil,POINT_CEIL)
616CREATE_ARG_FUNC(std::floor,floor,POINT_FLOOR)
617CREATE_ARG_FUNC(std::trunc,trunc,POINT_TRUNC)
618CREATE_ARG_FUNC(std::round,round,POINT_ROUND)
619CREATE_ARG_FUNC(std::nearbyint,nearbyint,POINT_NEARBYINT)
620CREATE_ARG_FUNC(std::rint,rint,POINT_RINT)
Test structure used for several test.
This class implement the point shape in an N-dimensional space.
int is_expression
indicate that this class encapsulate an expression
int has_init
indicate that init must be called before value
std::remove_const< typenameorig::coord_type >::type scal
result of the expression
__device__ __host__ void init() const
This function must be called before value.
__device__ __host__ point_expression_op(const exp1 &o1)
constructor from an expression
__device__ __host__ r_type value(size_t k) const
Evaluate the expression.
orig::coord_type return_type
return type of the expression
int is_expression
indicate that this class encapsulate an expression
orig orig_type
Origin type.
int has_init
indicate that init must be called before value
__device__ __host__ void init() const
This function must be called before value.
__device__ __host__ r_type value(size_t k) const
Evaluate the expression.
orig::coord_type return_type
return type of the expression
std::remove_const< typenameorig::coord_type >::type scal
Scalar value.
__device__ __host__ point_expression_op(const exp1 &o1)
Constructor from expression.
int is_expression
indicate that this class encapsulate an expression
orig orig_type
Origin type.
std::remove_const< typenameorig::coord_type >::type scal
Scalar value.
int has_init
indicate that init must be called before value
__device__ __host__ r_type value(size_t k) const
Evaluate the expression.
orig::coord_type return_type
return type of the expression
__device__ __host__ point_expression_op(const exp1 &o1)
Constructor from expression.
__device__ __host__ void init() const
This function must be called before value.
Unknown operation specialization.
Main class that encapsulate a constant number used in a point expression.