C++ mpi module for stochmagnet_main Package
OMP_PtrArray.h
1 #ifndef OMP_PtrArray_H
2 #define OMP_PtrArray_H
3 
4 //base class header
5 #include "CORE_Object.h"
6 
7 //exception header
8 #include "CORE_Exception.h"
9 
10 //temmplate base class for array header
11 #include "CORE_PtrArray.h"
12 
13 
14 //openmp header
15 #include "openMP.h"
16 
21 template<class T>
22 class OMP_PtrArray : public CORE_PtrArray<T,OMP_PtrArray<T>> {
23 
24 private:
25  //This class type
26  typedef OMP_PtrArray<T> Self;
27 
28 public:
29 
30 
31 
35  }
36 
37 
41  explicit OMP_PtrArray(const tIndex& n) {
42  this->setSize(n);
43  }
44 
45 
46 
47 
48 
49  // DESTRUCTORS
52  virtual ~OMP_PtrArray() {
53  }
54 
55 
56 
57 
58  //MEMORY
59  //=====
60 public:
68  virtual tMemSize getMemorySize() const override {
69  return sizeof(*this)+this->getContentsMemorySize();
70  }
71 
72 
73  // ----------------
74  // New constructors
75  // ----------------
79  static inline CORE_UniquePointer<Self> New() {
80  return CORE_UniquePointer<Self>(new Self(),
82  };
83 
84 public:
85 
86 
87  //accessor operators
88  //====================
89 
90 
91  //accessor iterator
92  //=================
93 
94 
95  //accessor methods
96  //=================
97 
98  //assignement operator
99  //====================
100 
101 public:
105  inline Self& operator=(const T& v) {
106  initialize(v);
107  return *this;
108  }
112  inline Self& operator=(std::initializer_list<T>&& values) {
113  copy(values);
114  return *this;
115  }
119  inline Self& operator=(const std::initializer_list<T>& values) {
120  copy(values);
121  return *this;
122  }
123 
128  template<size_t N>
129  inline Self& operator=(const std::array<T,N>& values) {
130  copy(values);
131  return *this;
132 
133  }
134 
138  inline Self& operator=(const std::valarray<T>& values) {
139  copy(values);
140  return *this;
141  }
142 
146  inline Self& operator=(const std::vector<T>& values) {
147  copy(values);
148  return *this;
149  }
153  inline Self& operator=(const Self& values) {
154  copy(values);
155  return *this;
156  }
160  inline Self& operator=(Self&& values) {
161  copy(values);
162  return *this;
163  }
164 
170  template<typename Q,class I1>
171  inline Self& operator=(const CORE_Array<Q,I1>& values) {
172  copy(values);
173  return *this;
174  }
180  template<typename Q,class I1>
181  inline Self& operator=(const CORE_Array<Q,I1>&& values) {
182  copy(values);
183  return *this;
184  }
185 
186 
187 
188 
189  //copy methods
190  //============
191 public:
192 
193 
199  template<typename Q,class I>
200  inline void copy(const CORE_Array<Q,I>& cpy) {
201  this->setSize(cpy.getSize());
202  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
203  }
204 
210  template<typename Q,class I>
211  inline void copy(CORE_Array<Q,I>&& cpy) {
212  this->setSize(cpy.getSize());
213  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
214  }
215 
220  template<class I>
221  inline void copy(const Self& cpy) {
222  this->setSize(cpy.getSize());
223  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
224  }
225 
230  template<class I>
231  inline void copy(Self&& cpy) {
232  this->setSize(cpy.getSize());
233  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
234  }
235 
236 
242  template<typename Q>
243  inline void copy(const tIndex& n , const Q* Vs) {
244  this->setSize(n);
245  Copy(n,Vs,this->getValues());
246  }
247 
252  inline void copy(const tIndex& n,const std::initializer_list<T>& Vs) {
253  tIndex p=functions_numeric::min(n,Vs.size());
254  this->setSize(p);
255  Copy(p,Vs,this->getValues());
256  }
261  inline void copy(const tIndex& n,std::initializer_list<T>&& Vs) {
262  tIndex p=functions_numeric::min(n,Vs.size());
263  this->setSize(p);
264  Copy(p,Vs,this->getValues());
265  }
272  template<typename Q,size_t N>
273  inline void copy(const tIndex& n,const std::array<Q,N>& Vs) {
274  tIndex p=functions_numeric::min(n,N);
275  this->setSize(p);
276  Copy(p,Vs.getData(),this->getValues());
277  }
278 
284  template<typename Q>
285  inline void copy(const tIndex& n,const std::valarray<Q>& Vs) {
286  tIndex p=functions_numeric::min(n,Vs.size());
287  this->setSize(p);
288  Copy(p,&Vs[0],this->getValues());
289  }
295  template<typename Q>
296  inline void copy(const tIndex&n , const std::vector<Q>& Vs) {
297  tIndex p=functions_numeric::min(n,Vs.size());
298  this->setSize(p);
299  Copy(Vs.size(),Vs,this->getValues());
300  }
301 
302 
303 
304  //static Copy
305  //----------
306 
313  template<class Q>
314  inline static void Copy(const tIndex& n,const Q* X,T* R) {
315 
316 
317  OMP_PARALLEL_SHARED((n,X,R)) {//begin parallel section
318  // thread id
319  tInteger threadId=OMP_GET_THREAD_ID();
320 
321  // threads number
322  tInteger nThreads=OMP_GET_THREADS_NUMBER();
323 
324  //start index
325  tIndex start=threadId*n/nThreads;
326 
327  //end index
328  tIndex end=(threadId+1)*n/nThreads;
329 
330  //iterator on R values at start
331  T* iR=R;
332  iR+=start;
333 
334  //iterator on cpy values at start
335  const Q* iX=X;
336  iX+=start;
337 
338  if (sizeof(T)==sizeof(Q)) {
339  memcpy(iR,iX,sizeof(T)*(end-start));
340  } else {
341  //iterator on R values at end
342  const T* iRe=R;
343  iRe+=end;
344 
345  //copy the values of cpyA into aValue for element in [start,end[
346  while (iR!=iRe) {
347  (*iR)=(*iX);
348  iR++;
349  iX++;
350  }
351  }
352 
353  }//end parallel section
354  }
355 
363  template<typename Q>
364  inline static void Copy(const tIndex& n,const std::vector<Q>& X,T *R) {
365 
366 
367  //values of X
368  auto vX=X.cbegin();
369 
370  OMP_PARALLEL_SHARED((n,vX,R)) {//begin parallel section
371  // thread id
372  tInteger threadId=OMP_GET_THREAD_ID();
373 
374  // threads number
375  tInteger nThreads=OMP_GET_THREADS_NUMBER();
376 
377  //start index
378  tIndex start=threadId*n/nThreads;
379 
380  //end index
381  tIndex end=(threadId+1)*n/nThreads;
382 
383  //iterator on R values at start
384  T* iR=R;
385  iR+=start;
386 
387  //iterator on R values at end
388  const T* iRe=R;
389  iRe+=end;
390 
391  //iterator on cpy values at start
392  auto iX=vX;
393  iX+=start;
394 
395 
396  while (iR!=iRe) {
397  (*iR)=(*iX);
398  iR++;
399  iX++;
400  }
401 
402  }//end parallel section
403  }
404 
405 
406 
413  inline static void Copy(const tIndex& n,const std::initializer_list<T>& X,T *R) {
414 
415 
416  //get values of X
417  auto vX=X.begin();
418 
419  OMP_PARALLEL_SHARED((n,vX,R)) {//begin parallel section
420  // thread id
421  tInteger threadId=OMP_GET_THREAD_ID();
422 
423  // threads number
424  tInteger nThreads=OMP_GET_THREADS_NUMBER();
425 
426  //start index
427  tIndex start=threadId*n/nThreads;
428 
429  //end index
430  tIndex end=(threadId+1)*n/nThreads;
431 
432  //iterator on R values at start
433  T* iR=R;
434  iR+=start;
435 
436  //iterator on R values at end
437  const T* iRe=R;
438  iRe+=end;
439 
440  //iterator on X at start
441  auto iX=vX;
442  iX+=start;
443 
444 
445  while (iR!=iRe) {
446  (*iR)=(*iX);
447  iR++;
448  iX++;
449  }
450 
451  }//end parallel section
452  }
453 
454 
461  inline static void Copy(const tIndex& n,std::initializer_list<T>&& X,T *R) {
462 
463 
464  //get values of X
465  auto vX=X.begin();
466 
467  OMP_PARALLEL_SHARED((n,vX,R)) {//begin parallel section
468  // thread id
469  tInteger threadId=OMP_GET_THREAD_ID();
470 
471  // threads number
472  tInteger nThreads=OMP_GET_THREADS_NUMBER();
473 
474  //start index
475  tIndex start=threadId*n/nThreads;
476 
477  //end index
478  tIndex end=(threadId+1)*n/nThreads;
479 
480  //iterator on R values at start
481  T* iR=R;
482  iR+=start;
483 
484  //iterator on R values at end
485  const T* iRe=R;
486  iRe+=end;
487 
488  //iterator on X at start
489  auto iX=vX;
490  iX+=start;
491 
492 
493  while (iR!=iRe) {
494  (*iR)=(*iX);
495  iR++;
496  iX++;
497  }
498 
499  }//end parallel sections
500  }
501 
502 
503 
504  //initializers
505  //============
511  inline void initialize(const T& x) {
512  Initialize(x,this->getSize(),this->getValues());
513  }
514 
520  inline static void Initialize(const T& v, const tIndex& n,T* R) {
521 
522  if (fabs(v)<std::numeric_limits<T>::epsilon()) {
523 
524  //set to 0 by memset method
525 
526  OMP_PARALLEL_SHARED((n,R)) {//begin parallel section
527  // thread id
528  tInteger threadId=OMP_GET_THREAD_ID();
529 
530  // threads number
531  tInteger nThreads=OMP_GET_THREADS_NUMBER();
532 
533  //start index
534  tIndex start=threadId*n/nThreads;
535 
536  //end index
537  tIndex end=(threadId+1)*n/nThreads;
538 
539  if (end>start) memset(&R[start],0,(end-start)*sizeof(T));
540 
541  }
542 
543  } else {
544 
545  OMP_PARALLEL_SHARED((n,v,R)) {//begin parallel section
546  // thread id
547  tInteger threadId=OMP_GET_THREAD_ID();
548 
549  // threads number
550  tInteger nThreads=OMP_GET_THREADS_NUMBER();
551 
552  //start index
553  tIndex start=threadId*n/nThreads;
554 
555  //end index
556  tIndex end=(threadId+1)*n/nThreads;
557 
558  //iterator on R values at start
559  T* iR=R;
560  iR+=start;
561 
562  //iterator on R values at end
563  const T* iRe=R;
564  iRe+=end;
565 
566 
567 
568 
569  //copy the values of cpyA into aValue for element in [start,end[
570  while (iR!=iRe) {
571  (*iR)=v;
572  iR++;
573  }
574 
575  }//end parallel section
576  }
577  }
578 
579 
588  inline static void UniformRandomize(const T& min,const T& max,
589  const tIndex& n,T* values) {
590 
591  //x=d*(max-min)+min
592  T alpha=(max-min)/RAND_MAX;
593 
594 
595  //init the random data
596  OMP_PARALLEL_SHARED((alpha,n,min,values)) {//begin parallel section
597 
598  // threads number
599  tInteger nThreads=OMP_GET_THREADS_NUMBER();
600 
601  // thread id
602  tInteger threadId=OMP_GET_THREAD_ID();
603 
604 
605  //start index
606  tIndex start=threadId*n/nThreads;
607 
608  //end index
609  tIndex end=(threadId+1)*n/nThreads;
610 
611  //iterator on start values
612  T* iV=values;iV+=start;
613  //iterator on end values
614  const T* iVe=values;iVe+=end;
615 
616  //set random seed by process
617  tULLInt seed;
618  for(start=0;start<=threadId;start++) {
619  seed=std::rand();
620  }
621  std::srand(seed);
622 
623 
624  //copy the values of vs into A for element in [start,end[
625  while (iV!=iVe) {
626  (*iV)=alpha*std::rand()+min;
627  iV++;
628  }
629 
630  }//end parallel section
631  }
632 
633 
638  inline void uniformRandomize(const T& min,const T& max) {
639  UniformRandomize(min,max,this->getSize(),this->getValues());
640  }
641 
642 
643 
644  //compount assignement operator
645  //==============================
646 
650  inline Self& operator+=(const T& v) {
651  Add(v,this->getSize(),this->getValues());
652  return (*this);
653  }
657  inline Self& operator-=(const T& v) {
658  Add(-v,this->getSize(),this->getValues());
659  return (*this);
660  }
661 
665  inline Self& operator*=(const T& v) {
666  Multiply(v,this->getSize(),this->getValues());
667  return (*this);
668 
669  }
673  inline Self& operator/=(const T& v) {
674  if (fabs(v)<std::numeric_limits<T>::epsilon()) {
675  throw CORE_Exception("core",
676  "OMP_PtrArray::/=("+std::to_string(v)+")",
677  "division by zero");
678  }
679  Multiply(1./v,this->getSize(),this->getValues());
680  return (*this);
681  }
682 
683 
684  //integer type compond operators
685  //===============================
689  inline Self& operator%=(const T& v) requires functions_type::isIntegerType<T> {
690  auto F=[&v](const auto &x){return x%v;};
691  this->transform(F);
692  return (*this);
693  }
694 
699  inline Self& operator&=(const T& v) requires functions_type::isIntegerType<T> {
700  auto F=[&v](const auto &x){return x&v;};
701  this->transform(F);
702  return (*this);
703  }
704 
708  inline Self& operator|=(const T& v) requires functions_type::isIntegerType<T> {
709  auto F=[&v](const auto &x){return x|v;};
710  this->transform(F);
711  return (*this);
712  }
713 
717  inline Self& operator^=(const T& v) requires functions_type::isIntegerType<T> {
718  auto F=[&v](const auto &x){return x^v;};
719  this->transform(F);
720  return (*this);
721  }
725  inline Self& operator<<=(const T& v) requires functions_type::isIntegerType<T> {
726  auto F=[&v](const auto &x){return x<<v;};
727  this->transform(F);
728  return (*this);
729  }
733  inline Self& operator>>=(const T& v) requires functions_type::isIntegerType<T> {
734  auto F=[&v](const auto &x){return x>>v;};
735  this->transform(F);
736  return (*this);
737  }
738 
739  //class compount assignement operator
740  //-----------------------------------
747  template<typename Q,class I>
748  inline Self& operator+=(const CORE_Array<Q,I>& v) {
749  tIndex p=functions_numeric::min(v.getSize(),this->getSize());
750  Add(p,v.getValues(),this->getValues());
751  return *this;
752  }
753 
754 
761  template<typename Q,class I>
762  inline Self& operator-=(const CORE_Array<Q,I>& v) {
763  tIndex p=functions_numeric::min(v.getSize(),this->getSize());
764  Sub(p,v.getValues(),this->getValues());
765  return (*this);
766  }
773  template<typename Q,class I>
774  inline Self& operator*=(const CORE_Array<Q,I>& v) {
775  tIndex p=functions_numeric::min(v.getSize(),this->getSize());
776  Multiply(p,v.getValues(),this->getValues());
777  return (*this);
778  }
785  template<typename Q,class I>
786  inline Self& operator/=(const CORE_Array<Q,I>& v) {
787  tIndex p=functions_numeric::min(v.getSize(),this->getSize());
788  Divide(p,v.getValues(),this->getValues());
789  return (*this);
790  }
791 
792 
793 
794  //transform methods
795  //=================
796 
797 
802  template<typename LambdaFct>
803  inline void transform(LambdaFct&& F) {
804  Transform(F,(*this));
805  }
806 
812  template<typename LambdaFct>
813  inline void transform(LambdaFct&& F,
814  const CORE_Array<T,Self>& X) {
815  Transform(F,X,(*this));
816  }
823  template<typename LambdaFct>
824  inline void transform(LambdaFct&& F,
825  const CORE_Array<T,Self>& X,
826  const CORE_Array<T,Self>& Y) {
827  Transform(F,X,Y,*this);
828  }
829 
830 
836  template<typename LambdaFct>
837  static inline void Transform(LambdaFct&& F,
838  Self& X) {
839 
840  //size of all the array
841  tIndex n=X.getSize();
842 
843 
844 
845  //get the cont begin iterator of X
846  auto iX=X.cbegin();
847 
848 
849  //get the begin iterator of R
850  auto iR=X.begin();
851 
852 
853 
854  //init the random data
855  OMP_PARALLEL_SHARED((n,iX,iR,F)) {//begin parallel section
856 
857  // thread id
858  tInteger threadId=OMP_GET_THREAD_ID();
859 
860  //threads number
861  tInteger nThreads=OMP_GET_THREADS_NUMBER();
862 
863  tInteger start=threadId*n/nThreads;
864  tInteger end=(threadId+1)*n/nThreads;
865 
866  std::transform(iX+start,iX+end,
867  iR+start,F);
868 
869 
870  }//end parallel section
871  }
872 
873 
874 
881  template<typename LambdaFct>
882  static inline void Transform(LambdaFct&& F,
883  const CORE_Array<T,Self>& X,
884  Self& R) {
885 
886  //size of all the array
887  tIndex n=X.getSize();
888 
889  //resize the result
890  R.setSize(n);
891 
892 
893 
894 
895  //get the cont begin iterator of X
896  auto iX=X.cbegin();
897 
898 
899  //get the begin iterator of R
900  auto iR=R.begin();
901 
902 
903 
904  //init the random data
905  OMP_PARALLEL_SHARED((n,iX,iR,F)) {//begin parallel section
906 
907  // thread id
908  tInteger threadId=OMP_GET_THREAD_ID();
909 
910  //threads number
911  tInteger nThreads=OMP_GET_THREADS_NUMBER();
912 
913  tInteger start=threadId*n/nThreads;
914  tInteger end=(threadId+1)*n/nThreads;
915 
916  std::transform(iX+start,iX+end,
917  iR+start,F);
918 
919 
920  }//end parallel section
921  }
922 
923 
931  template<typename LambdaFct>
932  static inline void Transform(LambdaFct&& F,
933  const CORE_Array<T,Self>& X,
934  const CORE_Array<T,Self>& Y,
935  Self& R) {
936 
937  //siez of all the array
938  tIndex n=X.getSize();
939 
940  if (n!=Y.getSize())
941  throw CORE_Exception("opemp",
942  "OMP_PtrArray::Transform(F,X,Y,R)",
943  "X ("+std::to_string(X.getSize())+") & Y ("+std::to_string(Y.getSize())+") have not same size");
944 
945  R.setSize(n);
946 
947 
948 
949  //get the const begin iterator of X
950  auto iX=X.cbegin();
951 
952  //get the const begin iterator of Y
953  auto iY=Y.cbegin();
954 
955 
956  //get the begin iterator of R
957  auto iR=R.begin();
958 
959 
960 
961 
962 
963  //init the random data
964  OMP_PARALLEL_SHARED((n,iX,iY,iR,F)) {//begin parallel section
965 
966  // thread id
967  tInteger threadId=OMP_GET_THREAD_ID();
968  //threads number
969  tInteger nThreads=OMP_GET_THREADS_NUMBER();
970 
971  tInteger start=threadId*n/nThreads;
972  tInteger end=(threadId+1)*n/nThreads;
973 
974  std::transform(iX+start,iX+end,
975  iY+start,
976  iR+start,F);
977 
978 
979  }//end parallel section
980  }
981 
988  template<typename Q>
989  static void Add(const Q& v,const tIndex& n,T* values) {
990 
991  OMP_PARALLEL_SHARED((n,values,v)) {//begin parallel section
992  // thread id
993  tInteger threadId=OMP_GET_THREAD_ID();
994 
995  // threads number
996  tInteger nThreads=OMP_GET_THREADS_NUMBER();
997 
998  //start index
999  tIndex start=threadId*n/nThreads;
1000 
1001  //end index
1002  tIndex end=(threadId+1)*n/nThreads;
1003 
1004 
1005  //iterator on start index
1006  T* iV=values;iV+=start;
1007 
1008  //iterator on end index
1009  T* iVe=values;iVe+=end;
1010 
1011  //loop on index
1012  while(iV!=iVe) {
1013  (*iV)+=v;
1014  iV++;
1015  }
1016 
1017  }//end parallel section
1018  }
1019 
1026  template<typename Q>
1027  inline static void Add(const tIndex & n,const Q* Y,T* X) {
1028 
1029  OMP_PARALLEL_SHARED((n,X,Y)) {//begin parallel section
1030  // thread id
1031  tInteger threadId=OMP_GET_THREAD_ID();
1032 
1033  // threads number
1034  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1035 
1036  //start index
1037  tIndex start=threadId*n/nThreads;
1038 
1039  //end index
1040  tIndex end=(threadId+1)*n/nThreads;
1041 
1042 
1043  //iterator on start index of X
1044  T* iX=X;iX+=start;
1045 
1046  //iterator on start index of Y
1047  const Q* iY=Y;iY+=start;
1048 
1049  //iterator on end index of X
1050  T* iXe=X;iXe+=end;
1051 
1052  //loop on index
1053  while(iX!=iXe) {
1054  (*iX)+=(*iY);
1055  iY++;
1056  iX++;
1057  }
1058 
1059  }//end parallel section
1060 
1061  }
1062 
1069  template<typename Q>
1070  inline static void Sub(const tIndex & n,const Q* Y,T* X) {
1071 
1072  OMP_PARALLEL_SHARED((n,X,Y)) {//begin parallel section
1073  // thread id
1074  tInteger threadId=OMP_GET_THREAD_ID();
1075 
1076  // threads number
1077  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1078 
1079  //start index
1080  tIndex start=threadId*n/nThreads;
1081 
1082  //end index
1083  tIndex end=(threadId+1)*n/nThreads;
1084 
1085 
1086  //iterator on start index of X
1087  T* iX=X;iX+=start;
1088 
1089  //iterator on start index of Y
1090  const Q* iY=Y;iY+=start;
1091 
1092  //iterator on end index of X
1093  T* iXe=X;iXe+=end;
1094 
1095  //loop on index
1096  while(iX!=iXe) {
1097  (*iX)-=(*iY);
1098  iY++;
1099  iX++;
1100  }
1101 
1102  }//end parallel section
1103 
1104  }
1105 
1106 
1107 
1114  template<typename Q>
1115  static void Multiply(const Q& v,const tIndex& n,T* values) {
1116 
1117  OMP_PARALLEL_SHARED((n,values,v)) {//begin parallel section
1118  // thread id
1119  tInteger threadId=OMP_GET_THREAD_ID();
1120 
1121  // threads number
1122  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1123 
1124  //start index
1125  tIndex start=threadId*n/nThreads;
1126 
1127  //end index
1128  tIndex end=(threadId+1)*n/nThreads;
1129 
1130 
1131  //iterator on start index
1132  T* iV=values;iV+=start;
1133 
1134  //iterator on end index
1135  T* iVe=values;iVe+=end;
1136 
1137  //loop on index
1138  while(iV!=iVe) {
1139  (*iV)*=v;
1140  iV++;
1141  }
1142 
1143  }//end parallel section
1144  }
1145 
1146 
1153  template<typename Q>
1154  inline static void Multiply(const tIndex & n,const Q* Y,T* X) {
1155 
1156  OMP_PARALLEL_SHARED((n,X,Y)) {//begin parallel section
1157  // thread id
1158  tInteger threadId=OMP_GET_THREAD_ID();
1159 
1160  // threads number
1161  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1162 
1163  //start index
1164  tIndex start=threadId*n/nThreads;
1165 
1166  //end index
1167  tIndex end=(threadId+1)*n/nThreads;
1168 
1169 
1170  //iterator on start index of X
1171  T* iX=X;iX+=start;
1172 
1173  //iterator on start index of Y
1174  const Q* iY=Y;iY+=start;
1175 
1176  //iterator on end index of X
1177  T* iXe=X;iXe+=end;
1178 
1179  //loop on index
1180  while(iX!=iXe) {
1181  (*iX)*=(*iY);
1182  iY++;
1183  iX++;
1184  }
1185 
1186  }//end parallel section
1187 
1188  }
1197  template<typename Q>
1198  inline static void Divide(const tIndex & n,const Q* Y,T* X) {
1199 
1200  Q eps=std::numeric_limits<Q>::epsilon();
1201 
1202  OMP_PARALLEL_SHARED((eps,n,X,Y)) {//begin parallel section
1203  // thread id
1204  tInteger threadId=OMP_GET_THREAD_ID();
1205 
1206  // threads number
1207  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1208 
1209  //start index
1210  tIndex start=threadId*n/nThreads;
1211 
1212  //end index
1213  tIndex end=(threadId+1)*n/nThreads;
1214 
1215 
1216  //iterator on start index of X
1217  T* iX=X;iX+=start;
1218 
1219  //iterator on start index of Y
1220  const Q* iY=Y;iY+=start;
1221 
1222  //iterator on end index of X
1223  T* iXe=X;iXe+=end;
1224 
1225  //loop on index
1226  while(iX!=iXe) {
1227  if (fabs(*iY)<eps) throw CORE_Exception("openmp",
1228  "OMP_PtrArray::Divide()",
1229  "division by zero");
1230  (*iX)/=(*iY);
1231  iY++;
1232  iX++;
1233  }
1234 
1235  }//end parallel section
1236 
1237  }
1238 
1241  inline void normalize() {
1242  Normalize(this->getSize(),this->getValues());
1243  }
1244 
1250  inline static T norm2(const tIndex& n,const T *values) {
1251  //initialization of norm
1252  T norm2=0;
1253 
1254  OMP_PARALLEL_SHARED_REDUCTION((n,values),(+:norm2)) {//begin parallel section
1255 
1256  // thread id
1257  tInteger threadId=OMP_GET_THREAD_ID();
1258  // threads number
1259  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1260 
1261  //start idnex of the loop
1262  tIndex start=threadId*n/nThreads;
1263  //end index oft the loop
1264  tIndex end=(threadId+1)*n/nThreads;;
1265 
1266  const T* iV =values;iV+=start;//iterator on start index
1267 
1268  const T* eiV=values;eiV+=end;//end iterator on end index
1269 
1270  norm2=0;
1271  while (iV!=eiV) {
1272  norm2+=(*iV)*(*iV);
1273  iV++;
1274  }
1275 
1276  }
1277  return norm2;
1278  }
1283  inline static void Normalize(const tIndex& n,T* values) {
1284 
1285  //inverse of norm of V
1286  T inorm=norm2(n,values);
1287  if (fabs(inorm)>std::numeric_limits<T>::epsilon()) {//norm is not null
1288  //inverse of norm
1289  inorm=1./sqrt(inorm);
1290  //loop on
1291  OMP_PARALLEL_SHARED((n,values,inorm)) {//begin parallel section
1292 
1293  // thread id
1294  tInteger threadId=OMP_GET_THREAD_ID();
1295  // threads number
1296  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1297 
1298  //start idnex of the loop
1299  tIndex start=threadId*n/nThreads;
1300  //end index oft the loop
1301  tIndex end=(threadId+1)*n/nThreads;;
1302  T* iV =values;iV+=start;//iterator on values
1303  const T* iVe=values;iVe+=end;//iterator on end values
1304  while (iV!=iVe) {
1305  (*iV)*=inorm;
1306  iV++;
1307  }
1308 
1309  }
1310 
1311  }
1312  }
1320  template<typename Q,class I>
1321  inline void axpy(const Q& alpha, const CORE_Array<Q,I>& X,const T& beta) {
1322  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
1323  AXPY(p,alpha,X.getValues(),beta,this->getValues());
1324  }
1325 
1334  template<typename Q>
1335  inline void AXPY(const tIndex& n,const Q& alpha, const Q* X,const T& beta, T* Y) {
1336 
1337  OMP_PARALLEL_SHARED((n,alpha,beta,X,Y)) {//begin parallel section
1338 
1339  // thread id
1340  tInteger threadId=OMP_GET_THREAD_ID();
1341 
1342  // threads number
1343  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1344 
1345  //start index of the values within the thread
1346  tIndex start=threadId*n/nThreads;
1347 
1348  //end index of the values within the thread
1349  tIndex end=(threadId+1)*n/nThreads;
1350 
1351  //start iterator on X
1352  const Q *iX=X+start;
1353 
1354  //start iterator on Y
1355  T *iY=Y+start;
1356 
1357  //end iterator on Y
1358  const T *iYe=Y+end;
1359 
1360  while (iY!=iYe) {
1361  (*iY)=beta*(*iY)+alpha*(*iX);
1362  iX++;
1363  iY++;
1364  }
1365  }
1366  }
1367 
1368 
1369  //Data consistency
1370  //=================
1375  inline tBoolean isNANContained() const {
1376  return IsNANContained(this->getSize(),this->getValues());
1377  }
1384  inline static tBoolean IsNANContained(const tIndex& n,const T* values) {
1385 
1386 
1387  tBoolean isnan=false;//0
1388  OMP_PARALLEL_SHARED_REDUCTION((n,values),(max:isnan)) {//begin parallel section
1389 
1390  // thread id
1391  tInteger threadId=OMP_GET_THREAD_ID();
1392 
1393  // threads number
1394  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1395 
1396  //start index
1397  const T* iV=values+threadId*n/nThreads;
1398 
1399  //end index
1400  const T* iVe=values+(threadId+1)*n/nThreads;
1401 
1402 
1403  //test if there is a nan value within [start,end[
1404  while (iV!=iVe) {
1405  if (std::isnan(*iV)) break;
1406  iV++;
1407  }
1408 
1409  isnan=(iV!=iVe);
1410 
1411  }//end parallel section
1412 
1413  return isnan;
1414 
1415  }
1416 
1417 
1418 
1419 
1420 
1421 
1422  //algebric method
1423  //===================
1424 
1428  inline void sum(T& s) const {
1429  s=Sum(this->getSize(),this->getValues());
1430  }
1431 
1432 
1438  inline static T Sum(const tIndex& n,const T* values) {
1439 
1440 
1441 
1442  T s=0;//0
1443  OMP_PARALLEL_SHARED_REDUCTION((n,values),(+:s)) {//begin parallel section
1444 
1445  // thread id
1446  tInteger threadId=OMP_GET_THREAD_ID();
1447  // threads number
1448  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1449 
1450  //start index
1451  const T* iV=values+threadId*n/nThreads;
1452 
1453  //end index
1454  const T* iVe=values+(threadId+1)*n/nThreads;
1455 
1456 
1457  //test if there is a nan value within [start,end[
1458  s=0;
1459  while (iV!=iVe){s+=(*iV);iV++;}
1460 
1461 
1462  }//end parallel section
1463 
1464  return s;
1465  }
1469  inline void prod(T& p) const {
1470  p=Prod(this->getSize(),this->getValues());
1471  }
1472 
1478  inline static T Prod(const tIndex& n,const T* values) {
1479 
1480  T p=1;
1481  OMP_PARALLEL_SHARED_REDUCTION((n,values),(*:p)) {//begin parallel section
1482 
1483  // thread id
1484  tInteger threadId=OMP_GET_THREAD_ID();
1485  // threads number
1486  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1487 
1488  //start index
1489  const T* iV=values+threadId*n/nThreads;
1490 
1491  //end index
1492  const T* iVe=values+(threadId+1)*n/nThreads;
1493 
1494 
1495  //test if there is a nan value within [start,end[
1496  p=1;
1497  while (iV!=iVe){p*=(*iV);iV++;}
1498 
1499 
1500  }//end parallel section
1501 
1502  return p;
1503 
1504 
1505  }
1513  template<typename Q,class I>
1514  inline T& scalarProduct(const CORE_Array<Q,I>& X,T& s) const {
1515  tIndex p=functions_numeric::min(this->getSize(),X.getSize());
1516  s=ScalarProduct(p,X.getValues(),this->getValues());
1517  return s;
1518  }
1519 
1520 
1521 
1529  template<typename Q>
1530  inline static T ScalarProduct(const tIndex& n,
1531  const Q* X,
1532  const T* Y) {
1533 
1534  //s=sum_i Xi Yi
1535  T s=0;
1536 
1537  OMP_PARALLEL_SHARED_REDUCTION((n,Y,X),(+:s)) {//begin parallel section
1538 
1539 
1540  // thread id
1541  tInteger threadId=OMP_GET_THREAD_ID();
1542  // threads number
1543  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1544 
1545  //start idnex of the loop
1546  tIndex start=threadId*n/nThreads;
1547  //end index oft the loop
1548  tIndex end=(threadId+1)*n/nThreads;;
1549 
1550  //start iterator of the loop
1551  auto iX=X;iX+=start;
1552  auto iY=Y;iY+=start;
1553 
1554 
1555  //end iterator of the loop
1556  auto iXe=X;iXe+=end;
1557  s=0;
1558  while (iX!=iXe) {
1559  s+=(*iX)*(*iY);
1560  iY++;
1561  iX++;
1562  }
1563  }//end parallel loop
1564 
1565  return s;
1566  }
1567 
1568 
1569 
1574  inline tReal l2Norm2() const {
1575  return L2Distance2(0,(tReal*)null,this->getSize(),this->getValues());
1576  }
1577 
1585  template<typename Q,class I>
1586  inline tReal l2Distance2(const CORE_Array<Q,I>& X) const {
1587  return L2Distance2(X.getSize(),X.getValues(),this->getSize(),this->getValues());
1588  }
1589 
1590 
1591 
1601  template<typename Q>
1602  inline static tReal L2Distance2(const tIndex& nX,const Q* Xs,
1603  const tIndex& nY,const T* Ys) {
1604 
1605 
1606  //d2=\sum_i |Xi-Yi|^2
1607  tReal d2=0;
1608 
1609  //size of common loop
1610  tIndex n=functions_numeric::min(nX,nY);
1611 
1612 
1613  OMP_PARALLEL_SHARED_REDUCTION((n,Xs,Ys),(+:d2)) {
1614 
1615  //third id
1616  tInteger threadId=OMP_GET_THREAD_ID();
1617  // number of threads
1618  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1619 
1620  //start index
1621  tIndex start=threadId*n/nThreads;
1622  //end index
1623  tIndex end=(threadId+1)*n/nThreads;
1624 
1625  //iterator on start
1626  const T *iY=Ys+start;
1627  const Q *iX=Xs+start;
1628  //iterator on end
1629  const Q *iXe=Xs+end;
1630  //temporary value
1631  tReal tmp;
1632 
1633  d2=0;
1634  while (iX!=iXe) {
1635  tmp=(*iX)-(*iY);
1636  d2+=tmp*tmp;
1637  iX++;
1638  iY++;
1639  }//end loop on X & Y
1640  }//end parallel section
1641 
1642  tIndex p=nX-n;
1643  if (p>0) {
1644  OMP_PARALLEL_SHARED_REDUCTION((p,n,Xs),(+:d2)) {
1645 
1646  //third id
1647  tInteger threadId=OMP_GET_THREAD_ID();
1648  // number of threads
1649  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1650 
1651  //start index
1652  tIndex start=threadId*p/nThreads;
1653  //end index
1654  tIndex end=(threadId+1)*p/nThreads;
1655 
1656  //iterator on start
1657  const Q *iX=Xs+n+start;
1658  //iterator on end
1659  const Q *iXe=Xs+n+end;
1660 
1661  while (iX!=iXe) {
1662  d2+=(*iX)*(*iX);
1663  iX++;
1664  }
1665  }//end parallel section
1666  }//and loop on X
1667 
1668 
1669 
1670  p=nY-n;
1671  if (p>0) {
1672  OMP_PARALLEL_SHARED_REDUCTION((p,n,Ys),(+:d2)) {
1673 
1674  //third id
1675  tInteger threadId=OMP_GET_THREAD_ID();
1676  // number of threads
1677  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1678 
1679  //start index
1680  tIndex start=threadId*p/nThreads;
1681  //end index
1682  tIndex end=(threadId+1)*p/nThreads;
1683 
1684  //iterator on start
1685  const T *iY=Ys+n+start;
1686  //iterator on end
1687  const T *iYe=Ys+n+end;
1688  while (iY!=iYe) {
1689  d2+=(*iY)*(*iY);
1690  iY++;
1691  }
1692 
1693  }//end parallel section
1694  }//and loop on Y
1695 
1696  return d2;
1697  }
1698 
1699 
1704  inline tReal linfNorm(tIndex& imax) const {
1705  return LinfDistance(0,(tReal*)null,this->getSize(),this->getValues(),imax);
1706  }
1707 
1716  template<typename Q,class I>
1717  inline tReal linfDistance(const CORE_Array<Q,I>& X,tIndex& imax) const {
1718  return LinfDistance(X.getSize(),X.getValues(),this->getSize(),this->getValues(),imax);
1719  }
1720 
1721 
1722 
1732  template<typename Q>
1733  inline static tReal LinfDistance(const tIndex& nX,const Q* Xs,
1734  const tIndex& nY,const T* Ys,
1735  tIndex& imax) {
1736 
1737 
1738  //common size
1739  tIndex n=functions_numeric::min(nX,nY);
1740 
1741 
1742  //S=(index,value)
1743  std::pair<tIndex,tReal> S(0,0);
1744 
1745  //common loop
1746  OMP_PARALLEL_SHARED_REDUCTION((n,Ys,Xs), (argrmax:S)) {
1747  // thread id
1748  tInteger threadId=OMP_GET_THREAD_ID();
1749  // threads number
1750  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1751 
1752  //start index
1753  tIndex start=threadId*n/nThreads;
1754  //end index
1755  tIndex end=(threadId+1)*n/nThreads;
1756 
1757  //begin iterator on start
1758  const T *iY=Ys+start;
1759 
1760  //begin iterator on start
1761  const Q *iX=Xs+start;
1762 
1763  //start index
1764  tIndex i;
1765  //local variable
1766  T norm2;
1767  for (i=start;i<end;i++) {
1768  norm2=(*iY)-(*iX);
1769  norm2*=norm2;
1770  if (S.second<norm2) {
1771  S.second=norm2;
1772  S.first=i;
1773  }
1774  iY++;
1775  iX++;
1776 
1777  }
1778  }//end parallel
1779 
1780  tIndex p=nX-n;
1781  if (p>0) {
1782  OMP_PARALLEL_SHARED_REDUCTION((n,p,Xs), (argrmax:S)) {
1783  // thread id
1784  tInteger threadId=OMP_GET_THREAD_ID();
1785  // threads number
1786  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1787 
1788  //start index
1789  tIndex start=threadId*p/nThreads;
1790  //end index
1791  tIndex end=(threadId+1)*p/nThreads;
1792 
1793 
1794  //begin iterator on start
1795  const Q*iX=Xs+n+start;
1796  //begin iterator on end
1797  const Q *iXe=Xs+n+end;
1798 
1799  //start index
1800  tIndex i=n+start;
1801  //local variable
1802  tReal norm2;
1803  while (iX!=iXe) {
1804  norm2=(*iX)*(*iX);
1805  if (S.second<norm2) {
1806  S.second=norm2;
1807  S.first=i;
1808  }
1809  iX++;
1810  i++;
1811  }
1812  }//end parallel
1813 
1814  }//end loop on X
1815  p=nY-n;
1816  if (p>0) {
1817  OMP_PARALLEL_SHARED_REDUCTION((n,p,Ys), (argrmax:S)) {
1818  // thread id
1819  tInteger threadId=OMP_GET_THREAD_ID();
1820  // threads number
1821  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1822 
1823  //start index
1824  tIndex start=threadId*p/nThreads;
1825  //end index
1826  tIndex end=(threadId+1)*p/nThreads;
1827 
1828 
1829  //begin iterator on start
1830  const T *iY=Ys+n+start;
1831  //begin iterator on end
1832  const T *iYe=Ys+n+end;
1833 
1834  //start index
1835  tIndex i=n+start;
1836  //local variable
1837  tReal norm2;
1838  while (iY!=iYe) {
1839  norm2=(*iY)*(*iY);
1840  if (S.second<norm2) {
1841  S.second=norm2;
1842  S.first=i;
1843  }
1844  iY++;
1845  i++;
1846  }
1847  }//end parallel
1848 
1849  }//end loop on X
1850 
1851 
1852  //return value
1853  imax=S.first;
1854  return sqrt(S.second);
1855 
1856  }
1857 
1858 
1859 
1860  //ordered methods
1861  //===============
1862 
1866  inline void min(T& m) const requires functions_type::isOrderedType<T> {
1867  m=Min(this->getSize(),this->getValues());
1868  }
1874  inline static T Min(const tIndex& n,const T* values) requires functions_type::isOrderedType<T> {
1875 
1876 
1877  //default min value set to the first value
1878  T p=(n>0)?(*values):0;
1879  OMP_PARALLEL_SHARED_REDUCTION((n,values),(min:p)) {//begin parallel section
1880 
1881  // thread id
1882  tInteger threadId=OMP_GET_THREAD_ID();
1883  // threads number
1884  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1885 
1886  //start index
1887  const T* iV=values+threadId*n/nThreads;
1888 
1889  //end index
1890  const T* iVe=values+(threadId+1)*n/nThreads;
1891 
1892  while (iV!=iVe){p=(p<(*iV))?p:(*iV);iV++;}
1893 
1894 
1895  }//end parallel section
1896 
1897  return p;
1898 
1899 
1900  }
1901 
1905  inline void max(T& m) const requires functions_type::isOrderedType<T> {
1906  m=Max(this->getSize(),this->getValues());
1907  }
1913  inline static T Max(const tIndex& n,const T* values) requires functions_type::isOrderedType<T> {
1914 
1915 
1916  //defaut max values set to the first values
1917  T p=(n>0)?(*values):0;
1918 
1919  OMP_PARALLEL_SHARED_REDUCTION((n,values),(max:p)) {//begin parallel section
1920 
1921  // thread id
1922  tInteger threadId=OMP_GET_THREAD_ID();
1923  // threads number
1924  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1925 
1926  //start index
1927  const T* iV=values+threadId*n/nThreads;
1928 
1929  //end index
1930  const T* iVe=values+(threadId+1)*n/nThreads;
1931 
1932  while (iV!=iVe){p=(p>(*iV))?p:(*iV);iV++;}
1933 
1934 
1935  }//end parallel section
1936 
1937  return p;
1938 
1939 
1940  }
1941 
1942 
1946  inline void directionalSort(const tUChar& order) requires functions_type::isOrderedType<T>{
1947  switch(order) {
1948  case 'i':
1949  std::sort(this->begin(),this->end(),std::less<T>());
1950  break;
1951  case 'd':
1952  std::sort(this->begin(),this->end(),std::greater<T>());
1953  break;
1954  }
1955 
1956  }
1957 
1958 };
1959 
1960 
1961 
1963 
1967 
1968 
1970 
1973 
1975 
1976 //default field
1977 #ifndef DEFAULT_OMP_ARRAY
1978 #define DEFAULT_OMP_ARRAY
1980 #endif
1981 
1982 
1983 #endif
this class describes an array of values T of dynamical size with algebrical operators and I is an imp...
Definition: CORE_Array.h:91
const T * getValues() const
get the values of the array for reading
Definition: CORE_Array.h:206
constexpr auto cbegin() const
return begin iterator for reading
Definition: CORE_Collection.h:143
tIndex getSize() const
return the size of the container
Definition: CORE_Collection.h:111
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
this class describes an arithmetic array type implemented with as a pointer allocation object with im...
Definition: CORE_PtrArray.h:69
const T * getValues() const
get the values of the array for reading
Definition: CORE_PtrArray.h:357
auto begin()
return begin iterator for writing
Definition: CORE_PtrArray.h:312
auto end()
return end iterator for writing
Definition: CORE_PtrArray.h:318
void setSize(const tIndex &n)
set the number of values
Definition: CORE_PtrArray.h:146
constexpr auto cbegin() const
return begin iterator for reading
Definition: CORE_PtrArray.h:300
tIndex getSize() const
return the size of the array for writing
Definition: CORE_PtrArray.h:155
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_PtrArray.h:132
this class define a PTR array with OpenMP vectorization
Definition: OMP_PtrArray.h:22
Self & operator*=(const CORE_Array< Q, I > &v)
array multiply operator
Definition: OMP_PtrArray.h:774
static T norm2(const tIndex &n, const T *values)
computes the square of norm of the norm
Definition: OMP_PtrArray.h:1250
Self & operator-=(const CORE_Array< Q, I > &v)
array sub operator
Definition: OMP_PtrArray.h:762
static void Transform(LambdaFct &&F, const CORE_Array< T, Self > &X, const CORE_Array< T, Self > &Y, Self &R)
transform the transform element with the lambda function Ri = F(const Xi,const Yi)
Definition: OMP_PtrArray.h:932
Self & operator*=(const T &v)
multiplicator operator
Definition: OMP_PtrArray.h:665
Self & operator=(const Self &values)
build an array by a copy of c
Definition: OMP_PtrArray.h:153
void transform(LambdaFct &&F, const CORE_Array< T, Self > &X)
transform the transform element in parallel to the lambda function Ti=F(const Xi)
Definition: OMP_PtrArray.h:813
tReal linfDistance(const CORE_Array< Q, I > &X, tIndex &imax) const
compute the square of L2-distance of this to X
Definition: OMP_PtrArray.h:1717
void copy(const tIndex &n, std::initializer_list< T > &&Vs)
initialize the array to the values of list
Definition: OMP_PtrArray.h:261
Self & operator/=(const T &v)
divisor operator
Definition: OMP_PtrArray.h:673
Self & operator=(Self &&values)
build an array by a copy of c (in mirror with the copy operator)
Definition: OMP_PtrArray.h:160
static void Copy(const tIndex &n, std::initializer_list< T > &&X, T *R)
copy the the n first values of an initializer
Definition: OMP_PtrArray.h:461
void AXPY(const tIndex &n, const Q &alpha, const Q *X, const T &beta, T *Y)
compute Y=beta.Y+ alpha .X
Definition: OMP_PtrArray.h:1335
void uniformRandomize(const T &min, const T &max)
randomize the vector in [min,max]
Definition: OMP_PtrArray.h:638
void copy(Self &&cpy)
copy the container : mv is destroyed after this
Definition: OMP_PtrArray.h:231
tReal l2Distance2(const CORE_Array< Q, I > &X) const
compute the square of L2-distance of this to X
Definition: OMP_PtrArray.h:1586
static void Multiply(const tIndex &n, const Q *Y, T *X)
compute X*=Y
Definition: OMP_PtrArray.h:1154
void copy(const tIndex &n, const std::array< Q, N > &Vs)
initialize the array to the values of array of size N
Definition: OMP_PtrArray.h:273
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: OMP_PtrArray.h:68
void copy(const tIndex &n, const std::vector< Q > &Vs)
initialize the array to the values of vector
Definition: OMP_PtrArray.h:296
void sum(T &s) const
return the sum of all the elements
Definition: OMP_PtrArray.h:1428
Self & operator=(const std::vector< T > &values)
build an array by a copy of c
Definition: OMP_PtrArray.h:146
static void Copy(const tIndex &n, const std::vector< Q > &X, T *R)
copy the the n first values of an initializer
Definition: OMP_PtrArray.h:364
Self & operator=(const CORE_Array< Q, I1 > &values)
build an array by a copy of c
Definition: OMP_PtrArray.h:171
void transform(LambdaFct &&F)
transform the transform element in parallel to the lambda function Ti=F(const Ti)
Definition: OMP_PtrArray.h:803
Self & operator/=(const CORE_Array< Q, I > &v)
array divisor operator
Definition: OMP_PtrArray.h:786
static void UniformRandomize(const T &min, const T &max, const tIndex &n, T *values)
randomize the vector in [0,max]
Definition: OMP_PtrArray.h:588
Self & operator=(const std::valarray< T > &values)
build an array by a copy of c
Definition: OMP_PtrArray.h:138
Self & operator=(std::initializer_list< T > &&values)
build an array by a copy of c
Definition: OMP_PtrArray.h:112
Self & operator%=(const T &v) requires functions_type
modulo operator
Definition: OMP_PtrArray.h:689
Self & operator=(const std::array< T, N > &values)
build an array by a copy of c
Definition: OMP_PtrArray.h:129
static void Add(const Q &v, const tIndex &n, T *values)
add to the values the constant v
Definition: OMP_PtrArray.h:989
void copy(const tIndex &n, const std::initializer_list< T > &Vs)
initialize the array to the values of list
Definition: OMP_PtrArray.h:252
OMP_PtrArray(const tIndex &n)
build an instance of class of size n
Definition: OMP_PtrArray.h:41
static void Copy(const tIndex &n, const std::initializer_list< T > &X, T *R)
copy the the n first values of an initializer
Definition: OMP_PtrArray.h:413
static void Initialize(const T &v, const tIndex &n, T *R)
copy the n values of a pointers array
Definition: OMP_PtrArray.h:520
static T ScalarProduct(const tIndex &n, const Q *X, const T *Y)
return the sclar product
Definition: OMP_PtrArray.h:1530
tReal linfNorm(tIndex &imax) const
compute the Linf-norm of this
Definition: OMP_PtrArray.h:1704
void copy(const tIndex &n, const Q *Vs)
initialize the array to the values of pointer of size n
Definition: OMP_PtrArray.h:243
static void Divide(const tIndex &n, const Q *Y, T *X)
compute X/=Y
Definition: OMP_PtrArray.h:1198
Self & operator=(const std::initializer_list< T > &values)
build an array by a copy of c
Definition: OMP_PtrArray.h:119
Self & operator-=(const T &v)
sub operator
Definition: OMP_PtrArray.h:657
void copy(CORE_Array< Q, I > &&cpy)
copy the container : mv is destroyed after this
Definition: OMP_PtrArray.h:211
void copy(const CORE_Array< Q, I > &cpy)
copy the container
Definition: OMP_PtrArray.h:200
OMP_PtrArray()
build an instance of class
Definition: OMP_PtrArray.h:34
Self & operator=(const CORE_Array< Q, I1 > &&values)
build an array by a copy of c (in mirror with the copy operator)
Definition: OMP_PtrArray.h:181
static tReal LinfDistance(const tIndex &nX, const Q *Xs, const tIndex &nY, const T *Ys, tIndex &imax)
compute the index of the array where the module of the difference between X & Y is max
Definition: OMP_PtrArray.h:1733
static void Multiply(const Q &v, const tIndex &n, T *values)
multiply the values by the constant v
Definition: OMP_PtrArray.h:1115
virtual ~OMP_PtrArray()
destroy an instance of class
Definition: OMP_PtrArray.h:52
void normalize()
normalize the array
Definition: OMP_PtrArray.h:1241
static void Add(const tIndex &n, const Q *Y, T *X)
compute X+=Y
Definition: OMP_PtrArray.h:1027
static void Transform(LambdaFct &&F, const CORE_Array< T, Self > &X, Self &R)
transform the transform element with the lambda function Ri = F(const Xi)
Definition: OMP_PtrArray.h:882
tReal l2Norm2() const
compute the square of L2-norm of this
Definition: OMP_PtrArray.h:1574
static void Sub(const tIndex &n, const Q *Y, T *X)
compute X-=Y
Definition: OMP_PtrArray.h:1070
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: OMP_PtrArray.h:1375
void copy(const tIndex &n, const std::valarray< Q > &Vs)
initialize the array to the values of val array
Definition: OMP_PtrArray.h:285
static void Transform(LambdaFct &&F, Self &X)
transform the transform element with the lambda function Xi = F(const Xi)
Definition: OMP_PtrArray.h:837
void transform(LambdaFct &&F, const CORE_Array< T, Self > &X, const CORE_Array< T, Self > &Y)
transform the transform element with the lambda function Ti := F(const Xi,const Yi)
Definition: OMP_PtrArray.h:824
static void Copy(const tIndex &n, const Q *X, T *R)
copy the n values of a pointers array
Definition: OMP_PtrArray.h:314
void prod(T &p) const
return the produc of all the elements
Definition: OMP_PtrArray.h:1469
Self & operator+=(const T &v)
add operator
Definition: OMP_PtrArray.h:650
static tBoolean IsNANContained(const tIndex &n, const T *values)
return true if one value is Not A Number
Definition: OMP_PtrArray.h:1384
void axpy(const Q &alpha, const CORE_Array< Q, I > &X, const T &beta)
compute This=beta.This+ alpha .X
Definition: OMP_PtrArray.h:1321
static void Normalize(const tIndex &n, T *values)
normalize the array
Definition: OMP_PtrArray.h:1283
static CORE_UniquePointer< Self > New()
return a unique pointer of the class
Definition: OMP_PtrArray.h:79
Self & operator=(const T &v)
fill the values of the array with v
Definition: OMP_PtrArray.h:105
void copy(const Self &cpy)
copy the container
Definition: OMP_PtrArray.h:221
void initialize(const T &x)
initialize the array to the value x
Definition: OMP_PtrArray.h:511
static T Sum(const tIndex &n, const T *values)
return the sum of all the elements
Definition: OMP_PtrArray.h:1438
T & scalarProduct(const CORE_Array< Q, I > &X, T &s) const
return the scalar product
Definition: OMP_PtrArray.h:1514
static T Prod(const tIndex &n, const T *values)
return the product of all the elements
Definition: OMP_PtrArray.h:1478
static tReal L2Distance2(const tIndex &nX, const Q *Xs, const tIndex &nY, const T *Ys)
compute the square of L2 distance of X to Y
Definition: OMP_PtrArray.h:1602