C++ mpi module for stochmagnet_main Package
OMP_ValArray.h
1 #ifndef OMP_ValArray_H
2 #define OMP_ValArray_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_ValArray.h"
12 
13 
18 template<class T>
19 class OMP_ValArray : public CORE_ValArray<T,OMP_ValArray<T>> {
20 
21 private:
22  //This class type
23  typedef OMP_ValArray<T> Self;
24 
25 public:
26 
27 
28 
32  }
33 
34 
38  explicit OMP_ValArray(const tIndex& n) : CORE_ValArray<T,Self>(n) {
39  }
40 
41 
42 
43 
44 
45  // DESTRUCTORS
48  virtual ~OMP_ValArray() {
49  }
50 
51 
52 
53 
54  //MEMORY
55  //=====
56 public:
64  virtual tMemSize getMemorySize() const override {
65  return sizeof(*this)+this->getContentsMemorySize();
66  }
67 
68 
69  // ----------------
70  // New constructors
71  // ----------------
75  static inline CORE_UniquePointer<Self> New() {
76  return CORE_UniquePointer<Self>(new Self(),
78  };
79 
80 public:
81 
82 
83  //accessor operators
84  //====================
85 
86 
87  //accessor iterator
88  //=================
89 
90 
91  //accessor methods
92  //=================
93 
94  //assignement operator
95  //====================
96 
97 public:
98 
102  inline Self& operator=(const T& v) {
103  initialize(v);
104  return *this;
105  }
109  inline Self& operator=(const std::initializer_list<T>& values) {
110  Copy(values.size(),values,this->getArray());
111  return *this;
112  }
116  inline Self& operator=(std::initializer_list<T>&& values) {
117  Copy(values.size(),values,this->getArray());
118  return *this;
119  }
120 
125  template<size_t N>
126  inline Self& operator=(const std::array<T,N>& values) {
127  Copy(N,values,this->getArray());
128  return *this;
129 
130  }
131 
135  inline Self& operator=(const std::valarray<T>& values) {
136  Copy(values.size(),values,this->getArray());
137  return *this;
138  }
139 
143  inline Self& operator=(const std::vector<T>& values) {
144  Copy(values.size(),values,this->getArray());
145  return *this;
146  }
150  inline Self& operator=(const Self& values) {
151  Copy(values,this->getArray());
152  return *this;
153  }
157  inline Self& operator=(Self&& values) {
158  Copy(values,this->getArray());
159  return *this;
160  }
161 
167  template<typename Q,class I1>
168  inline Self& operator=(const CORE_Array<Q,I1>& values) {
169  Copy(values,this->getArray());
170  return *this;
171  }
177  template<typename Q,class I1>
178  inline Self& operator=(const CORE_Array<Q,I1>&& values) {
179  Copy(values,this->getArray());
180  return *this;
181  }
182 
183 
184 
185 
186  //copy methods
187  //============
188 public:
189 
190 
196  template<typename Q,class I>
197  inline void copy(const CORE_Array<Q,I>& X) {
198  Copy(X,this->getArray());
199  }
200 
206  template<typename Q,class I>
207  inline void copy(CORE_Array<Q,I>&& X) {
208  Copy(X,this->getArray());
209  }
210 
216  template<typename Q,class I>
217  inline void copy(const CORE_ValArray<Q,I>& X) {
218  Copy(X.getArray(),this->getArray());
219  }
220 
226  template<typename Q,class I>
227  inline void copy(CORE_ValArray<Q,I>&& X) {
228  Copy(X.getArray(),this->getArray());
229  }
230 
231 
232 
236  inline void copy(const Self& cpy) {
237  Copy(cpy.getArray(),this->getArray());
238  }
239 
243  inline void copy(Self&& cpy) {
244  Copy(cpy.getArray(),this->getArray());
245  }
246 
247 
248 
254  template<typename Q>
255  inline void copy(const tIndex& n , const Q* Vs) {
256  Copy(n,Vs,this->getArray());
257  }
258 
264  inline void copy(const tIndex& n,const std::initializer_list<T>& Vs) {
265  tIndex p=functions_numeric::min(n,Vs.size());
266  Copy(p,Vs,this->getArray());
267  }
272  inline void copy(const tIndex& n,std::initializer_list<T>&& Vs) {
273  tIndex p=functions_numeric::min(n,Vs.size());
274  Copy(p,Vs,this->getArray());
275  }
282  template<typename Q,size_t N>
283  inline void copy(const tIndex& n, const std::array<Q,N>& Vs) {
284  tIndex p=functions_numeric::min(n,N);
285  Copy(p,Vs.getData(),this->getArray());
286  }
287 
293  template<typename Q>
294  inline void copy(const tIndex& n, const std::valarray<Q>& Vs) {
295  tIndex p=functions_numeric::min(n,Vs.size());
296  Copy(p,Vs,this->getArray());
297  }
303  template<typename Q>
304  inline void copy(const tIndex& n, const std::vector<Q>& Vs) {
305  tIndex p=functions_numeric::min(n,Vs.size());
306  Copy(p,Vs,this->getArray());
307  }
308 
309 
310 
311  //static Copy
312  //----------
319  template<typename Q,class I>
320  inline static void Copy(const CORE_Array<Q,I>& X,std::valarray<T>& R) {
321 
322  //resize R
323  tIndex p=X.getSize();
324  if (R.size()!=p) R.resize(p);
325 
326  //get begin iterator of R
327  auto iR=std::ranges::begin(R);
328 
329  //get const begin iterator on X
330  auto iX=X.cbegin();
331 
332  OMP_PARALLEL_SHARED((p,iX,iR)) {//begin parallel section
333  // thread id
334  tInteger threadId=OMP_GET_THREAD_ID();
335 
336  // threads number
337  tInteger nThreads=OMP_GET_THREADS_NUMBER();
338 
339  //start index
340  tIndex start=threadId*p/nThreads;
341 
342  //end index
343  tIndex end=(threadId+1)*p/nThreads;
344 
345  //iterator on R values at start
346  auto iRi=iR;
347  iRi+=start;
348 
349  //iterator on cpy values at start
350  auto iXi=iX;
351  iXi+=start;
352 
353  //iterator on cpy values at end
354  auto eXi=iX;
355  eXi+=end;
356 
357  //copy the values of cpyA into aValue for element in [start,end[
358  std::for_each(iXi,eXi,[&iRi](const auto& Xi) {(*iRi)=Xi;iRi++;});
359 
360  }//end parallel section
361  }
362 
363 
364 
370  template<typename Q>
371  inline static void Copy(const std::valarray<Q>& X,std::valarray<T>& R) {
372  Copy(X.size(),X,R);
373  }
379  template<typename Q>
380  inline static void Copy(const std::valarray<T>& X,std::valarray<T>& R) {
381  R=X;
382  }
383 
391  template<typename Q>
392  inline static void Copy(const tIndex& n,const std::valarray<Q>& X,std::valarray<T>& R) {
393  Copy(n,&X[0],R);
394  }
395 
403  template<typename Q>
404  inline static void Copy(const tIndex& n,const std::vector<Q>& X,std::valarray<T>& R) {
405  //resize R
406  tIndex p=functions_numeric::min(n,X.size());
407  if (R.size()!=p) R.resize(p);
408 
409  //get begin iterator of R
410  auto iR=std::ranges::begin(R);
411 
412  //get const begin iterator on X
413  auto iX=X.cbegin();
414 
415  OMP_PARALLEL_SHARED((p,iX,iR)) {//begin parallel section
416  // thread id
417  tInteger threadId=OMP_GET_THREAD_ID();
418 
419  // threads number
420  tInteger nThreads=OMP_GET_THREADS_NUMBER();
421 
422  //start index
423  tIndex start=threadId*p/nThreads;
424 
425  //end index
426  tIndex end=(threadId+1)*p/nThreads;
427 
428  //iterator on R values at start
429  auto iRi=iR;
430  iRi+=start;
431 
432  //iterator on cpy values at start
433  auto iXi=iX;
434  iXi+=start;
435 
436  //iterator on cpy values at end
437  auto eXi=iX;
438  eXi+=end;
439 
440  //copy the values of cpyA into aValue for element in [start,end[
441  std::for_each(iXi,eXi,[&iRi](const auto& Xi) {(*iRi)=Xi;iRi++;});
442 
443  }//end parallel section
444  }
445 
446 
454  inline static void Copy(const tIndex& n,const std::initializer_list<T>& X,std::valarray<T>& R) {
455  //resize R
456  tIndex p=functions_numeric::min(n,X.size());
457  if (R.size()!=p) R.resize(p);
458 
459  //get begin iterator of R
460  auto iR=std::ranges::begin(R);
461 
462  //get const begin iterator on X
463  auto iX=X.begin();
464 
465  OMP_PARALLEL_SHARED((p,iX,iR)) {//begin parallel section
466  // thread id
467  tInteger threadId=OMP_GET_THREAD_ID();
468 
469  // threads number
470  tInteger nThreads=OMP_GET_THREADS_NUMBER();
471 
472  //start index
473  tIndex start=threadId*p/nThreads;
474 
475  //end index
476  tIndex end=(threadId+1)*p/nThreads;
477 
478  //iterator on R values at start
479  auto iRi=iR;
480  iRi+=start;
481 
482  //iterator on cpy values at start
483  auto iXi=iX;
484  iXi+=start;
485 
486  //iterator on cpy values at end
487  auto eXi=iX;
488  eXi+=end;
489 
490  //copy the values of cpyA into aValue for element in [start,end[
491  std::for_each(iXi,eXi,[&iRi](const auto& Xi) {(*iRi)=Xi;iRi++;});
492 
493  }//end parallel section
494  }
502  inline static void Copy(const tIndex& n,std::initializer_list<T>&& X,std::valarray<T>& R) {
503  //resize R
504  tIndex p=functions_numeric::min(n,X.size());
505  if (R.size()!=p) R.resize(p);
506 
507  //get begin iterator of R
508  auto iR=std::ranges::begin(R);
509 
510  //get const begin iterator on X
511  auto iX=X.begin();
512 
513  OMP_PARALLEL_SHARED((p,iX,iR)) {//begin parallel section
514  // thread id
515  tInteger threadId=OMP_GET_THREAD_ID();
516 
517  // threads number
518  tInteger nThreads=OMP_GET_THREADS_NUMBER();
519 
520  //start index
521  tIndex start=threadId*p/nThreads;
522 
523  //end index
524  tIndex end=(threadId+1)*p/nThreads;
525 
526  //iterator on R values at start
527  auto iRi=iR;
528  iRi+=start;
529 
530  //iterator on cpy values at start
531  auto iXi=iX;
532  iXi+=start;
533 
534  //iterator on cpy values at end
535  auto eXi=iX;
536  eXi+=end;
537 
538  //copy the values of cpyA into aValue for element in [start,end[
539  std::for_each(iXi,eXi,[&iRi](const auto& Xi) {(*iRi)=Xi;iRi++;});
540 
541  }//end parallel section
542  }
543 
544 
551  template<typename Q>
552  requires functions_type::isArithmeticType<Q>
553  inline static void Copy(const tIndex& n,const Q* X,std::valarray<T>& R) {
554  R.setSize(n);
555 
556  //get begin iterator of R
557  auto iR=std::ranges::begin(R);
558 
559  OMP_PARALLEL_SHARED((n,X,iR)) {//begin parallel section
560  // thread id
561  tInteger threadId=OMP_GET_THREAD_ID();
562 
563  // threads number
564  tInteger nThreads=OMP_GET_THREADS_NUMBER();
565 
566  //start index
567  tIndex start=threadId*n/nThreads;
568 
569  //end index
570  tIndex end=(threadId+1)*n/nThreads;
571 
572  //iterator on R values at start
573  auto iRi=iR;
574  iRi+=start;
575 
576  //iterator on R values at end
577  auto iRe=iR;
578  iRe+=end;
579 
580  //iterator on X at start
581  const Q* iX=X+start;
582 
583 
584  //copy the values of cpyA into aValue for element in [start,end[
585  std::for_each(iRi,iRe,[&iX](const auto& Ri) {Ri=(*iX);iX++;});
586 
587  }//end parallel section
588 
589  }
590 
591 
592 
593  //initializer
594  //===========
595 
601  inline void initialize(const T& x) {
602  Initialize(x,this->getArray());
603  }
610  inline void Initialize(const T& x,std::valarray<T>& values) {
611  auto F=[&x](const auto &Ri){return x;};
612  this->transform(F);
613 
614  }
619  inline void uniformRandomize(const T& min,const T& max) {
620  UniformRandomize(min,max,this->getArray());
621  }
622 
623 
631  inline static void UniformRandomize(const T& min,const T& max,std::valarray<T>& values){
632  T alpha=(max-min)/RAND_MAX;
633 
634  //init the random data
635  auto iR=std::ranges::begin(values);
636 
637  //number of elements
638  tIndex n=values.size();
639 
640  OMP_PARALLEL_SHARED((alpha,n,min,iR)) {//begin parallel section
641 
642  // threads number
643  tInteger nThreads=OMP_GET_THREADS_NUMBER();
644 
645  // thread id
646  tInteger threadId=OMP_GET_THREAD_ID();
647 
648  tIndex start=0;
649 
650  //set random seed by process
651  tULLInt seed=0;
652  for(start=0;start<=threadId;start++) {
653  seed=std::rand();
654  }
655  std::srand(seed);
656 
657  //start index
658  start=threadId*n/nThreads;
659 
660  //end index
661  tIndex end=(threadId+1)*n/nThreads;
662 
663 
664 
665 
666  std::transform(iR+start,iR+end,
667  iR+start,[&alpha,&min](const auto& Ri) {
668  return alpha*std::rand()+min;
669  });
670 
671  //V3
672  // auto iRi=iR+start;
673  // auto iRe=iR+end;
674  // while (iRi!=iRe) {
675  // (*iRi)=alpha*F(drand)+min;
676  // iRi++;
677  // }
678 
679  }//end parallel section
680 
681  }
682 
683 
684  //compount assignement operator
685  //==============================
686 
690  inline OMP_ValArray<T>& operator+=(const T& v) {
691  auto F=[&v](const auto &x){return x+v;};
692  this->transform(F);
693  return (*this);
694  }
698  inline OMP_ValArray<T>& operator-=(const T& v) {
699  auto F=[&v](const auto& x){return x-v;};
700  transform(F);
701  return (*this);
702  }
703 
707  inline OMP_ValArray<T>& operator*=(const T& v) {
708  auto F=[&v](const auto &x){return x*v;};
709  this->transform(F);
710  return (*this);
711 
712  }
716  inline OMP_ValArray<T>& operator/=(const T& v) {
717  if (fabs(v)<std::numeric_limits<T>::epsilon()) {
718  throw CORE_Exception("core",
719  "OMP_ValArray::/=("+std::to_string(v)+")",
720  "division by zero");
721  }
722  auto F=[&v](const auto &x){return x/v;};
723  this->transform(F);
724  return (*this);
725  }
726 
727 
728  //integer type compond operators
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 
742  inline OMP_ValArray<T>& operator&=(const T& v) requires functions_type::isIntegerType<T>{
743  auto F=[&v](const auto &x){return x&v;};
744  this->transform(F);
745  return (*this);
746  }
747 
751  inline OMP_ValArray<T>& operator|=(const T& v) requires functions_type::isIntegerType<T> {
752  auto F=[&v](const auto &x){return x|v;};
753  this->transform(F);
754  return (*this);
755  }
756 
760  inline OMP_ValArray<T>& operator^=(const T& v) requires functions_type::isIntegerType<T> {
761  auto F=[&v](const auto &x){return x^v;};
762  this->transform(F);
763  return (*this);
764  }
768  inline OMP_ValArray<T>& operator<<=(const T& v) requires functions_type::isIntegerType<T> {
769  auto F=[&v](const auto &x){return x<<v;};
770  this->transform(F);
771  return (*this);
772  }
776  inline OMP_ValArray<T>& operator>>=(const T& v) requires functions_type::isIntegerType<T> {
777  auto F=[&v](const auto &x){return x>>v;};
778  this->transform(F);
779  return (*this);
780  }
781 
782  //class compount assignement operator
783  //-----------------------------------
789  template<typename Q,class I>
790  inline Self& operator+=(const CORE_Array<Q,I>& X) {
791  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
792  auto iX=X.cbegin();
793  auto iV=this->begin();
794  OMP_PARALLEL_SHARED((p,iX,iV)) {//begin parallel section
795  // thread id
796  tInteger threadId=OMP_GET_THREAD_ID();
797 
798  // threads number
799  tInteger nThreads=OMP_GET_THREADS_NUMBER();
800 
801  //start index
802  tIndex start=threadId*p/nThreads;
803 
804  //end index
805  tIndex end=(threadId+1)*p/nThreads;
806 
807  std::transform(iX+start,iX+end,
808  iV+start,
809  iV+start,[](const auto& Xi,const auto &Vi) {return Vi+Xi;});
810 
811 
812  }//end parallel section
813  return *this;
814  }
815 
816 
823  template<typename Q,class I>
824  inline Self& operator-=(const CORE_Array<Q,I>& X) {
825  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
826  auto iX=X.cbegin();
827  auto iV=this->begin();
828  OMP_PARALLEL_SHARED((p,iX,iV)) {//begin parallel section
829  // thread id
830  tInteger threadId=OMP_GET_THREAD_ID();
831 
832  // threads number
833  tInteger nThreads=OMP_GET_THREADS_NUMBER();
834 
835  //start index
836  tIndex start=threadId*p/nThreads;
837 
838  //end index
839  tIndex end=(threadId+1)*p/nThreads;
840 
841  std::transform(iX+start,iX+end,
842  iV+start,
843  iV+start,[](const auto& Xi,const auto &Vi) {return Vi-Xi;});
844 
845 
846  }//end parallel section
847  return (*this);
848  }
849 
856  template<typename Q,class I>
857  inline Self& operator*=(const CORE_Array<Q,I>& X) {
858  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
859  auto iX=X.cbegin();
860  auto iV=this->begin();
861  OMP_PARALLEL_SHARED((p,iX,iV)) {//begin parallel section
862  // thread id
863  tInteger threadId=OMP_GET_THREAD_ID();
864 
865  // threads number
866  tInteger nThreads=OMP_GET_THREADS_NUMBER();
867 
868  //start index
869  tIndex start=threadId*p/nThreads;
870 
871  //end index
872  tIndex end=(threadId+1)*p/nThreads;
873 
874  std::transform(iX+start,iX+end,
875  iV+start,
876  iV+start,[](const auto& Xi,const auto &Vi) {return Vi*Xi;});
877 
878 
879  }//end parallel section
880  return (*this);
881  }
888  template<typename Q,class I>
889  inline Self& operator/=(const CORE_Array<Q,I>& X) {
890  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
891  Q eps=std::numeric_limits<Q>::epsilon();
892  auto iX=X.cbegin();
893  auto iV=this->begin();
894  OMP_PARALLEL_SHARED((p,eps,iX,iV)) {//begin parallel section
895  // thread id
896  tInteger threadId=OMP_GET_THREAD_ID();
897 
898  // threads number
899  tInteger nThreads=OMP_GET_THREADS_NUMBER();
900 
901  //start index
902  tIndex start=threadId*p/nThreads;
903 
904  //end index
905  tIndex end=(threadId+1)*p/nThreads;
906 
907  std::transform(iX+start,iX+end,
908  iV+start,
909  iV+start,[&eps](const auto& Xi,const auto &Vi) {
910  if (fabs(Xi)<eps) throw CORE_Exception("openmp",
911  "OMP_ValArray/=",
912  "division by 0");
913  return Vi/Xi;});
914 
915 
916  }//end parallel section
917  return (*this);
918  }
919 
920 
921  //transform methods
922  //=================
927  template<typename LambdaFct>
928  inline void transform(LambdaFct&& F) {
929  Transform(F,(*this));
930  }
931 
937  template<typename LambdaFct>
938  inline void transform(LambdaFct&& F,
939  const CORE_Array<T,Self>& X) {
940  Transform(F,X,(*this));
941  }
948  template<typename LambdaFct>
949  inline void transform(LambdaFct&& F,
950  const CORE_Array<T,Self>& X,
951  const CORE_Array<T,Self>& Y) {
952  Transform(F,X,Y,*this);
953  }
954 
955 
961  template<typename LambdaFct>
962  static inline void Transform(LambdaFct&& F,
963  Self& X) {
964 
965  //size of all the array
966  tIndex n=X.getSize();
967 
968 
969 
970  //get the cont begin iterator of X
971  auto iX=X.cbegin();
972 
973 
974  //get the begin iterator of R
975  auto iR=X.begin();
976 
977 
978 
979  //init the random data
980  OMP_PARALLEL_SHARED((n,iX,iR,F)) {//begin parallel section
981 
982  // thread id
983  tInteger threadId=OMP_GET_THREAD_ID();
984 
985  //threads number
986  tInteger nThreads=OMP_GET_THREADS_NUMBER();
987 
988  tInteger start=threadId*n/nThreads;
989  tInteger end=(threadId+1)*n/nThreads;
990 
991  std::transform(iX+start,iX+end,
992  iR+start,F);
993 
994 
995  }//end parallel section
996  }
997 
998 
999 
1006  template<typename LambdaFct>
1007  static inline void Transform(LambdaFct&& F,
1008  const CORE_Array<T,Self>& X,
1009  Self& R) {
1010 
1011  //size of all the array
1012  tIndex n=X.getSize();
1013 
1014  //resize the result
1015  R.setSize(n);
1016 
1017 
1018 
1019 
1020  //get the cont begin iterator of X
1021  auto iX=X.cbegin();
1022 
1023 
1024  //get the begin iterator of R
1025  auto iR=R.begin();
1026 
1027 
1028 
1029  //init the random data
1030  OMP_PARALLEL_SHARED((n,iX,iR,F)) {//begin parallel section
1031 
1032  // thread id
1033  tInteger threadId=OMP_GET_THREAD_ID();
1034 
1035  //threads number
1036  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1037 
1038  tInteger start=threadId*n/nThreads;
1039  tInteger end=(threadId+1)*n/nThreads;
1040 
1041  std::transform(iX+start,iX+end,
1042  iR+start,F);
1043 
1044 
1045  }//end parallel section
1046  }
1047 
1048 
1056  template<typename LambdaFct>
1057  static inline void Transform(LambdaFct&& F,
1058  const CORE_Array<T,Self>& X,
1059  const CORE_Array<T,Self>& Y,
1060  Self& R) {
1061 
1062  //siez of all the array
1063  tIndex n=X.getSize();
1064 
1065  if (n!=Y.getSize())
1066  throw CORE_Exception("opemp",
1067  "OMP_ValArray::Transform(F,X,Y,R)",
1068  "X ("+std::to_string(X.getSize())+") & Y ("+std::to_string(Y.getSize())+") have not same size");
1069 
1070  R.setSize(n);
1071 
1072 
1073 
1074  //get the const begin iterator of X
1075  auto iX=X.cbegin();
1076 
1077  //get the const begin iterator of Y
1078  auto iY=Y.cbegin();
1079 
1080 
1081  //get the begin iterator of R
1082  auto iR=R.begin();
1083 
1084 
1085 
1086 
1087 
1088  //init the random data
1089  OMP_PARALLEL_SHARED((n,iX,iY,iR,F)) {//begin parallel section
1090 
1091  // thread id
1092  tInteger threadId=OMP_GET_THREAD_ID();
1093  //threads number
1094  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1095 
1096  tInteger start=threadId*n/nThreads;
1097  tInteger end=(threadId+1)*n/nThreads;
1098 
1099  std::transform(iX+start,iX+end,
1100  iY+start,
1101  iR+start,F);
1102 
1103 
1104  }//end parallel section
1105  }
1106 
1110  inline T norm2() const {
1111  tIndex n=this->getSize();
1112  auto iV=this->cbegin();
1113 
1114  T norm2=0;
1115  OMP_PARALLEL_SHARED_REDUCTION((n,iV),(+:norm2)) {//begin parallel section
1116  // thread id
1117  tInteger threadId=OMP_GET_THREAD_ID();
1118 
1119  // threads number
1120  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1121 
1122  //start index
1123  tIndex start=threadId*n/nThreads;
1124 
1125  //end index
1126  tIndex end=(threadId+1)*n/nThreads;
1127 
1128 
1129  norm2=0;
1130  std::for_each(iV+start,iV+end,[&norm2](const auto &Vi){norm2+=Vi*Vi;});
1131 
1132 
1133 
1134  }//end parallel section
1135 
1136  return norm2;
1137  }
1138 
1141  inline void normalize() {
1142  auto iV=this->begin();
1143  T inorm=norm2();
1144 
1145  if (inorm>std::numeric_limits<T>::epsilon()) {
1146  inorm=1./inorm;
1147  tIndex n=this->getSize();
1148  auto iV=this->cbegin();
1149  OMP_PARALLEL_SHARED((n,inorm,iV)) {//begin parallel section
1150  // thread id
1151  tInteger threadId=OMP_GET_THREAD_ID();
1152 
1153  // threads number
1154  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1155 
1156  //start index
1157  tIndex start=threadId*n/nThreads;
1158 
1159  //end index
1160  tIndex end=(threadId+1)*n/nThreads;
1161 
1162  std::transform(iV+start,iV+end,iV+start,
1163  iV+start,[&inorm](const auto& Vi){return Vi*inorm;});
1164 
1165 
1166 
1167  }//end parallel section
1168 
1169  }
1170  }
1171 
1179  template<typename Q,class I>
1180  inline void axpy(const Q& alpha, const CORE_Array<Q,I>& X,const T& beta) {
1181  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
1182 
1183  auto iX=X.cbegin();
1184  auto iY=this->begin();
1185  OMP_PARALLEL_SHARED((p,alpha,beta,iX,iY)) {//begin parallel section
1186 
1187  // thread id
1188  tInteger threadId=OMP_GET_THREAD_ID();
1189  // threads number
1190  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1191 
1192  //start index of the loop
1193  tIndex start=threadId*p/nThreads;
1194 
1195  //end index of the loop
1196  tIndex end=(threadId+1)*p/nThreads;
1197 
1198 
1199  std::transform(iX+start,iX+end,
1200  iY+start,
1201  iY+start,[&alpha,&beta](const auto& Xi,const auto& Yi) {return beta*Yi+alpha*Xi;});
1202  }
1203  }
1204 
1205  //Data consistency
1206  //=================
1211  inline tBoolean isNANContained() const {
1212  tBoolean isnan=false;//0
1213  auto iV=this->cbegin();
1214  tIndex n=this->getSize();
1215  OMP_PARALLEL_SHARED_REDUCTION((n,iV),(max:isnan)) {//begin parallel section
1216 
1217  // thread id
1218  tInteger threadId=OMP_GET_THREAD_ID();
1219 
1220  // threads number
1221  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1222 
1223  //start index
1224  tInteger start=threadId*n/nThreads;
1225 
1226  //end index
1227  tInteger end=(threadId+1)*n/nThreads;
1228 
1229  isnan=(std::find_if(iV+start,iV+end,[](const auto& Vi) {return std::isnan(Vi);})!=iV+end);
1230 
1231 
1232  }//end parallel section
1233 
1234  return isnan;
1235  }
1236 
1237 
1238 
1239 
1240 
1241  //algebric method
1242  //===================
1243 
1244 
1245 
1253  template<typename Q,class I>
1254  inline T& scalarProduct(const CORE_Array<Q,I>& X,T& s) const {
1255  tIndex p=functions_numeric::min(this->getSize(),X.getSize());
1256  auto iV=this->cbegin();
1257  auto iX=X.cbegin();
1258  s=0;
1259  OMP_PARALLEL_SHARED_REDUCTION((p,iX,iV),(+:s)) {//begin parallel section
1260 
1261  // thread id
1262  tInteger threadId=OMP_GET_THREAD_ID();
1263 
1264  // threads number
1265  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1266 
1267  //start index
1268  tInteger start=threadId*p/nThreads;
1269 
1270  //end index
1271  tInteger end=(threadId+1)*p/nThreads;
1272 
1273  //start iterator on X
1274  auto iXi=iX+start;
1275 
1276  s=0;
1277  std::for_each(iV+start,iV+end,[&s,&iXi](const auto& Vi) {s+=Vi*(*iXi);iXi++;});
1278 
1279 
1280  }//end parallel section
1281  return s;
1282  }
1283 
1287  inline void sum(T& s) const {
1288  auto iV=this->cbegin();
1289  tIndex n=this->getSize();
1290  s=0;
1291  OMP_PARALLEL_SHARED_REDUCTION((n,iV),(+:s)) {//begin parallel section
1292 
1293  // thread id
1294  tInteger threadId=OMP_GET_THREAD_ID();
1295 
1296  // threads number
1297  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1298 
1299  //start index
1300  tInteger start=threadId*n/nThreads;
1301 
1302  //end index
1303  tInteger end=(threadId+1)*n/nThreads;
1304 
1305 
1306  s=0;
1307  std::for_each(iV+start,iV+end,[&s](const auto& Vi) {s+=Vi;});
1308 
1309 
1310  }//end parallel section
1311 
1312  }
1313 
1314 
1318  inline void prod(T& p) const {
1319  auto iV=this->cbegin();
1320  tIndex n=this->getSize();
1321  p=1;
1322  OMP_PARALLEL_SHARED_REDUCTION((n,iV),(*:p)) {//begin parallel section
1323 
1324  // thread id
1325  tInteger threadId=OMP_GET_THREAD_ID();
1326 
1327  // threads number
1328  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1329 
1330  //start index
1331  tInteger start=threadId*n/nThreads;
1332 
1333  //end index
1334  tInteger end=(threadId+1)*n/nThreads;
1335 
1336 
1337  p=1;
1338  std::for_each(iV+start,iV+end,[&p](const auto& Vi) {p*=Vi;});
1339 
1340 
1341  }//end parallel section
1342 
1343 
1344  }
1345 
1346 
1351  inline tReal l2Norm2() const {
1352  return L2Distance2(0,null,this->getArray());
1353  }
1354 
1362  template<typename Q,class I>
1363  inline tReal l2Distance2(const CORE_Array<Q,I>& X) const {
1364  return L2Distance2(X.getSize(),X.getValues(),this->getArray());
1365  }
1366 
1367 
1368 
1377  template<typename Q>
1378  inline static tReal L2Distance2(const tIndex& nX,const Q* Xs,
1379  const std::valarray<T>& Y) {
1380 
1381 
1382  //d2=\sum_i |Xi-Yi|^2
1383  tReal d2=0;
1384 
1385  //size of common loop
1386  tIndex n=functions_numeric::min(nX,Y.size());
1387 
1388  auto Ys=std::cbegin(Y);
1389 
1390  OMP_PARALLEL_SHARED_REDUCTION((n,Xs,Ys),(+:d2)) {
1391 
1392  //third id
1393  tInteger threadId=OMP_GET_THREAD_ID();
1394  // number of threads
1395  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1396 
1397  //start index
1398  tIndex start=threadId*n/nThreads;
1399  //end index
1400  tIndex end=(threadId+1)*n/nThreads;
1401 
1402 
1403 
1404  const Q *iX=Xs+start;
1405 
1406  //temporary value
1407  tReal tmp;
1408 
1409  d2=0;
1410  std::for_each(Ys+start,Ys+end,
1411  [&d2,&iX,&tmp](const auto& Yi) {
1412  tmp=(*iX)-Yi;
1413  d2+=tmp*tmp;
1414  iX++;
1415  }//end loop on X & Y
1416  );
1417  }//end parallel section
1418 
1419  tIndex p=nX-n;
1420  if (p>0) {
1421  OMP_PARALLEL_SHARED_REDUCTION((p,n,Xs),(+:d2)) {
1422 
1423  //third id
1424  tInteger threadId=OMP_GET_THREAD_ID();
1425  // number of threads
1426  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1427 
1428  //start index
1429  tIndex start=threadId*p/nThreads;
1430  //end index
1431  tIndex end=(threadId+1)*p/nThreads;
1432 
1433  //iterator on start
1434  const Q *iX=Xs+n+start;
1435  //iterator on end
1436  const Q *iXe=Xs+n+end;
1437 
1438  while (iX!=iXe) {
1439  d2+=(*iX)*(*iX);
1440  iX++;
1441  }
1442  }//end parallel section
1443  }//and loop on X
1444 
1445 
1446 
1447  p=Y.size()-n;
1448  if (p>0) {
1449  OMP_PARALLEL_SHARED_REDUCTION((p,n,Ys),(+:d2)) {
1450 
1451  //third id
1452  tInteger threadId=OMP_GET_THREAD_ID();
1453  // number of threads
1454  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1455 
1456  //start index
1457  tIndex start=threadId*p/nThreads;
1458  //end index
1459  tIndex end=(threadId+1)*p/nThreads;
1460 
1461  std::for_each(Ys+n+start,Ys+n+end,
1462  [&d2](const auto& Yi) {d2+=Yi*Yi;});
1463 
1464  }//end parallel section
1465  }//and loop on Y
1466 
1467  return d2;
1468  }
1469 
1470 
1475  inline tReal linfNorm(tIndex& imax) const {
1476  return LinfDistance(0,(T*)null,this->getArray(),imax);
1477  }
1478 
1486  template<typename Q,class I>
1487  inline tReal linfDistance(const CORE_Array<Q,I>& X,tIndex& imax) const {
1488  return LinfDistance(X.getSize(),X.getValues(),this->getArray(),imax);
1489  }
1490 
1491 
1492 
1501  template<typename Q>
1502  inline static tReal LinfDistance(const tIndex& nX,const Q* Xs,
1503  const std::valarray<T>& Y,
1504  tIndex& imax) {
1505 
1506 
1507 
1508  //common size
1509  tIndex n=functions_numeric::min(nX,Y.size());
1510 
1511 
1512  std::pair<tIndex,T> S(0,0);
1513 
1514  auto Ys=std::cbegin(Y);
1515 
1516  //common loop
1517  OMP_PARALLEL_SHARED_REDUCTION((n,Ys,Xs), (argrmax:S)) {
1518  // thread id
1519  tInteger threadId=OMP_GET_THREAD_ID();
1520  // threads number
1521  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1522 
1523  //start index
1524  tIndex start=threadId*n/nThreads;
1525  //end index
1526  tIndex end=(threadId+1)*n/nThreads;
1527 
1528 
1529 
1530  //begin iterator on start
1531  const Q *iX=Xs+start;
1532 
1533  //start index
1534  tIndex i=start;
1535  //local variable
1536  tReal norm2;
1537  std::for_each(Ys+start,Ys+end,
1538  [&i,&norm2,&iX,&S](const auto& Yi) {
1539  norm2=Yi-(*iX);
1540  norm2*=norm2;
1541  if (S.second<norm2) {
1542  S.second=norm2;
1543  S.first=i;
1544  }
1545  iX++;
1546  i++;
1547  });
1548  }//end parallel
1549 
1550  tIndex p=nX-n;
1551  if (p>0) {
1552  OMP_PARALLEL_SHARED_REDUCTION((n,p,Xs), (argrmax:S)) {
1553  // thread id
1554  tInteger threadId=OMP_GET_THREAD_ID();
1555  // threads number
1556  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1557 
1558  //start index
1559  tIndex start=threadId*p/nThreads;
1560  //end index
1561  tIndex end=(threadId+1)*p/nThreads;
1562 
1563 
1564  //begin iterator on start
1565  const Q*iX=Xs+n+start;
1566  //begin iterator on end
1567  const Q *iXe=Xs+n+end;
1568 
1569  //start index
1570  tIndex i=n+start;
1571  //local variable
1572  tReal norm2;
1573  while (iX!=iXe) {
1574  norm2=(*iX)*(*iX);
1575  if (S.second<norm2) {
1576  S.second=norm2;
1577  S.first=i;
1578  }
1579  iX++;
1580  i++;
1581  }
1582  }//end parallel
1583 
1584  }//end loop on X
1585  p=Y.size()-n;
1586  if (p>0) {
1587  OMP_PARALLEL_SHARED_REDUCTION((n,p,Ys), (argrmax:S)) {
1588  // thread id
1589  tInteger threadId=OMP_GET_THREAD_ID();
1590  // threads number
1591  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1592 
1593  //start index
1594  tIndex start=threadId*p/nThreads;
1595  //end index
1596  tIndex end=(threadId+1)*p/nThreads;
1597 
1598  //start index
1599  tIndex i=n+start;
1600  //module of Y
1601  tReal mod2;
1602  std::for_each(Ys+n+start,Ys+n+end,
1603  [&i,&S,&mod2](const auto& Yi) {
1604  mod2=Yi*Yi;
1605  i++;
1606  if (S.second<mod2) {
1607  S.second=mod2;
1608  S.first=i;
1609  }});
1610 
1611  }//end parallel
1612 
1613  }//end loop on Y
1614 
1615 
1616  imax=S.first;
1617  return sqrt(S.second);
1618 
1619  }
1620 
1621 
1622 
1623 
1624 
1625 
1626  //ordered methods
1627  //===============
1628 
1632  inline void min(T& minV) const requires functions_type::isOrderedType<T> {
1633  auto iV=this->cbegin();
1634  tIndex n=this->getSize();
1635  minV=0;
1636  if (n==0) return;
1637  minV=(*iV);
1638  OMP_PARALLEL_SHARED_REDUCTION((n,iV),(min:minV)) {//begin parallel section
1639 
1640  // thread id
1641  tInteger threadId=OMP_GET_THREAD_ID();
1642 
1643  // threads number
1644  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1645 
1646  //start index
1647  tInteger start=threadId*n/nThreads;
1648 
1649  //end index
1650  tInteger end=(threadId+1)*n/nThreads;
1651 
1652  if (end>start) {
1653  auto iVs=iV+start;
1654  minV=*(iVs);
1655  std::for_each(iVs,iV+end,[&minV](const auto& Vi) {minV=(minV<Vi)?minV:Vi;});
1656  }
1657 
1658  }//end parallel section
1659 
1660  }
1661 
1662 
1666  inline void max(T& maxV) const requires functions_type::isOrderedType<T> {
1667  auto iV=this->cbegin();
1668  tIndex n=this->getSize();
1669  maxV=0;
1670  if (n==0) return;
1671  maxV=(*iV);
1672  OMP_PARALLEL_SHARED_REDUCTION((n,iV),
1673  (max:maxV)) {//begin parallel section
1674 
1675  // thread id
1676  tInteger threadId=OMP_GET_THREAD_ID();
1677 
1678  // threads number
1679  tInteger nThreads=OMP_GET_THREADS_NUMBER();
1680 
1681  //start index
1682  tInteger start=threadId*n/nThreads;
1683 
1684  //end index
1685  tInteger end=(threadId+1)*n/nThreads;
1686 
1687  if (end>start) {
1688  auto iVs=iV+start;
1689  maxV=*(iVs);
1690  std::for_each(iVs,iV+end,[&maxV](const auto& Vi) {maxV=(maxV>Vi)?maxV:Vi;});
1691  }
1692 
1693  }//end parallel section
1694 
1695  }
1696 
1697 
1698 
1702  inline void directionalSort(const tUChar& order) requires functions_type::isOrderedType<T>{
1703  switch(order) {
1704  case 'i':
1705  std::sort(this->begin(),this->end(),std::less<T>());
1706  break;
1707  case 'd':
1708  std::sort(this->begin(),this->end(),std::greater<T>());
1709  break;
1710  }
1711 
1712  }
1713 
1714 };
1715 
1716 
1717 
1719 
1723 
1724 
1726 
1729 
1731 
1732 
1733 #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 a std::valarray object with implementa...
Definition: CORE_ValArray.h:70
constexpr auto cbegin() const
return begin iterator for reading
Definition: CORE_ValArray.h:199
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_ValArray.h:126
tIndex getSize() const
return the size of the array for writing
Definition: CORE_ValArray.h:147
auto end()
return end iterator for writing
Definition: CORE_ValArray.h:217
auto begin()
return begin iterator for writing
Definition: CORE_ValArray.h:211
std::valarray< T > & getArray()
get the array
Definition: CORE_ValArray.h:257
this class describes a standart arithmetic array type implemented with a std::valarray object of type...
Definition: OMP_ValArray.h:19
OMP_ValArray(const tIndex &n)
build an instance of class of size n
Definition: OMP_ValArray.h:38
static CORE_UniquePointer< Self > New()
return a unique pointer of the class
Definition: OMP_ValArray.h:75
Self & operator=(Self &&values)
build an array by a copy of c (in mirror with the copy operator)
Definition: OMP_ValArray.h:157
Self & operator=(const CORE_Array< Q, I1 > &values)
build an array by a copy of c
Definition: OMP_ValArray.h:168
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_ValArray.h:949
void copy(const CORE_ValArray< Q, I > &X)
copy the container
Definition: OMP_ValArray.h:217
static tReal LinfDistance(const tIndex &nX, const Q *Xs, const std::valarray< T > &Y, tIndex &imax)
compute the index of the array where the module of the difference between X & Y is max
Definition: OMP_ValArray.h:1502
Self & operator=(const std::array< T, N > &values)
build an array by a copy of c
Definition: OMP_ValArray.h:126
requires static functions_type::isArithmeticType< Q > void Copy(const tIndex &n, const Q *X, std::valarray< T > &R)
copy the n values of a pointers array
Definition: OMP_ValArray.h:553
static void Copy(const tIndex &n, const std::valarray< Q > &X, std::valarray< T > &R)
copy the the n first values of a valarray
Definition: OMP_ValArray.h:392
void axpy(const Q &alpha, const CORE_Array< Q, I > &X, const T &beta)
compute This=beta.This+ alpha .X
Definition: OMP_ValArray.h:1180
static void Copy(const tIndex &n, const std::vector< Q > &X, std::valarray< T > &R)
copy the the n first values of an initializer
Definition: OMP_ValArray.h:404
static void Copy(const std::valarray< T > &X, std::valarray< T > &R)
copy 2 std::valarray with same type : no parallelization : faster with the intrinsect method
Definition: OMP_ValArray.h:380
Self & operator=(const CORE_Array< Q, I1 > &&values)
build an array by a copy of c (in mirror with the copy operator)
Definition: OMP_ValArray.h:178
virtual ~OMP_ValArray()
destroy an instance of class
Definition: OMP_ValArray.h:48
Self & operator=(const std::initializer_list< T > &values)
build an array by a copy of c
Definition: OMP_ValArray.h:109
Self & operator=(const Self &values)
build an array by a copy of c
Definition: OMP_ValArray.h:150
void normalize()
normalize the array
Definition: OMP_ValArray.h:1141
T norm2() const
compute the norm 2 of the array
Definition: OMP_ValArray.h:1110
Self & operator=(const std::valarray< T > &values)
build an array by a copy of c
Definition: OMP_ValArray.h:135
tReal linfNorm(tIndex &imax) const
compute the Linf-norm of this
Definition: OMP_ValArray.h:1475
void sum(T &s) const
return the sum of all the elements
Definition: OMP_ValArray.h:1287
void initialize(const T &x)
initialize the array to the value x
Definition: OMP_ValArray.h:601
OMP_ValArray< T > & operator*=(const T &v)
multiplicator operator
Definition: OMP_ValArray.h:707
T & scalarProduct(const CORE_Array< Q, I > &X, T &s) const
return the scalar product
Definition: OMP_ValArray.h:1254
Self & operator/=(const CORE_Array< Q, I > &X)
array divisor operator
Definition: OMP_ValArray.h:889
OMP_ValArray< T > & operator-=(const T &v)
sub operator
Definition: OMP_ValArray.h:698
void copy(Self &&cpy)
copy the conatiner : mv is destroyed after this
Definition: OMP_ValArray.h:243
void copy(CORE_ValArray< Q, I > &&X)
copy the conatiner : mv is destroyed after this
Definition: OMP_ValArray.h:227
void Initialize(const T &x, std::valarray< T > &values)
initialize the array to the value x
Definition: OMP_ValArray.h:610
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: OMP_ValArray.h:64
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: OMP_ValArray.h:1211
void copy(const tIndex &n, const Q *Vs)
initialize the array to the values of pointer of size n
Definition: OMP_ValArray.h:255
void transform(LambdaFct &&F)
transform the transform element in parallel to the lambda function Ti=F(const Ti)
Definition: OMP_ValArray.h:928
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_ValArray.h:938
OMP_ValArray< T > & operator+=(const T &v)
add operator
Definition: OMP_ValArray.h:690
void copy(const tIndex &n, const std::array< Q, N > &Vs)
initialize the array to the values of array of size N
Definition: OMP_ValArray.h:283
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_ValArray.h:1007
void prod(T &p) const
return the produc of all the elements
Definition: OMP_ValArray.h:1318
Self & operator=(std::initializer_list< T > &&values)
build an array by a copy of c
Definition: OMP_ValArray.h:116
OMP_ValArray()
build an instance of class
Definition: OMP_ValArray.h:31
void copy(const Self &cpy)
copy the container
Definition: OMP_ValArray.h:236
tReal linfDistance(const CORE_Array< Q, I > &X, tIndex &imax) const
compute the square of L2-distance of this to X
Definition: OMP_ValArray.h:1487
void copy(const tIndex &n, const std::initializer_list< T > &Vs)
initialize the array to the values of list
Definition: OMP_ValArray.h:264
void uniformRandomize(const T &min, const T &max)
randomize the vector in [min,max]
Definition: OMP_ValArray.h:619
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_ValArray.h:1057
static void Copy(const tIndex &n, const std::initializer_list< T > &X, std::valarray< T > &R)
copy the the n first values of an initializer
Definition: OMP_ValArray.h:454
OMP_ValArray< T > & operator/=(const T &v)
divisor operator
Definition: OMP_ValArray.h:716
static void UniformRandomize(const T &min, const T &max, std::valarray< T > &values)
generate a random val array
Definition: OMP_ValArray.h:631
void copy(const tIndex &n, const std::vector< Q > &Vs)
initialize the array to the values of vector
Definition: OMP_ValArray.h:304
static tReal L2Distance2(const tIndex &nX, const Q *Xs, const std::valarray< T > &Y)
compute the square of L2 distance of X to Y
Definition: OMP_ValArray.h:1378
void copy(const tIndex &n, const std::valarray< Q > &Vs)
initialize the array to the values of val array
Definition: OMP_ValArray.h:294
Self & operator%=(const T &v) requires functions_type
modulo operator
Definition: OMP_ValArray.h:733
Self & operator-=(const CORE_Array< Q, I > &X)
array sub operator
Definition: OMP_ValArray.h:824
tReal l2Norm2() const
compute the square of L2-norm of this
Definition: OMP_ValArray.h:1351
Self & operator=(const std::vector< T > &values)
build an array by a copy of c
Definition: OMP_ValArray.h:143
Self & operator*=(const CORE_Array< Q, I > &X)
array multiply operator
Definition: OMP_ValArray.h:857
static void Copy(const tIndex &n, std::initializer_list< T > &&X, std::valarray< T > &R)
copy the the n first values of an initializer
Definition: OMP_ValArray.h:502
static void Transform(LambdaFct &&F, Self &X)
transform the transform element with the lambda function Xi = F(const Xi)
Definition: OMP_ValArray.h:962
void copy(const CORE_Array< Q, I > &X)
copy the array
Definition: OMP_ValArray.h:197
void copy(CORE_Array< Q, I > &&X)
copy the array
Definition: OMP_ValArray.h:207
static void Copy(const std::valarray< Q > &X, std::valarray< T > &R)
copy 2 std::valarray with different type
Definition: OMP_ValArray.h:371
tReal l2Distance2(const CORE_Array< Q, I > &X) const
compute the square of L2-distance of this to X
Definition: OMP_ValArray.h:1363
Self & operator=(const T &v)
fill the values of the array with v
Definition: OMP_ValArray.h:102
void copy(const tIndex &n, std::initializer_list< T > &&Vs)
initialize the array to the values of list
Definition: OMP_ValArray.h:272
static void Copy(const CORE_Array< Q, I > &X, std::valarray< T > &R)
copy 2 std::valarray with different type
Definition: OMP_ValArray.h:320