OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
Point_operators.hpp
1 /*
2  * Point_operators.hpp
3  *
4  * Created on: Jun 14, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_SPACE_SHAPE_POINT_OPERATORS_HPP_
9 #define OPENFPM_DATA_SRC_SPACE_SHAPE_POINT_OPERATORS_HPP_
10 
11 template<unsigned int dim ,typename T> class Point;
12 
13 #define POINT_SUM 1
14 #define POINT_SUB 2
15 #define POINT_MUL 3
16 #define POINT_DIV 4
17 #define POINT_MUL_POINT 5
18 #define POINT_NORM 6
19 #define POINT_NORM2 7
20 
21 // Functions
22 
23 #define POINT_ABS 8
24 #define POINT_EXP 9
25 #define POINT_EXP2 10
26 #define POINT_EXPM1 11
27 #define POINT_LOG 12
28 #define POINT_LOG10 13
29 #define POINT_LOG2 14
30 #define POINT_LOG1P 15
31 #define POINT_SQRT 17
32 #define POINT_CBRT 18
33 #define POINT_SIN 19
34 #define POINT_COS 20
35 #define POINT_TAN 21
36 #define POINT_ASIN 22
37 #define POINT_ACOS 23
38 #define POINT_ATAN 24
39 #define POINT_SINH 25
40 #define POINT_COSH 26
41 #define POINT_TANH 27
42 #define POINT_ASINH 28
43 #define POINT_ACOSH 29
44 #define POINT_ATANH 30
45 #define POINT_ERF 31
46 #define POINT_ERFC 32
47 #define POINT_TGAMMA 33
48 #define POINT_LGAMMA 34
49 #define POINT_CEIL 35
50 #define POINT_FLOOR 36
51 #define POINT_TRUNC 37
52 #define POINT_ROUND 38
53 #define POINT_NEARBYINT 39
54 #define POINT_RINT 40
55 #define POINT_SUB_UNI 41
56 
57 constexpr unsigned int max_expr(unsigned int dim1, unsigned int dim2)
58 {
59  return (dim1 > dim2)?dim1:dim2;
60 }
61 
71 template <unsigned int op1_dim, unsigned int op2_dim, unsigned int op>
72 struct r_type_dim
73 {
75  enum
76  {
77  value = max_expr(op1_dim,op2_dim),
78  };
79 };
80 
82 template <>
83 struct r_type_dim<1,1,POINT_SUM>
84 {
86  enum
87  {
88  value = 1,
89  };
90 };
91 
93 template <>
94 struct r_type_dim<1,1,POINT_SUB>
95 {
97  enum
98  {
99  value = 1,
100  };
101 };
102 
104 template <unsigned int op1_dim, unsigned int op2_dim>
105 struct r_type_dim<op1_dim,op2_dim,POINT_MUL_POINT>
106 {
108  enum
109  {
110  value = 1,
111  };
112 };
113 
115 template <>
116 struct r_type_dim<1,1,POINT_MUL>
117 {
119  enum
120  {
121  value = 1,
122  };
123 };
124 
126 template <>
127 struct r_type_dim<1,1,POINT_DIV>
128 {
130  enum
131  {
132  value = 1,
133  };
134 };
135 
142 template <unsigned int r, typename orig>
143 struct r_type_p
144 {
146  typedef orig type;
147 };
148 
154 template <typename orig>
155 struct r_type_p<1,orig>
156 {
158  typedef typename orig::coord_type type;
159 };
160 
161 
166 template<typename T>
168 {
170  T d;
171 
172 public:
173 
175  typedef int has_init;
176 
178  typedef int is_expression;
179 
181  static const unsigned int nvals = 1;
182 
188  inline point_expression(T & d)
189  :d(d)
190  {}
191 
197  inline void init() const
198  {
199  }
200 
208  inline T value(const size_t k) const
209  {
210  return d;
211  }
212 };
213 
214 
215 
224 template <typename orig, typename exp1, typename exp2, unsigned int op>
226 {
227 
228 };
229 
237 template <typename orig, typename exp1, typename exp2>
238 class point_expression_op<orig,exp1,exp2,POINT_SUM>
239 {
241  const exp1 o1;
243  const exp2 o2;
244 
245 public:
246 
248  typedef orig orig_type;
249 
251  typedef int is_expression;
252 
254  typedef int has_init;
255 
258 
260  static const unsigned int nvals = r_type_dim<exp1::nvals,exp2::nvals,POINT_SUM>::value;
261 
268  inline point_expression_op(const exp1 & o1, const exp2 & o2)
269  :o1(o1),o2(o2)
270  {}
271 
277  inline void init() const
278  {
279  o1.init();
280  o2.init();
281  }
282 
290  template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const
291  {
292  return o1.value(k) + o2.value(k);
293  }
294 
299  template<typename T, typename test=typename boost::disable_if_c< std::is_same<T,orig>::value || exp1::nvals != 1 || exp2::nvals != 1 >::type > inline operator T() const
300  {
301  init();
302  return o1.value(0) + o2.value(0);
303  }
304 };
305 
312 template <typename orig,typename exp1, typename exp2>
313 class point_expression_op<orig, exp1,exp2,POINT_SUB>
314 {
316  const exp1 o1;
318  const exp2 o2;
319 
320 public:
321 
323  typedef orig orig_type;
324 
326  typedef int has_init;
327 
329  typedef int is_expression;
330 
332  typedef orig return_type;
333 
335  static const unsigned int nvals = r_type_dim<exp1::nvals,exp2::nvals,POINT_SUB>::value;
336 
343  inline point_expression_op(const exp1 & o1, const exp2 & o2)
344  :o1(o1),o2(o2)
345  {}
346 
352  inline void init() const
353  {
354  o1.init();
355  o2.init();
356  }
357 
365  template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const
366  {
367  return o1.value(k) - o2.value(k);
368  }
369 
374  template<typename T, typename test=typename boost::disable_if_c< std::is_same<T,orig>::value || exp1::nvals != 1 || exp2::nvals != 1 >::type > operator T() const
375  {
376  init();
377  return o1.value(0) - o2.value(0);
378  }
379 };
380 
388 template <typename orig, typename exp1, typename exp2>
389 class point_expression_op<orig,exp1,exp2, POINT_SUB_UNI >
390 {
392  const exp1 o1;
393 
395  mutable typename orig::coord_type scal;
396 
397 public:
398 
400  typedef orig orig_type;
401 
403  typedef int is_expression;
404 
406  typedef int has_init;
407 
409  typedef typename orig::coord_type return_type;
410 
412  static const unsigned int nvals = exp1::nvals;
413 
419  inline point_expression_op(const exp1 & o1)
420  :o1(o1),scal(0.0)
421  {}
422 
424  inline void init() const
425  {
426  o1.init();
427  }
428 
436  template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const
437  {
438  return -(o1.value(k));
439  }
440 
442  template <typename T, typename check = typename std::enable_if<!std::is_same<T,orig>::value >::type >operator T() const
443  {
444  init();
445  return -(o1.value(0));
446  }
447 };
448 
449 
458 template <typename orig, typename exp1, typename exp2>
459 class point_expression_op<orig,exp1,exp2,POINT_MUL_POINT>
460 {
462  const exp1 o1;
464  const exp2 o2;
465 
467  mutable typename std::remove_const<typename orig::coord_type>::type scal;
468 
469 public:
470 
472  typedef orig orig_type;
473 
475  typedef int has_init;
476 
478  typedef int is_expression;
479 
481  typedef typename orig::coord_type return_type;
482 
484  static const unsigned int nvals = 1;
485 
492  inline point_expression_op(const exp1 & o1, const exp2 & o2)
493  :o1(o1),o2(o2),scal(0.0)
494  {}
495 
501  inline void init() const
502  {
503  o1.init();
504  o2.init();
505 
506  for (size_t i = 0 ; i < orig::dims ; i++)
507  scal += o1.value(i) * o2.value(i);
508  }
509 
517  template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const
518  {
519  return scal;
520  }
521 
523  template<typename T, typename test=typename boost::disable_if_c< std::is_same<T,orig>::value >::type > operator T() const
524  {
525  init();
526  return scal;
527  }
528 };
529 
530 
538 template <typename orig, typename exp1, typename exp2>
539 class point_expression_op<orig,exp1,exp2,POINT_MUL>
540 {
542  const exp1 o1;
544  const exp2 o2;
545 
546 public:
547 
549  typedef orig orig_type;
550 
552  typedef int has_init;
553 
555  typedef int is_expression;
556 
558  typedef orig return_type;
559 
561  static const unsigned int nvals = r_type_dim<exp1::nvals,exp2::nvals,POINT_MUL>::value;
562 
569  inline point_expression_op(const exp1 & o1, const exp2 & o2)
570  :o1(o1),o2(o2)
571  {}
572 
578  inline void init() const
579  {
580  o1.init();
581  o2.init();
582  }
583 
589  template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const
590  {
591  return o1.value(k) * o2.value(k);
592  }
593 
598  template<typename T, typename test=typename boost::disable_if_c< std::is_same<T,orig>::value || exp1::nvals != 1 || exp2::nvals != 1 >::type > operator T() const
599  {
600  init();
601  return o1.value(0) * o2.value(0);
602  }
603 
604 };
605 
612 template <typename orig, typename exp1, typename exp2>
613 class point_expression_op<orig,exp1,exp2,POINT_DIV>
614 {
616  const exp1 o1;
618  const exp2 o2;
619 
620 public:
621 
623  typedef orig orig_type;
624 
626  typedef int is_expression;
627 
629  typedef int has_init;
630 
632  typedef orig return_type;
633 
635  static const unsigned int nvals = r_type_dim<exp1::nvals,exp2::nvals,POINT_DIV>::value;
636 
643  inline point_expression_op(const exp1 & o1, const exp2 & o2)
644  :o1(o1),o2(o2)
645  {}
646 
652  inline void init() const
653  {
654  o1.init();
655  o2.init();
656  }
657 
665  template<typename r_type=typename std::remove_reference<decltype(o1.value(0))>::type > inline r_type value(size_t k) const
666  {
667  return o1.value(k) / o2.value(k);
668  }
669 
670 
675  template<typename T, typename test=typename boost::disable_if_c< std::is_same<T,orig>::value || exp1::nvals != 1 || exp2::nvals != 1 >::type > operator T() const
676  {
677  init();
678  return o1.value(0) / o2.value(0);
679  }
680 };
681 
689 template<unsigned int dim, typename T> point_expression<T[dim]> getExprL(T (& a)[dim])
690 {
691  return point_expression<T[dim]>(a);
692 }
693 
701 template<unsigned int dim, typename T> point_expression<const T[dim]> getExprR(T (& a)[dim])
702 {
704 }
705 
711 #define CREATE_POINT_OPERATOR(operator_name,OP_ID) \
712 \
713 \
714 template<unsigned int dim, typename T>\
715 inline point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<const T[dim]>,OP_ID>\
716 operator_name(const Point<dim,T> & va, const point_expression<const T[(unsigned int)dim]> & vb)\
717 {\
718  point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<const T[dim]>,OP_ID> exp_sum(va,vb);\
719 \
720  return exp_sum;\
721 }\
722 \
723 template<unsigned int dim, typename T>\
724 inline point_expression_op<Point<dim,T>,point_expression<const T[dim]>,Point<dim,T>,OP_ID>\
725 operator_name(const point_expression<const T[(unsigned int)dim]> & va, const Point<dim,T> & vb)\
726 {\
727  point_expression_op<Point<dim,T>,point_expression<const T[dim]>,Point<dim,T>,OP_ID> exp_sum(va,vb);\
728 \
729  return exp_sum;\
730 }\
731 \
732 template<unsigned int dim, typename T>\
733 inline point_expression_op<Point<dim,T>,point_expression<const T[dim]>,point_expression<double>,OP_ID>\
734 operator_name(const point_expression<const T[dim]> & va, double d)\
735 {\
736  point_expression_op<Point<dim,T>,point_expression<const T[dim]>,point_expression<double>,OP_ID> exp_sum(va,point_expression<double>(d));\
737 \
738  return exp_sum;\
739 }\
740 \
741 template<unsigned int dim, typename T>\
742 inline point_expression_op<Point<dim,T>,point_expression<double>,point_expression<const T[dim]>,OP_ID>\
743 operator_name(double d, const point_expression<const T[dim]> & va)\
744 {\
745  point_expression_op<Point<dim,T>,point_expression<double>,point_expression<const T[dim]>,OP_ID> exp_sum(point_expression<double>(d),va);\
746 \
747  return exp_sum;\
748 }\
749 \
750 template<unsigned int dim, typename T>\
751 inline point_expression_op<Point<dim,T>,point_expression<const T[dim]>,point_expression<const T[dim]>,OP_ID>\
752 operator_name(const point_expression<const T[dim]> & va, const point_expression<const T[dim]> & vb)\
753 {\
754  point_expression_op<Point<dim,T>,point_expression<const T[dim]>,point_expression<const T[dim]>,OP_ID> exp_sum(va,vb);\
755 \
756  return exp_sum;\
757 }\
758 \
759 template<unsigned int dim, typename T>\
760 inline point_expression_op<Point<dim,T>,point_expression<const T[dim]>,point_expression<T[dim]>,OP_ID>\
761 operator_name(const point_expression<const T[dim]> & va, const point_expression<T[dim]> & vb)\
762 {\
763  point_expression_op<Point<dim,T>,point_expression<const T[dim]>,point_expression<T[dim]>,OP_ID> exp_sum(va,vb);\
764 \
765  return exp_sum;\
766 }\
767 \
768 template<unsigned int dim, typename T>\
769 inline point_expression_op<Point<dim,T>,point_expression<T[dim]>,point_expression<const T[dim]>,OP_ID>\
770 operator_name(const point_expression<T[dim]> & va, const point_expression<const T[dim]> & vb)\
771 {\
772  point_expression_op<Point<dim,T>,point_expression<T[dim]>,point_expression<const T[dim]>,OP_ID> exp_sum(va,vb);\
773 \
774  return exp_sum;\
775 }\
776 \
777 template<typename orig, typename exp1 , typename exp2, unsigned int op1, unsigned int dim, typename T>\
778 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T[dim]>,OP_ID>\
779 operator_name(const point_expression_op<orig,exp1,exp2,op1> & va, const point_expression<T[dim]> & vb)\
780 {\
781  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T[dim]>,OP_ID> exp_sum(va,vb);\
782 \
783  return exp_sum;\
784 }\
785 \
786 template<typename orig, typename exp1 , typename exp2, unsigned int op1, unsigned int dim, typename T>\
787 inline point_expression_op<orig,point_expression<T[dim]>,point_expression_op<orig,exp1,exp2,op1>,OP_ID>\
788 operator_name(const point_expression<T[dim]> & va, const point_expression_op<orig,exp1,exp2,op1> & vb)\
789 {\
790  point_expression_op<orig,point_expression<T[dim]>,point_expression_op<orig,exp1,exp2,op1>,OP_ID> exp_sum(va,vb);\
791 \
792  return exp_sum;\
793 }\
794 \
795 \
796 template<unsigned int dim, typename T>\
797 inline point_expression_op<Point<dim,T>,Point<dim,T>,Point<dim,T>,OP_ID>\
798 operator_name(const Point<dim,T> & va, const Point<dim,T> & vb)\
799 {\
800  point_expression_op<Point<dim,T>,Point<dim,T>,Point<dim,T>,OP_ID> exp_sum(va,vb);\
801 \
802  return exp_sum;\
803 }\
804 \
805 template<typename orig, typename exp1 , typename exp2, unsigned int op1, unsigned int dim, typename T>\
806 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,OP_ID>\
807 operator_name(const point_expression_op<orig,exp1,exp2,op1> & va, const Point<dim,T> & vb)\
808 {\
809  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,OP_ID> exp_sum(va,vb);\
810 \
811  return exp_sum;\
812 }\
813 \
814 template<typename orig,typename exp1 , typename exp2, unsigned int op1, unsigned int dim, typename T>\
815 inline point_expression_op<Point<dim,T>,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,OP_ID>\
816 operator_name(const Point<dim,T> & va, const point_expression_op<orig,exp1,exp2,op1> & vb)\
817 {\
818  point_expression_op<Point<dim,T>,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,OP_ID> exp_sum(va,vb);\
819 \
820  return exp_sum;\
821 }\
822 \
823 template<typename orig, typename exp1 , typename exp2, unsigned int op1, typename T>\
824 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T>,OP_ID>\
825 operator_name(const point_expression_op<orig,exp1,exp2,op1> & va, T d)\
826 {\
827  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T>,OP_ID> exp_sum(va,d);\
828 \
829  return exp_sum;\
830 }\
831 \
832 template<typename orig,typename exp1 , typename exp2, unsigned int op1, typename T>\
833 inline point_expression_op<orig,point_expression<T>,point_expression_op<orig,exp1,exp2,op1>,OP_ID>\
834 operator_name(T d, const point_expression_op<orig,exp1,exp2,op1> & vb)\
835 {\
836  point_expression_op<orig,point_expression<T>,point_expression_op<orig,exp1,exp2,op1>,OP_ID> exp_sum(d,vb);\
837 \
838  return exp_sum;\
839 }\
840 \
841 template<typename orig,typename exp1 , typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>\
842 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,OP_ID>\
843 operator_name(const point_expression_op<orig,exp1,exp2,op1> & va, const point_expression_op<orig,exp3,exp4,op2> & vb)\
844 {\
845  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,OP_ID> exp_sum(va,vb);\
846 \
847  return exp_sum;\
848 }\
849 \
850 template<unsigned int dim , typename T, typename check=typename std::enable_if< !std::is_same<T,double>::value >::type >\
851 inline point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<T>,OP_ID>\
852 operator_name(const Point<dim,T> & va, T d)\
853 {\
854  point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<T>,OP_ID> exp_sum(va,point_expression<T>(d));\
855 \
856  return exp_sum;\
857 }\
858 \
859 template<unsigned int dim , typename T>\
860 inline point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<double>,OP_ID>\
861 operator_name(const Point<dim,T> & va, double d)\
862 {\
863  point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<double>,OP_ID> exp_sum(va,point_expression<double>(d));\
864 \
865  return exp_sum;\
866 }\
867 \
868 template<unsigned int dim , typename T, typename check=typename std::enable_if< !std::is_same<T,double>::value >::type >\
869 inline point_expression_op<Point<dim,T>,point_expression<T>,Point<dim,T>,OP_ID>\
870 operator_name(T d, const Point<dim,T> & vb)\
871 {\
872  point_expression_op<Point<dim,T>,point_expression<T>,Point<dim,T>,OP_ID> exp_sum(point_expression<T>(d),vb);\
873 \
874  return exp_sum;\
875 }\
876 \
877 template<unsigned int dim, typename T, typename check=typename std::enable_if< !std::is_same<T,double>::value >::type>\
878 inline point_expression_op<Point<dim,T>,point_expression<T[dim]>,Point<dim,T>,OP_ID>\
879 operator_name(T (& d)[dim], const Point<dim,T> & vb)\
880 {\
881  point_expression_op<Point<dim,T>,point_expression<T[dim]>,Point<dim,T>,OP_ID> exp_sum(point_expression<T[dim]>(d),vb);\
882 \
883  return exp_sum;\
884 }\
885 \
886 template<unsigned int dim , typename T>\
887 inline point_expression_op<Point<dim,T>,point_expression<double>,Point<dim,T>,OP_ID>\
888 operator_name(double d, const Point<dim,T> & vb)\
889 {\
890  point_expression_op<Point<dim,T>,point_expression<double>,Point<dim,T>,OP_ID> exp_sum(point_expression<double>(d),vb);\
891 \
892  return exp_sum;\
893 }\
894 \
895 template<typename orig, typename exp1 , typename exp2, unsigned int op1, typename T, typename check=typename std::enable_if< !std::is_same<T,double>::value >::type >\
896 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T>,OP_ID>\
897 operator_name(const point_expression_op<orig,exp1,exp2,op1> & va, T d)\
898 {\
899  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T>,OP_ID> exp_sum(va,point_expression<T>(d));\
900 \
901  return exp_sum;\
902 }\
903 \
904 template<typename orig, typename exp1 , typename exp2, unsigned int op1, typename T>\
905 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<double>,OP_ID>\
906 operator_name(const point_expression_op<orig,exp1,exp2,op1> & va, double d)\
907 {\
908  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<double>,OP_ID> exp_sum(va,point_expression<double>(d));\
909 \
910  return exp_sum;\
911 }
912 
913 
914 CREATE_POINT_OPERATOR(operator+,POINT_SUM)
915 CREATE_POINT_OPERATOR(operator-,POINT_SUB)
916 CREATE_POINT_OPERATOR(operator/,POINT_DIV)
917 
918 /* \brief sum two points expression
919  *
920  * \param va point expression one
921  * \param vb point expression two
922  *
923  * \return an object that encapsulate the expression
924  *
925  */
926 template<typename orig, typename exp1 , typename exp2, unsigned int op1, typename T, typename check=typename std::enable_if< ! std::is_same<T,orig>::value >::type >
927 inline T &
928 operator+=(T & d, const point_expression_op<orig,exp1,exp2,op1> & va)
929 {
930  va.init();
931  d += va.value(0);
932 
933  return d;
934 }
935 
936 
937 
938 /* \brief sum two points expression
939  *
940  * \param va point expression one
941  * \param vb point expression two
942  *
943  * \return an object that encapsulate the expression
944  *
945  */
946 template<typename orig, typename exp1 , typename exp2, unsigned int op1, typename T>
947 inline T &
948 operator+=(orig & d, const point_expression_op<orig,exp1,exp2,op1> & va)
949 {
950  va.init();
951 
952  d = d + va;
953 
954  return d;
955 }
956 
957 /* \brief minus points expression
958  *
959  * \param va point expression one
960  *
961  * \return an object that encapsulate the expression
962  *
963  */
964 template<typename orig, typename exp1, typename exp2, unsigned int op1>
966 operator-(const point_expression_op<orig,exp1,exp2,op1> & va)
967 {
968  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,void,POINT_SUB_UNI> exp_sum(va);
969 
970  return exp_sum;
971 }
972 
973 /* \brief minus points expression
974  *
975  * \param va point expression one
976  *
977  * \return an object that encapsulate the expression
978  *
979  */
980 template<unsigned int dim, typename T>
981 inline point_expression_op<Point<dim,T>,Point<dim,T>,void, POINT_SUB_UNI >
982 operator-(const Point<dim,T> & va)
983 {
984  point_expression_op<Point<dim,T>,Point<dim,T>,void,POINT_SUB_UNI> exp_sum(va);
985 
986  return exp_sum;
987 }
988 
989 
992 
993 
994 template<unsigned int dim, typename T>
995 inline point_expression_op<Point<dim,T>,point_expression<T[dim]>,point_expression<double>,POINT_MUL>
996 operator*(const point_expression<T[dim]> & va, double d)
997 {
998  point_expression_op<Point<dim,T>,point_expression<T[dim]>,point_expression<double>,POINT_MUL> exp_sum(va,point_expression<double>(d));
999 
1000  return exp_sum;
1001 }
1002 
1003 template<unsigned int dim, typename T>
1004 inline point_expression_op<Point<dim,T>,point_expression<double>,point_expression<T[dim]>,POINT_MUL>
1005 operator*(double d, const point_expression<T[dim]> & va)
1006 {
1007  point_expression_op<Point<dim,T>,point_expression<double>,point_expression<T[dim]>,POINT_MUL> exp_sum(point_expression<double>(d),va);
1008 
1009  return exp_sum;
1010 }
1011 
1012 template<unsigned int dim, typename T>
1013 inline point_expression_op<Point<dim,T>,point_expression<T[dim]>,point_expression<T[dim]>,POINT_MUL_POINT>
1014 operator*(const point_expression<T[dim]> & va, const point_expression<T[dim]> & vb)
1015 {
1016  point_expression_op<Point<dim,T>,point_expression<T[dim]>,point_expression<T[dim]>,POINT_MUL_POINT> exp_sum(va,vb);
1017 
1018  return exp_sum;
1019 }
1020 
1021 template<unsigned int dim, typename T, typename check=typename std::enable_if< !std::is_same<T,double>::value >::type>
1022 inline point_expression_op<Point<dim,T>,point_expression<T>,Point<dim,T>,POINT_MUL>
1023 operator*(T d, const Point<dim,T> & vb)
1024 {
1025  point_expression_op<Point<dim,T>,point_expression<T>,Point<dim,T>,POINT_MUL> exp_sum(point_expression<T>(d),vb);
1026 
1027  return exp_sum;
1028 }
1029 
1030 template<typename orig, typename exp1 , typename exp2, unsigned int op1, unsigned int dim, typename T>
1031 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T[dim]>,POINT_MUL_POINT>
1032 operator*(const point_expression_op<orig,exp1,exp2,op1> & va, const point_expression<T[dim]> & vb)
1033 {
1034  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T[dim]>,POINT_MUL_POINT> exp_sum(va,vb);
1035 
1036  return exp_sum;
1037 }
1038 
1039 template<typename orig, typename exp1 , typename exp2, unsigned int op1, unsigned int dim, typename T>
1041 operator*(const point_expression<T[dim]> & va, const point_expression_op<orig,exp1,exp2,op1> & vb)
1042 {
1043  point_expression_op<orig,point_expression<T[dim]>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL_POINT> exp_sum(va,vb);
1044 
1045  return exp_sum;
1046 }
1047 
1048 /* \brief Multiply two points expression
1049  *
1050  * \param va vector expression one
1051  * \param vb vector expression two
1052  *
1053  * \return an object that encapsulate the expression
1054  *
1055  */
1056 template<unsigned int dim, typename T>
1057 inline point_expression_op<Point<dim,T>,point_expression<double>,Point<dim,T>,POINT_MUL>
1058 operator*(double d, const Point<dim,T> & vb)
1059 {
1060  point_expression_op<Point<dim,T>,point_expression<double>,Point<dim,T>,POINT_MUL> exp_sum(point_expression<double>(d),vb);
1061 
1062  return exp_sum;
1063 }
1064 
1065 /* \brief Multiply two points expression
1066  *
1067  * \param va point expression one
1068  * \param vb point expression two
1069  *
1070  * \return an object that encapsulate the expression
1071  *
1072  */
1073 template<unsigned int dim, typename T, typename check=typename std::enable_if< !std::is_same<T,double>::value >::type >
1074 inline point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<T>,POINT_MUL>
1075 operator*(const Point<dim,T> & va, T d)
1076 {
1077  point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<T>,POINT_MUL> exp_sum(va,point_expression<T>(d));
1078 
1079  return exp_sum;
1080 }
1081 
1082 /* \brief Multiply two points expression
1083  *
1084  * \param va point expression one
1085  * \param vb point expression two
1086  *
1087  * \return an object that encapsulate the expression
1088  *
1089  */
1090 template<unsigned int dim, typename T>
1091 inline point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<double>,POINT_MUL>
1092 operator*(const Point<dim,T> & va, double d)
1093 {
1094  point_expression_op<Point<dim,T>,Point<dim,T>,point_expression<double>,POINT_MUL> exp_sum(va,point_expression<double>(d));
1095 
1096  return exp_sum;
1097 }
1098 
1099 /* \brief Multiply two points expression
1100  *
1101  * \param va point expression one
1102  * \param vb point expression two
1103  *
1104  * \return an object that encapsulate the expression
1105  *
1106  */
1107 template<unsigned int dim, typename T>
1108 inline point_expression_op<Point<dim,T>,Point<dim,T>,Point<dim,T>,POINT_MUL_POINT>
1109 operator*(const Point<dim,T> & va, const Point<dim,T> & vb)
1110 {
1111  point_expression_op<Point<dim,T>,Point<dim,T>,Point<dim,T>,POINT_MUL_POINT> exp_sum(va,vb);
1112 
1113  return exp_sum;
1114 }
1115 
1116 /* \brief Multiply two points expression
1117  *
1118  * \param va point expression one
1119  * \param vb point expression two
1120  *
1121  * \return an object that encapsulate the expression
1122  *
1123  */
1124 template<typename orig,
1125  unsigned int dim,
1126  typename T,
1127  typename exp1,
1128  typename exp2,
1129  unsigned int op1,
1130  typename sfinae = typename std::enable_if<point_expression_op<orig,exp1,exp2,op1>::nvals != 1>::type >
1131 inline point_expression_op<orig,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL_POINT>
1132 operator*(const Point<dim,T> & va, const point_expression_op<orig,exp1,exp2,op1> & vb)
1133 {
1134  point_expression_op<orig,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL_POINT> exp_sum(va,vb);
1135 
1136  return exp_sum;
1137 }
1138 
1139 /* \brief Multiply two points expression
1140  *
1141  * \param va point expression one
1142  * \param vb point expression two
1143  *
1144  * \return an object that encapsulate the expression
1145  *
1146  */
1147 template<typename orig,
1148  unsigned int dim,
1149  typename T,
1150  typename exp1,
1151  typename exp2,
1152  unsigned int op1,
1153  typename sfinae = typename std::enable_if<point_expression_op<orig,exp1,exp2,op1>::nvals == 1>::type >
1154 inline point_expression_op<orig,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL>
1155 operator*(const Point<dim,T> & va, const point_expression_op<orig,exp1,exp2,op1> & vb)
1156 {
1157  point_expression_op<orig,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL> exp_sum(va,vb);
1158 
1159  return exp_sum;
1160 }
1161 
1162 /* \brief Multiply two points expression
1163  *
1164  * \param va point expression one
1165  * \param vb point expression two
1166  *
1167  * \return an object that encapsulate the expression
1168  *
1169  */
1170 template<typename orig,
1171  unsigned int dim,
1172  typename T,
1173  typename exp1,
1174  typename exp2,
1175  unsigned int op1,
1176  typename sfinae = typename std::enable_if<point_expression_op<orig,exp1,exp2,op1>::nvals != 1>::type >
1177 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,POINT_MUL_POINT>
1178 operator*(const point_expression_op<orig,exp1,exp2,op1> & va, const Point<dim,T> & vb)
1179 {
1180  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,POINT_MUL_POINT> exp_sum(va,vb);
1181 
1182  return exp_sum;
1183 }
1184 
1185 /* \brief Multiply two points expression
1186  *
1187  * \param va point expression one
1188  * \param vb point expression two
1189  *
1190  * \return an object that encapsulate the expression
1191  *
1192  */
1193 template<typename orig,
1194  unsigned int dim,
1195  typename T,
1196  typename exp1,
1197  typename exp2,
1198  unsigned int op1,
1199  typename check = typename std::enable_if<point_expression_op<orig,exp1,exp2,op1>::nvals == 1>::type >
1200 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,POINT_MUL>
1201 operator*(const point_expression_op<orig,exp1,exp2,op1> & va, const Point<dim,T> & vb)
1202 {
1203  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,POINT_MUL> exp_sum(va,vb);
1204 
1205  return exp_sum;
1206 }
1207 
1208 /* \brief Multiply a point expression with a number
1209  *
1210  * \param d number
1211  * \param vb point expression
1212  *
1213  * \return an object that encapsulate the expression
1214  *
1215  */
1216 template<typename orig, typename T, typename exp1, typename exp2, unsigned int op1>
1217 inline point_expression_op<orig,point_expression<T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL>
1218 operator*(T d, const point_expression_op<orig,exp1,exp2,op1> & vb)
1219 {
1220  point_expression_op<orig,point_expression<T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL> exp_sum(point_expression<T>(d),vb);
1221 
1222  return exp_sum;
1223 }
1224 
1225 
1226 /* \brief Multiply two points expression
1227  *
1228  * \param va point expression one
1229  * \param d constant value
1230  *
1231  * \return an object that encapsulate the expression
1232  *
1233  */
1234 template<typename orig, typename exp1, typename exp2, unsigned int op1, typename T>
1235 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T>,POINT_MUL>
1236 operator*(const point_expression_op<orig,exp1,exp2,op1> & va, T d)
1237 {
1238  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression<T>,POINT_MUL> exp_sum(va,point_expression<T>(d));
1239 
1240  return exp_sum;
1241 }
1242 
1243 
1244 /* \brief Multiply two points expression
1245  *
1246  * \param va point expression one
1247  * \param vb point expression two
1248  *
1249  * \return an object that encapsulate the expression
1250  *
1251  */
1252 template<typename orig,
1253  typename exp1,
1254  typename exp2,
1255  unsigned int op1,
1256  typename exp3 ,
1257  typename exp4,
1258  unsigned int op2,
1259  typename check = typename std::enable_if<point_expression_op<orig,exp1,exp2,op1>::nvals != 1 && point_expression_op<orig,exp3,exp4,op2>::nvals != 1>::type >
1260 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,POINT_MUL_POINT>
1261 operator*(const point_expression_op<orig,exp1,exp2,op1> & va, const point_expression_op<orig,exp3,exp4,op2> & vb)
1262 {
1263  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,POINT_MUL_POINT> exp_sum(va,vb);
1264 
1265  return exp_sum;
1266 }
1267 
1268 /* \brief Multiply two points expression
1269  *
1270  * \param va point expression one
1271  * \param vb point expression two
1272  *
1273  * \return an object that encapsulate the expression
1274  *
1275  */
1276 template<typename orig,
1277  typename exp1,
1278  typename exp2,
1279  unsigned int op1,
1280  typename exp3 ,
1281  typename exp4,
1282  unsigned int op2,
1283  typename check = typename std::enable_if<point_expression_op<orig,exp1,exp2,op1>::nvals == 1 || point_expression_op<orig,exp3,exp4,op2>::nvals == 1 >::type >
1284 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,POINT_MUL>
1285 operator*(const point_expression_op<orig,exp1,exp2,op1> & va, const point_expression_op<orig,exp3,exp4,op2> & vb)
1286 {
1287  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,POINT_MUL> exp_sum(va,vb);
1288 
1289  return exp_sum;
1290 }
1291 
1293 
1294 /* \brief Multiply two points expression
1295  *
1296  * \param va point expression one
1297  * \param vb point expression two
1298  *
1299  * \return an object that encapsulate the expression
1300  *
1301  */
1302 template<unsigned int dim, typename T>
1303 inline point_expression_op<Point<dim,T>,Point<dim,T>,Point<dim,T>,POINT_MUL>
1304 pmul(const Point<dim,T> & va, const Point<dim,T> & vb)
1305 {
1306  point_expression_op<Point<dim,T>,Point<dim,T>,Point<dim,T>,POINT_MUL> exp_sum(va,vb);
1307 
1308  return exp_sum;
1309 }
1310 
1311 /* \brief Multiply two points expression
1312  *
1313  * \param va point expression one
1314  * \param vb point expression two
1315  *
1316  * \return an object that encapsulate the expression
1317  *
1318  */
1319 template<typename orig, unsigned int dim, typename T, typename exp1, typename exp2, unsigned int op1>
1320 inline point_expression_op<orig,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL>
1321 pmul(const Point<dim,T> & va, const point_expression_op<orig,exp1,exp2,op1> & vb)
1322 {
1323  point_expression_op<orig,Point<dim,T>,point_expression_op<orig,exp1,exp2,op1>,POINT_MUL> exp_sum(va,vb);
1324 
1325  return exp_sum;
1326 }
1327 
1328 /* \brief Multiply two points expression
1329  *
1330  * \param va point expression one
1331  * \param vb point expression two
1332  *
1333  * \return an object that encapsulate the expression
1334  *
1335  */
1336 template<typename orig,unsigned int dim, typename T, typename exp1, typename exp2, unsigned int op1>
1337 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,POINT_MUL>
1338 pmul(const point_expression_op<orig,exp1,exp2,op1> & va, const Point<dim,T> & vb)
1339 {
1340  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,Point<dim,T>,POINT_MUL> exp_sum(va,vb);
1341 
1342  return exp_sum;
1343 }
1344 
1345 /* \brief Multiply two points expression
1346  *
1347  * \param va point expression one
1348  * \param vb point expression two
1349  *
1350  * \return an object that encapsulate the expression
1351  *
1352  */
1353 template<typename orig, typename exp1, typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
1354 inline point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,POINT_MUL>
1355 pmul(const point_expression_op<orig,exp1,exp2,op1> & va, const point_expression_op<orig,exp3,exp4,op2> & vb)
1356 {
1357  point_expression_op<orig,point_expression_op<orig,exp1,exp2,op1>,point_expression_op<orig,exp3,exp4,op2>,POINT_MUL> exp_sum(va,vb);
1358 
1359  return exp_sum;
1360 }
1361 
1362 
1369 template<typename T, unsigned int dim>
1370 class point_expression<T[dim]>
1371 {
1373  T (& d)[dim];
1374 
1375 public:
1376 
1378  typedef int has_init;
1379 
1381  typedef int is_expression;
1382 
1384  static const unsigned int nvals = dim;
1385 
1391  inline point_expression(T (& d)[dim])
1392  :d(d)
1393  {
1394  }
1395 
1408  template<typename orig, typename exp1, typename exp2, unsigned int op> point_expression<T[dim]> & operator=(const point_expression_op<orig,exp1,exp2,op> & p_exp)
1409  {
1410  p_exp.init();
1411 
1412  for (size_t i = 0; i < dim ; i++)
1413  d[i] = p_exp.value(i);
1414 
1415  return *this;
1416  }
1417 
1423  inline void init() const
1424  {
1425  }
1426 
1436  inline T value(const size_t k) const
1437  {
1438  return d[k];
1439  }
1440 };
1441 
1442 
1449 template<typename T, unsigned int dim>
1450 class point_expression<const T[dim]>
1451 {
1453  const T (& d)[dim];
1454 
1455 public:
1456 
1458  typedef int has_init;
1459 
1461  typedef int is_expression;
1462 
1464  static const unsigned int nvals = dim;
1465 
1471  inline point_expression(const T (& d)[dim])
1472  :d(d)
1473  {
1474  }
1475 
1481  inline void init() const
1482  {
1483  }
1484 
1494  inline T value(const size_t k) const
1495  {
1496  return d[k];
1497  }
1498 };
1499 
1500 #include "Point_operators_functions.hpp"
1501 
1502 #endif /* OPENFPM_DATA_SRC_SPACE_SHAPE_POINT_OPERATORS_HPP_ */
void init() const
This function must be called before value.
int has_init
indicate that init must be called before value
int is_expression
indicate that this class encapsulate an expression
point_expression_op(const exp1 &o1, const exp2 &o2)
constructor from 2 expressions
T value(const size_t k) const
Evaluate the expression.
r_type value(size_t k) const
Evaluate the expression.
point_expression_op(const exp1 &o1, const exp2 &o2)
constructor from expression 1 and expression 2
r_type value(size_t k) const
Evaluate the expression.
It return the dimansionality of the operation given the dimensionality of the 2 operators.
Specialization for an array of dimension dim as expression.
int has_init
indicate that init must be called before value
point_expression_op(const exp1 &o1, const exp2 &o2)
Constructor from 2 point expressions.
int has_init
indicate that init must be called before value
int has_init
indicate that this class has an init function
orig::coord_type return_type
return type of the expression
point_expression(T &d)
constructor from a value
point_expression(const T(&d)[dim])
construct from an array of dimension dim
void init() const
This function must be called before value.
void init() const
This function must be called before value.
Unknown operation specialization.
orig::coord_type scal
scalar value produced by the expression
std::remove_const< typename orig::coord_type >::type scal
the expression produce a scalar
int has_init
indicate that init must be called before value
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Main class that encapsulate a constant number used in a point expression.
orig::coord_type type
meta-function return a scalar or the expression produce a scalar
point_expression_op(const exp1 &o1, const exp2 &o2)
constructor from 2 expression
point_expression< T[dim]> & operator=(const point_expression_op< orig, exp1, exp2, op > &p_exp)
Operator= for point expression.
int is_expression
indicate that this class encapsulate an expression
int has_init
indicate that init must be called before value
int is_expression
indicate that this class encapsulate an expression
point_expression_op(const exp1 &o1, const exp2 &o2)
constructor from 2 expressions
static const unsigned int nvals
this operation produce a vector as result of size dims
orig return_type
return type of the expression
Return type of the expression.
void init() const
This function must be called before value.
r_type value(size_t k) const
Evaluate the expression.
void init() const
This function must be called before value.
orig::coord_type return_type
return type of the expression evaluation
void init() const
initialize the the expression
r_type value(size_t k) const
evaluate the expression
void init() const
This function must be called before value.
int is_expression
indicate that this class encapsulate an expression
int is_expression
indicate that this class encapsulate an expression
Specialization for a const array of dimension dim.
int is_expression
indicate that this class encapsulate an expression
r_type_p< r_type_dim< exp1::nvals, exp2::nvals, POINT_SUM >::value, orig >::type return_type
return type of the expression
void init() const
This function must be called before value.
orig return_type
return type of the expression
point_expression(T(&d)[dim])
constructor from an array
int has_init
indicate that init must be called before value
T value(const size_t k) const
Evaluate the expression at coordinate k.
r_type value(size_t k) const
Evaluate the expression at coordinate k.
r_type value(size_t k) const
Evaluate the expression at coordinate k.
orig orig_type
original type of the point expression
int has_init
indicate that init must be called before value
orig return_type
return type of the expression
T value(const size_t k) const
Evaluate the expression at coordinate k.
int is_expression
indicate that this class encapsulate an expression
int has_init
indicate that init must be called before value
int is_expression
indicate that this class encapsulate an expression
orig type
meta-function return orig or the expression produce a vector
void init() const
This function must be called before value.