C++ mpi module for stochmagnet_main Package
CORE_StdPtrArray.h
1 #ifndef CORE_StdPtrArray_H
2 #define CORE_StdPtrArray_H
3 
4 #include "CORE_PtrArray.h"
5 
6 //numeric functions headers
7 #include "functions_numeric.h"
8 
12 template <typename T>
13 class CORE_StdPtrArray : public CORE_PtrArray<T,CORE_StdPtrArray<T>> {
14 
15 private:
16 
17  //This class type
18  typedef CORE_StdPtrArray<T> Self;
19 
20 
21 
22  // CONSTRUCTORS
23 public:
27  }
31  copy(c);
32  }
33 
34 
35 
36  // DESTRUCTORS
39  virtual ~CORE_StdPtrArray() {
40  }
41 
42 
43 private:
44 
45 
46 
47 
48  //MEMORY
49  //=====
50 public:
58  virtual tMemSize getMemorySize() const override {
59  return sizeof(*this)+this->getContentsMemorySize();
60  }
61 
62  //allocation methods
63  //===================
64 
65 public:
69  static inline CORE_UniquePointer<Self> New() {
70  return CORE_UniquePointer<Self>(new Self(),CORE_Object::Delete());
71  }
72 
73 
74 
75 
76 
77  //accessor operators
78  //====================
79 
80 
81  //accessor iterator
82  //=================
83 
84 
85  //accessor methods
86  //=================
87 
88 
89  //assignment operators
90  //====================
94  inline Self& operator=(const T& v) {
95  initialize(v);
96  return *this;
97  }
101  inline Self& operator=(const std::initializer_list<T>& values) {
102  copy(values.size(),values);
103  return *this;
104  }
105 
109  inline Self& operator=(std::initializer_list<T>&& values) {
110  copy(values.size(),values);
111  return *this;
112  }
113 
119  template<size_t N,typename Q>
120  inline Self& operator=(const std::array<Q,N>& values) {
121  copy(values);
122  return *this;
123 
124  }
125 
130  template<typename Q>
131  inline Self& operator=(const std::valarray<Q>& values) {
132  copy(values);
133  return *this;
134  }
135 
140  template<typename Q>
141  inline Self& operator=(const std::vector<Q>& values) {
142  copy(values);
143  return *this;
144  }
148  inline Self& operator=(const Self& values) {
149  copy(values);
150  return *this;
151  }
155  inline Self& operator=(const Self&& values) {
156  copy(values);
157  return *this;
158  }
159 
165  template<typename Q,class I1>
166  inline Self& operator=(const CORE_Array<Q,I1>& values) {
167  copy(values);
168  return *this;
169  }
175  template<typename Q,class I1>
176  inline Self& operator=(const CORE_Array<Q,I1>&& values) {
177  copy(values);
178  return *this;
179  }
180 
181 
182 
183 
184 
185  //copy methods
186  //=============
187 
188 
194  template<typename Q,class I>
195  inline void copy(const CORE_Array<Q,I>& cpy) {
196  this->setSize(cpy.getSize());
197  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
198  }
199 
205  template<typename Q,class I>
206  inline void copy(CORE_Array<Q,I>&& cpy) {
207  this->setSize(cpy.getSize());
208  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
209  }
210 
215  template<class I>
216  inline void copy(const Self& cpy) {
217  this->setSize(cpy.getSize());
218  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
219  }
220 
225  template<class I>
226  inline void copy(Self&& cpy) {
227  this->setSize(cpy.getSize());
228  Copy(cpy.getSize(),cpy.getValues(),this->getValues());
229  }
230 
231 
237  template<typename Q>
238  inline void copy(const tIndex& n , const Q* Vs) {
239  this->setSize(n);
240  Copy(n,Vs,this->getValues());
241  }
242 
248  inline void copy(const tIndex& n,const std::initializer_list<T>& Vs) {
249  tIndex p=functions_numeric::min(n,Vs.size());
250  this->setSize(p);
251  Copy(p,Vs,this->getValues());
252  }
257  inline void copy(const tIndex& n,std::initializer_list<T>&& Vs) {
258  tIndex p=functions_numeric::min(n,Vs.size());
259  this->setSize(p);
260  Copy(p,Vs,this->getValues());
261  }
268  template<typename Q,size_t N>
269  inline void copy(const tIndex& n,const std::array<Q,N>& Vs) {
270  tIndex p=functions_numeric::min(n,N);
271  this->setSize(p);
272  Copy(p,Vs.getData(),this->getValues());
273  }
274 
280  template<typename Q>
281  inline void copy(const tIndex& n,const std::valarray<Q>& Vs) {
282  tIndex p=functions_numeric::min(n,Vs.size());
283  this->setSize(p);
284  Copy(p,&Vs[0],this->getValues());
285  }
291  template<typename Q>
292  inline void copy(const tIndex&n , const std::vector<Q>& Vs) {
293  tIndex p=functions_numeric::min(n,Vs.size());
294  this->setSize(p);
295  Copy(Vs.size(),Vs,this->getValues());
296  }
297 
298 
299  //static Copy
300  //===========
301 
302 
311  template<typename Q>
312  inline static void Copy(const tIndex& n,const Q* X,T* R) {
313 
314  //begin iterator of X
315  const Q* iX=X;
316 
317  //begin iterator of R
318  T* iR=R;
319 
320  if (sizeof(T)==sizeof(Q)) {
321  memcpy(iR,iX,sizeof(T)*n);
322  } else {
323  //en iterator of R
324  const T* iRe=R+n;
325 
326  //loop on values
327  while (iR!=iRe) {
328  (*iR)=(*iX);
329  iR++;
330  iX++;
331  }
332  }
333  }
334 
335 
344  template<typename Q>
345  inline static void Copy(const tIndex& n,const std::vector<Q>& X,T* R) {
346 
347  //begin iterator of R
348  T *iR=R;
349  //end iterator on R
350  T *iRe=R+n;
351 
352  //begin iterator of X
353  auto iX=X.cbegin();
354 
355  while (iR!=iRe) {
356  (*iR)=(*iX);
357  iR++;
358  iX++;
359  }
360  }
361 
369  inline static void Copy(const tIndex& n,std::initializer_list<T> X,T* R) {
370 
371 
372 
373  //begin iterator of R
374  T *iR=R;
375  //end iterator on R
376  T *iRe=R+n;
377 
378  //begin iterator of X
379  auto iX=X.begin();
380 
381  while (iR!=iRe) {
382  (*iR)=(*iX);
383  iR++;
384  iX++;
385  }
386  }
387 
388 
389  //initializers methods
390  //====================
391 
395  inline void initialize(const T& v) {
396  if (this->getSize()>0) {
397  if (fabs(v)<std::numeric_limits<T>::epsilon()) {
398  memset(this->getValues(),0,this->getSize()*sizeof(T));
399  } else {
400  //begin iterator of R=This
401  T *iR=this->getValues();
402  //begin iterator of R
403  const T* iRe=iR+this->getSize();
404 
405  //loop on values
406  while (iR!=iRe) {
407  (*iR)=v;
408  iR++;
409  }
410  }
411  }
412  }
413 
420  inline static void UniformRandomize(const T& min,const T& max,const tIndex& n,T* values){
421 
422  T alpha=(max-min)/RAND_MAX;
423 
424  //begin iterator
425  T* iV=values;
427  const T* iVe=values;
428  iVe+=n;
429 
430  //loops:
431  while (iV<iVe) {
432  (*iV)=alpha*((T)std::rand())+min;
433  iV++;
434  }
435  }
436 
437 
438 
443  inline void uniformRandomize(const T& min,const T& max) {
444  UniformRandomize(min,max,this->getSize(),this->getValues());
445  }
446 
447 
448  //compound assignement operators (+=,-=,*=,/=,^=...)
449  //===================================================
450 
451  //arithmetic type compound operators
452  //====================================
453 
457  inline Self& operator+=(const T& v) {
458  Add(v,this->getSize(),this->getValues());
459  return (*this);
460  }
464  inline Self& operator-=(const T& v) {
465  Add(-v,this->getSize(),this->getValues());
466  return (*this);
467 
468  }
469 
473  inline Self& operator*=(const T& v) {
474  Multiply(v,this->getSize(),this->getValues());
475  return (*this);
476 
477  }
481  inline Self& operator/=(const T& v) {
482  if (fabs(v)<std::numeric_limits<T>::epsilon()) {
483  throw CORE_Exception("core",
484  "CORE_StdPtrArray/=",
485  "division by 0");
486  }
487  Multiply(1./v,this->getSize(),this->getValues());
488  return (*this);
489  }
490 
491  //integer type compound operators
492  //===============================
496  inline Self& operator%=(const T& v) requires functions_type::isIntegerType<T> {
497  transform([&v](const auto& x){return x%v;});
498  return (*this);
499  }
500 
504  inline Self& operator&=(const T& v) requires functions_type::isIntegerType<T> {
505  transform([&v](const auto& x){return x&v;});
506  return (*this);
507  }
508 
512  inline Self& operator|=(const T& v) requires functions_type::isIntegerType<T> {
513  transform([&v](const auto& x){return x|v;});
514  return (*this);
515  }
516 
520  inline Self& operator^=(const T& v) requires functions_type::isIntegerType<T> {
521  transform([&v](const auto& x){return x^v;});
522  return (*this);
523  }
527  inline Self& operator<<=(const T& v) requires functions_type::isIntegerType<T> {
528  transform([&v](const auto& x){return x<<v;});
529  return (*this);
530  }
531 
535  inline Self& operator>>=(const T& v) requires functions_type::isIntegerType<T> {
536  transform([&v](const auto& x){return x>>v;});
537  return (*this);
538  }
539 
540  //class type compound operatos
541  //=============================
542 
546  template<typename Q,class I>
547  inline Self& operator+=(const CORE_Array<Q,I>& X) {
548  //min dimension
549  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
550  Add(p,X.getValues(),this->getValues());
551  return (*this);
552  }
553 
558  template<typename Q,class I>
559  inline Self& operator-=(const CORE_Array<Q,I>& X) {
560  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
561  Sub(p,X.getValues(),this->getValues());
562  return (*this);
563  }
568  template<typename Q,class I>
569  inline Self& operator*=(const CORE_Array<Q,I>& X) {
570  //min dimension
571  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
572  Multiply(p,X.getValues(),this->getValues());
573  return (*this);
574  }
575 
576 
581  template<typename Q,class I>
582  inline Self& operator/=(const CORE_Array<Q,I>& X) {
583  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
584  Divide(p,X.getValues(),this->getValues());
585  return (*this);
586  }
587 
588 
589  //transform methods
590  //=================
591 
592 
596  template<typename LambdaFct>
597  inline void transform(LambdaFct&& F) {
598  Transform(F,(*this));
599  }
600 
605  template<typename LambdaFct>
606  inline void transform(LambdaFct&& F,
607  const CORE_Array<T,Self>& X) {
608  Transform(F,X,(*this));
609  }
610 
616  template<typename LambdaFct>
617  inline void transform(LambdaFct&& F,
618  const CORE_Array<T,Self>& X,
619  const CORE_Array<T,Self>& Y) {
620 
621  Transform(F,X,Y,*this);
622  }
623 
628  template<typename LambdaFct>
629  static inline void Transform(LambdaFct&& F,
630  Self& R) {
631  std::transform(R.cbegin(),R.cend(),R.begin(),F);
632  }
633 
634 
640  template<typename LambdaFct>
641  static inline void Transform(LambdaFct&& F,
642  const CORE_Array<T,Self>& X,
643  Self& R) {
644  R.setSize(X.getsize());
645  std::transform(X.cbegin(),X.cend(),R.begin(),F);
646  }
647 
654  template<typename LambdaFct>
655  static inline void Transform(LambdaFct&& F,
656  const CORE_Array<T,Self>& X,
657  const CORE_Array<T,Self>& Y,
658  Self& R) {
659  if (X.getSize()!=Y.getSize())
660  throw CORE_Exception("core",
661  "CORE_StdPtrArray::Transform(F,X,Y,R)",
662  "X ("+std::to_string(X.getSize())+") & Y ("+std::to_string(Y.getSize())+") have not same size");
663 
664 
665  R.setSize(X.getSize());
666  std::transform(X.cbegin(),X.cend(),
667  Y.cbegin(),
668  R.begin(),F);
669  }
675  template<typename Q>
676  inline static void Add(const Q& X,const tIndex& n,T* R) {
677 
678  //iterator on R
679  T* iR=R;
680 
681  //iterator at end of R
682  const T* iRe=iR;iRe+=n;
683 
684  while (iR!=iRe) {//loop on index
685  (*iR)+=X;//This[i]+=X[i]
686  iR++;
687  }
688  }
694  template<typename Q>
695  inline static void Add(const tIndex& n,const Q* X,T* R) {
696 
697 
698  //iterator on X
699  const Q* iX=X;
700 
701  //iterator on R
702  T* iR=R;
703 
704  //iterator at end of R
705  const T* iRe=iR;iRe+=n;
706 
707  while (iR!=iRe) {//loop on index
708  (*iR)+=(*iX);//This[i]+=X[i]
709  iX++;
710  iR++;
711  }
712  }
719  template<typename Q>
720  inline static void Sub(const tIndex& n,const Q* X,T* R) {
721 
722 
723  //iterator on X
724  const Q* iX=X;
725 
726  //iterator on R
727  T* iR=R;
728 
729  //iterator at end of R
730  const T* iRe=iR;iRe+=n;
731 
732  while (iR!=iRe) {//loop on index
733  (*iR)-=(*iX);//This[i]-=X[i]
734  iX++;
735  iR++;
736  }
737  }
738 
739 
746  template<typename Q>
747  requires functions_type::isArithmeticType<Q>
748  inline static void Multiply(const Q& X,const tIndex& n,T* R) {
749 
750 
751 
752  //iterator on R
753  T* iR=R;
754 
755  //iterator at end of R
756  const T* iRe=iR;iRe+=n;
757 
758  while (iR!=iRe) {//loop on index
759  (*iR)*=X;//This[i]*=X
760  iR++;
761  }
762  }
763 
764 
771  template<typename Q>
772  inline static void Multiply(const tIndex& n,const Q* X,T* R) {
773 
774 
775  //iterator on X
776  const Q* iX=X;
777 
778  //iterator on R
779  T* iR=R;
780 
781  //iterator at end of R
782  const T* iRe=iR;iRe+=n;
783 
784  while (iR!=iRe) {//loop on index
785  (*iR)*=(*iX);//This[i]*=X[i]
786  iX++;
787  iR++;
788  }
789  }
796  template<typename Q>
797  inline static void Divide(const tIndex& n,const Q* X,T* R) {
798 
799  Q eps=std::numeric_limits<Q>::epsilon();
800 
801  //iterator on X
802  const Q* iX=X;
803 
804  //iterator on R
805  T* iR=R;
806 
807  //iterator at end of R
808  const T* iRe=iR;iRe+=n;
809 
810  while (iR!=iRe) {//loop on index
811  if (fabs(*iX)<eps) {
812  throw CORE_Excpetion("core","CORE_StdPtrArray::Divide(n,X,X)",
813  "division by 0 at index "+std::to_string(iX-X));
814  }
815  (*iR)/=(*iX);//This[i]*=X[i]
816  iX++;
817  iR++;
818  }
819  }
820 
821 
822 
823 
826  inline void normalize() {
827  Normalize(this->getSize(),this->getValues());
828  }
829 
835  template<typename Q, size_t N>
836  static void Normalize(std::array<Q,N>& a) {
837  Normalize(N,a.data());
838  }
843  static void Normalize(const tIndex& n,T* values) {
844  T norm=0;
845 
846  T* iV=values;//iterator on values
847 
848  const T* iVe=iV;//end iterator on values
849  iVe+=n;
850 
851  //loop on elements to compute norm
852  while (iV!=iVe) {norm+=(*iV)*(*iV);iV++;}
853 
854  //compute inverse of norm
855  if (norm>std::numeric_limits<T>::epsilon()) {
856  norm=sqrt(1./norm);
857  }
858  //update the values
859  iV=values;
860  while (iV!=iVe) {(*iV)*=norm;iV++;}
861 
862  }
863 
871  template<typename Q,class I>
872  inline void axpy(const Q& alpha, const CORE_Array<Q,I>& X,const T& beta) {
873  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
874  AXPY(p,alpha,X.getValues(),beta,this->getValues());
875  }
876 
877 
878 
887  template<typename Q>
888  inline void AXPY(const tIndex& n,const Q& alpha, const Q* X,const T& beta,T* Y) {
889  const Q* iX=X;
890  T *iY=Y;
891  const T *iYe=iY+n;
892  while (iY!=iYe) {
893  (*iY)=beta*(*iY)+alpha*(*iX);
894  iX++;
895  iY++;
896  }
897  }
898 
899 
900  //Data consistency
901  //=================
906  inline tBoolean isNANContained() const {
907  return IsNANContained(this->getSize(),this->getValues());
908  }
915  inline static tBoolean IsNANContained(const tIndex& n , const T* values) {
916  //loop on all values and stop the loop when the first nan value is found and return true
917  //return false otherwise
918  const T* iR=values;
919  const T* iRe=iR+n;
920  while (iR!=iRe) {
921  if (std::isnan(*iR)) return true;
922  iR++;
923  }
924  return false;
925  }
926 
927 
928  //algebric methods
929  //================
930 
931 
932 
936  inline void sum(T& s) const {
937  s=Sum(this->getSize(),this->getValues());
938  }
939 
940 
946  inline static T Sum(const tIndex& n,const T* values) {
947  const T* iR=values;
948  const T* iRe=iR+n;
949  T s=0;
950  while (iR!=iRe) {
951  s+=(*iR);
952  iR++;
953  }
954  return s;
955  }
956 
960  inline void prod(T& prod) const {
961  prod=Prod(this->getSize(),this->getValues());
962  }
968  inline static T Prod(const tIndex& n,const T* values) {
969  const T* iR=values;
970  const T* iRe=iR+n;
971  T p=1;
972  while (iR!=iRe) {
973  p*=(*iR);
974  iR++;
975  }
976  return p;
977  }
978 
979 
987  template<typename Q,class I>
988  inline T& scalarProduct(const CORE_Array<Q,I>& X,T& s) const {
989  tIndex n=functions_numeric::min(this->getSize(),X.getSize());
990  s=ScalarProduct(n,X.getValues(),this->getValues());
991  return s;
992  }
993 
994 
1002  template<typename Q>
1003  inline static T ScalarProduct(const tIndex n,const Q* X,const T* Y) {
1004 
1005  //s=\sum_{i=0}^{n-1} X[i].Y[i]
1006 
1007  T s=0;
1008 
1009  //iterator on Y
1010  const T* iY=Y;
1011  //iterator on X
1012  const Q* iX=X;
1013  //ietrator at end of X
1014  const Q* iXe=iX;iXe+=n;
1015 
1016  while (iX!=iXe) {
1017  s+=(*iX)*(*iY);
1018  iX++;
1019  iY++;
1020  }
1021 
1022  return s;
1023  }
1024 
1029  inline tReal l2Norm2() const {
1030  return L2Distance2(0,(T*)null,this->getSize(),this->getValues());
1031  }
1039  template<typename Q,class I>
1040  inline tReal l2Distance2(const CORE_Array<Q,I>& X) const {
1041  return L2Distance2(X.getSize(),X.getValues(),this->getSize(),this->getValues());
1042  }
1047  inline tReal linfDistance(tIndex& imax) const {
1048  return LinfDistance(0,(T*)null,
1049  this->getSize(),this->getValues(),
1050  imax);
1051  }
1060  template<typename Q,class I>
1061  inline tReal linfDistance(const CORE_Array<Q,I>& X,tIndex& imax) const {
1062  return LinfDistance(X.getSize(),X.getValues(),
1063  this->getSize(),this->getValues(),
1064  imax);
1065  }
1066 
1076  template<typename Q>
1077  inline static tReal L2Distance2(const tIndex& nX,const Q* Xs,
1078  const tIndex& nY,const T* Ys) {
1079  tIndex p=functions_numeric::min(nX,nY);
1080  tReal s=0;
1081  const Q* iX =Xs;
1082  const Q* iXe=Xs+p;
1083  const T* iY =Ys;
1084  tReal tmp;
1085  //s+=|X_i-Y_i|^2 i in [0,p[
1086  while (iX!=iXe) {
1087  tmp=(*iX)-(*iY);
1088  s+=tmp*tmp;
1089  //next index
1090  iX++;
1091  iY++;
1092  }
1093  //s+=|X_i|^2 i in [p,nX[
1094  iXe=Xs+nX;
1095  while (iX!=iXe) {
1096  s=(*iX)*(*iX);
1097  //next index
1098  iX++;
1099  }
1100 
1101  //s+=|Y_i|^2 i in [p,nY[
1102  const T* iYe=Ys+nY;
1103  while (iY!=iYe) {
1104  s=(*iY)*(*iY);
1105  //next index
1106  iY++;
1107  }
1108  return s;
1109  }
1110 
1120  template<typename Q>
1121  inline static tReal LinfDistance(const tIndex& nX,const Q* Xs,
1122  const tIndex& nY,const T* Ys,
1123  tIndex& imax) {
1124  tIndex p=functions_numeric::min(nX,nY);
1125 
1126  tReal s=0;
1127  imax=0;
1128  tIndex i=0;
1129  const Q* iX =Xs;
1130  const Q* iXe=Xs+p;
1131  const T* iY =Ys;
1132  tReal tmp;
1133  //s+=|X_i-Y_i|^2 i in [0,p[
1134  while (iX!=iXe) {
1135  tmp=std::fabs((*iX)-(*iY));
1136  if (tmp>s) {
1137  s=tmp;
1138  imax=i;
1139  }
1140  //next index
1141  iX++;
1142  iY++;
1143  i++;
1144  }
1145  //s+=|X_i|^2 i in [p,nX[
1146  iXe=Xs+nX;
1147  while (iX!=iXe) {
1148  tmp=std::fabs(*iX);
1149  if (tmp>s) {
1150  s=tmp;
1151  imax=i;
1152  }
1153  //next index
1154  iX++;
1155  i++;
1156  }
1157 
1158  //s+=|Y_i|^2 i in [p,nY[
1159  const T* iYe=Ys+nY;
1160  while (iY!=iYe) {
1161  tmp=std::fabs(*iY);
1162  if (tmp>s) {
1163  s=tmp;
1164  imax=i;
1165  }
1166  //next index
1167  iY++;
1168  i++;
1169  }
1170  return s;
1171  }
1172 
1173 
1174  //ordered type methods
1175  //=======================
1176 
1180  inline void min(T& m) const requires functions_type::isOrderedType<T> {
1181  m=Min(this->getSize(),this->getValues());
1182  }
1188  inline static T Min(const tIndex& n ,const T* values) requires functions_type::isOrderedType<T> {
1189  const T* iR=values;
1190  const T* iRe=iR+n;
1191  T minValue=(*iR);
1192  while (iR!=iRe) {
1193  minValue=((*iR)<minValue)?(*iR):minValue;
1194  iR++;
1195  }
1196  return minValue;
1197  }
1201  inline void max(T& m) const requires functions_type::isOrderedType<T> {
1202  m=Max(this->getSize(),this->getValues());
1203  }
1204 
1205 
1211  inline static T Max(const tIndex& n ,const T* values) requires functions_type::isOrderedType<T> {
1212  const T* iR=values;
1213  const T* iRe=iR+n;
1214  T maxValue=(*iR);
1215  while (iR!=iRe) {
1216  maxValue=((*iR)>maxValue)?(*iR):maxValue;
1217  iR++;
1218  }
1219  return maxValue;
1220  }
1221 
1222 
1223 
1227  inline void directionalSort(const tUChar& order) requires functions_type::isOrderedType<T>{
1228  switch(order) {
1229  case 'i':
1230  std::sort(this->begin(),this->end(),std::less<T>());
1231  break;
1232  case 'd':
1233  std::sort(this->begin(),this->end(),std::greater<T>());
1234  break;
1235  }
1236 
1237  }
1238 
1239 };
1240 
1241 
1242 
1244 
1246 
1249 
1250 
1251 //default array
1252 #ifndef DEFAULT_ARRAY
1253 #define DEFAULT_ARRAY
1255 
1257 
1260 #endif
1261 
1262 #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
constexpr auto cend() const
return end iterator for reading
Definition: CORE_Collection.h:149
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
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 describes a standart arithmetic array type implemented with a memory allocation with type ...
Definition: CORE_StdPtrArray.h:13
Self & operator=(const Self &&values)
build an array by a copy of c in mirror with the copy operator)
Definition: CORE_StdPtrArray.h:155
static void UniformRandomize(const T &min, const T &max, const tIndex &n, T *values)
generate a random val array
Definition: CORE_StdPtrArray.h:420
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: CORE_StdPtrArray.h:58
void copy(const tIndex &n, const std::valarray< Q > &Vs)
initialize the array to the values of val array
Definition: CORE_StdPtrArray.h:281
void AXPY(const tIndex &n, const Q &alpha, const Q *X, const T &beta, T *Y)
compute Y=beta.Y+ alpha .X
Definition: CORE_StdPtrArray.h:888
static void Normalize(const tIndex &n, T *values)
normalize the array
Definition: CORE_StdPtrArray.h:843
void copy(CORE_Array< Q, I > &&cpy)
copy the conatiner : mv is destroyed after this
Definition: CORE_StdPtrArray.h:206
void copy(const tIndex &n, const std::vector< Q > &Vs)
initialize the array to the values of vector
Definition: CORE_StdPtrArray.h:292
static void Transform(LambdaFct &&F, const CORE_Array< T, Self > &X, Self &R)
apply the transform element with the lambda function Ri = F(const Xi)
Definition: CORE_StdPtrArray.h:641
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: CORE_StdPtrArray.h:1077
static void Sub(const tIndex &n, const Q *X, T *R)
mulitply method : R:=R-X
Definition: CORE_StdPtrArray.h:720
CORE_StdPtrArray()
build an instance of class
Definition: CORE_StdPtrArray.h:26
static void Add(const tIndex &n, const Q *X, T *R)
mulitply method : R:=R+X
Definition: CORE_StdPtrArray.h:695
Self & operator=(const Self &values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:148
void transform(LambdaFct &&F)
transform the transform element with the lambda function Ti = F(const Ti)
Definition: CORE_StdPtrArray.h:597
T & scalarProduct(const CORE_Array< Q, I > &X, T &s) const
return the scalar product
Definition: CORE_StdPtrArray.h:988
Self & operator%=(const T &v) requires functions_type
modulo operator
Definition: CORE_StdPtrArray.h:496
void copy(const tIndex &n, const std::array< Q, N > &Vs)
initialize the array to the values of array of size N
Definition: CORE_StdPtrArray.h:269
void copy(const tIndex &n, const std::initializer_list< T > &Vs)
initialize the array to the values of list
Definition: CORE_StdPtrArray.h:248
Self & operator=(const std::array< Q, N > &values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:120
static void Transform(LambdaFct &&F, const CORE_Array< T, Self > &X, const CORE_Array< T, Self > &Y, Self &R)
apply the transform element with the lambda function Ri = F(const Xi,const Yi)
Definition: CORE_StdPtrArray.h:655
static void Copy(const tIndex &n, std::initializer_list< T > X, T *R)
copy the first n values of a values
Definition: CORE_StdPtrArray.h:369
Self & operator+=(const T &v)
add operator
Definition: CORE_StdPtrArray.h:457
void copy(const CORE_Array< Q, I > &cpy)
copy the container
Definition: CORE_StdPtrArray.h:195
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: CORE_StdPtrArray.h:906
void prod(T &prod) const
return the produc of all the elements
Definition: CORE_StdPtrArray.h:960
Self & operator/=(const T &v)
divisor operator
Definition: CORE_StdPtrArray.h:481
tReal l2Norm2() const
compute the square of L2-Norm of this
Definition: CORE_StdPtrArray.h:1029
void uniformRandomize(const T &min, const T &max)
randomize the vector in [min,max]
Definition: CORE_StdPtrArray.h:443
tReal linfDistance(tIndex &imax) const
compute the L infinity norm of This
Definition: CORE_StdPtrArray.h:1047
static CORE_UniquePointer< Self > New()
return a new unique pointer of this
Definition: CORE_StdPtrArray.h:69
static void Copy(const tIndex &n, const Q *X, T *R)
copy the first n values of a values
Definition: CORE_StdPtrArray.h:312
Self & operator=(const T &v)
fill the values of the array with v
Definition: CORE_StdPtrArray.h:94
void axpy(const Q &alpha, const CORE_Array< Q, I > &X, const T &beta)
compute This=beta.This+ alpha .X
Definition: CORE_StdPtrArray.h:872
static T ScalarProduct(const tIndex n, const Q *X, const T *Y)
return the scalar product <X,Y>
Definition: CORE_StdPtrArray.h:1003
static void Normalize(std::array< Q, N > &a)
normalize the array
Definition: CORE_StdPtrArray.h:836
void copy(const tIndex &n, std::initializer_list< T > &&Vs)
initialize the array to the values of list
Definition: CORE_StdPtrArray.h:257
static void Copy(const tIndex &n, const std::vector< Q > &X, T *R)
copy the first n values of a values
Definition: CORE_StdPtrArray.h:345
Self & operator=(const std::initializer_list< T > &values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:101
Self & operator-=(const T &v)
sub operator
Definition: CORE_StdPtrArray.h:464
static void Multiply(const tIndex &n, const Q *X, T *R)
multiply method : R:=R*X
Definition: CORE_StdPtrArray.h:772
void copy(const Self &cpy)
copy the container
Definition: CORE_StdPtrArray.h:216
Self & operator*=(const CORE_Array< Q, I > &X)
array multiply operator This*=X
Definition: CORE_StdPtrArray.h:569
static void Transform(LambdaFct &&F, Self &R)
apply the transform element with the lambda function Ri = F(const Ri)
Definition: CORE_StdPtrArray.h:629
void copy(Self &&cpy)
copy the container : mv is destroyed after this
Definition: CORE_StdPtrArray.h:226
static tBoolean IsNANContained(const tIndex &n, const T *values)
return true if one value is Not A Number
Definition: CORE_StdPtrArray.h:915
Self & operator-=(const CORE_Array< Q, I > &X)
array sub operator : This -=X
Definition: CORE_StdPtrArray.h:559
void transform(LambdaFct &&F, const CORE_Array< T, Self > &X)
transform the transform element with the lambda function Ti = F(const Xi)
Definition: CORE_StdPtrArray.h:606
static tReal LinfDistance(const tIndex &nX, const Q *Xs, const tIndex &nY, const T *Ys, tIndex &imax)
compute the L-inf distance of X to Y
Definition: CORE_StdPtrArray.h:1121
Self & operator=(const std::vector< Q > &values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:141
virtual ~CORE_StdPtrArray()
destroy an instance of class
Definition: CORE_StdPtrArray.h:39
Self & operator=(const std::valarray< Q > &values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:131
void sum(T &s) const
return the sum of all the elements
Definition: CORE_StdPtrArray.h:936
CORE_StdPtrArray(const CORE_PtrArray< T, Self > &c)
build an instance of class
Definition: CORE_StdPtrArray.h:30
requires static functions_type::isArithmeticType< Q > void Multiply(const Q &X, const tIndex &n, T *R)
mulitply method : R:=R*X
Definition: CORE_StdPtrArray.h:748
static T Sum(const tIndex &n, const T *values)
return the sum of all the elements
Definition: CORE_StdPtrArray.h:946
static T Prod(const tIndex &n, const T *values)
return the produc of all the elements
Definition: CORE_StdPtrArray.h:968
void copy(const tIndex &n, const Q *Vs)
initialize the array to the values of pointer of size n
Definition: CORE_StdPtrArray.h:238
Self & operator=(const CORE_Array< Q, I1 > &values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:166
Self & operator=(std::initializer_list< T > &&values)
build an array by a copy of c
Definition: CORE_StdPtrArray.h:109
Self & operator*=(const T &v)
multiplicator operator
Definition: CORE_StdPtrArray.h:473
static void Divide(const tIndex &n, const Q *X, T *R)
divide method : R:=R/X
Definition: CORE_StdPtrArray.h:797
tReal l2Distance2(const CORE_Array< Q, I > &X) const
compute the square of L2-distance of this to X
Definition: CORE_StdPtrArray.h:1040
static void Add(const Q &X, const tIndex &n, T *R)
mulitply method : R:=R+X
Definition: CORE_StdPtrArray.h:676
Self & operator=(const CORE_Array< Q, I1 > &&values)
build an array by a copy of c in mirror with the copy operator)
Definition: CORE_StdPtrArray.h:176
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: CORE_StdPtrArray.h:617
void initialize(const T &v)
randomize the field
Definition: CORE_StdPtrArray.h:395
void normalize()
normalize the array
Definition: CORE_StdPtrArray.h:826
tReal linfDistance(const CORE_Array< Q, I > &X, tIndex &imax) const
compute the L infinity distance of this to X
Definition: CORE_StdPtrArray.h:1061
Self & operator/=(const CORE_Array< Q, I > &X)
array divisor operator This/=X
Definition: CORE_StdPtrArray.h:582