C++ mpi module for stochmagnet_main Package
CORE_StdValArray.h
1 #ifndef CORE_StdValArray_H
2 #define CORE_StdValArray_H
3 
4 #include "CORE_ValArray.h"
5 
6 //numeric function headers
7 #include "functions_numeric.h"
8 
13 template <typename T>
14 class CORE_StdValArray : public CORE_ValArray<T,CORE_StdValArray<T>> {
15 
16 private:
17 
18  //This class type
19  typedef CORE_StdValArray<T> Self;
20 
21 
22 
23  // CONSTRUCTORS
24 public:
28  }
29 
33  explicit CORE_StdValArray(const tIndex& n) : CORE_ValArray<T,Self>(n) {
34  }
35 
36 
37  // DESTRUCTORS
40  virtual ~CORE_StdValArray() {
41  }
42 
43 
44 private:
45 
46 
47 
48 
49  //MEMORY
50  //=====
51 public:
59  virtual tMemSize getMemorySize() const override {
60  return sizeof(*this)+this->getContentsMemorySize();
61  }
62 
63  //allocation methods
64  //===================
65 
66 public:
70  static inline CORE_UniquePointer<Self> New() {
71  return CORE_UniquePointer<Self>(new Self(),CORE_Object::Delete());
72  }
73 
74 
75 
76 
77 
78  //accessor operators
79  //====================
80 
81 
82  //accessor iterator
83  //=================
84 
85 
86  //accessor methods
87  //=================
88 
89 
90  //assignment operators
91  //====================
95  inline Self& operator=(const T& v) {
96  initialize(v);
97  return *this;
98  }
102  inline Self& operator=(const std::initializer_list<T>& values) {
103  copy(values.size(),values);
104  return *this;
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(N,values);
122  return *this;
123 
124  }
125 
130  template<typename Q>
131  inline Self& operator=(const std::valarray<Q>& values) {
132  copy(values.size(),values);
133  return *this;
134  }
135 
140  template<typename Q>
141  inline Self& operator=(const std::vector<Q>& values) {
142  copy(values.size(),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 
193  template<typename Q,class I>
194  inline void copy(const CORE_Array<Q,I>& X) {
195  Copy(X,this->getArray());
196  }
197 
203  template<typename Q,class I>
204  inline void copy(CORE_Array<Q,I>&& X) {
205  Copy(X,this->getArray());
206  }
207 
213  template<typename Q,class I>
214  inline void copy(const CORE_ValArray<Q,I>& cpy) {
215  Copy(cpy.getArray(),this->getArray());
216  }
217 
223  template<typename Q,class I>
224  inline void copy(CORE_ValArray<Q,I>&& cpy) {
225  Copy(cpy.getArray(),this->getArray());
226  }
227 
228 
229 
233  inline void copy(const Self& cpy) {
234  Copy(cpy.getArray(),this->getArray());
235  }
236 
240  inline void copy(Self&& cpy) {
241  Copy(cpy.getArray(),this->getArray());
242  }
243 
244 
245 
251  template<typename Q>
252  inline void copy(const tIndex& n , const Q* Vs) {
253  Copy(n,Vs,this->getArray());
254  }
255 
260  inline void copy(const tIndex& n,const std::initializer_list<T>& Vs) {
261  tIndex p=functions_numeric::min(n,Vs.size());
262  Copy(p,Vs,this->getArray());
263  }
268  inline void copy(const tIndex& n,std::initializer_list<T>&& Vs) {
269  tIndex p=functions_numeric::min(n,Vs.size());
270  Copy(p,Vs,this->getArray());
271  }
278  template<typename Q,size_t N>
279  inline void copy(const tIndex& n, const std::array<Q,N>& Vs) {
280  tIndex p=functions_numeric::min(n,N);
281  Copy(p,Vs.getData(),this->getArray());
282  }
283 
289  template<typename Q>
290  inline void copy(const tIndex& n, const std::valarray<Q>& Vs) {
291  tIndex p=functions_numeric::min(n,Vs.size());
292  Copy(p,Vs,this->getArray());
293  }
299  template<typename Q>
300  inline void copy(const tIndex& n, const std::vector<Q>& Vs) {
301  tIndex p=functions_numeric::min(n,Vs.size());
302  Copy(p,Vs,this->getArray());
303  }
304 
305 
306  //static copy
307  //-----------
308 
309 
316  inline static void Copy(const std::valarray<T>& X,std::valarray<T>& R) {
317  R=X;
318  }
325  template<typename Q,class I>
326  inline static void Copy(const CORE_Array<Q,I>& X,std::valarray<T>& R) {
327  R.resize(X.getSize());
328  auto iX=X.cbegin();
329  std::for_each(std::ranges::begin(R),std::ranges::end(R),[&iX](auto& Ri){Ri=(*iX);iX++;});
330  }
339  template<class Q>
340  inline static void Copy(const tIndex& n,const std::valarray<Q>& X,std::valarray<T>& R) {
341  if (n==X.size()) {
342  R.resize(n);
343  R=X;
344  } else {
345  R.resize(n);
346  auto iX=X.cbegin();
347  std::for_each(std::ranges::begin(R),std::ranges::end(R),[&iX](auto& Ri){Ri=(*iX);iX++;});
348  }
349 
350  }
358  inline static void Copy(const tIndex& n,std::initializer_list<T>&& X,std::valarray<T>& R) {
359  if (n==X.size()) {
360  R.resize(n);
361  R=X;
362  } else {
363  R.resize(n);
364  auto iX=X.begin();
365  std::for_each(std::ranges::begin(R),std::ranges::end(R),[&iX](auto& Ri){Ri=(*iX);iX++;});
366  }
367 
368  }
369 
377  inline static void Copy(const tIndex& n,std::initializer_list<T> X,std::valarray<T>& R) {
378  if (n==X.size()) {
379  R.resize(n);
380  R=X;
381  } else {
382  R.resize(n);
383  auto iX=X.begin();
384  std::for_each(std::ranges::begin(R),std::ranges::end(R),[&iX](auto& Ri){Ri=(*iX);iX++;});
385  }
386 
387  }
388 
397  template<class Q>
398  inline static void Copy(const tIndex& n,const std::vector<Q>& X,std::valarray<T>& R) {
399  R.resize(n);
400  auto iX=X.begin();
401  std::for_each(std::ranges::begin(R),std::ranges::end(R),[&iX](auto& Ri){Ri=(*iX);iX++;});
402  }
403 
412  template<typename Q>
413  inline static void Copy(const tIndex& n,const Q* X,std::valarray<T>& R) {
414  R.resize(n);
415  auto iX=X;
416  std::for_each(std::ranges::begin(R),std::ranges::end(R),[&iX](auto& Ri){Ri=(*iX);iX++;});
417  }
418 
419 
420 
421 
422  //initializers methods
423  //====================
429  inline void initialize(const T& x) {
430  for(auto& Ri: this->getArray()) {Ri=x;};
431  }
432 
433 
434 
440  inline static void UniformRandomize(const T& min,const T& max,std::vector<T>& values){
441  T alpha=(max-min)/RAND_MAX;
442  for(auto& V : values) {V=alpha*((T)std::rand())+min;};
443  }
449  inline static void UniformRandomize(const T& min,const T& max,std::valarray<T>& values){
450  T alpha=(max-min)/RAND_MAX;
451  for(auto& V : values) {V=alpha*((T)std::rand())+min;};
452  }
459  template<size_t N>
460  inline static void UniformRandomize(const T& min,const T& max,std::array<T,N>& values){
461  T alpha=(max-min)/RAND_MAX;
462  for(auto& V : values) {V=alpha*((T)std::rand())+min;};
463  }
464 
465 
466 
471  inline void uniformRandomize(const T& min,const T& max) {
472  UniformRandomize(min,max,this->getArray());
473  }
474 
475 
476  //compound assignement operators (+=,-=,*=,/=,^=...)
477  //===================================================
478 
479  //arithmetic type compound operators
480  //====================================
484  inline Self& operator+=(const T& v) {
485  this->getArray()+=v;
486  return (*this);
487  }
491  inline Self& operator-=(const T& v) {
492  this->getArray()-=v;
493  return (*this);
494 
495  }
496 
500  inline Self& operator*=(const T& v) {
501  this->getArray()*=v;
502  return (*this);
503 
504  }
508  inline Self& operator/=(const T& v) {
509  if (fabs(v)<std::numeric_limits<T>::epsilon()) {
510  throw CORE_Exception("core",
511  "CORE_StdValArray/=",
512  "division by 0");
513  }
514  this->getArray()/=v;
515  return (*this);
516  }
517 
518  //integer type compond operators
519  //===============================
523  inline Self& operator%=(const T& v) requires functions_type::isIntegerType<T> {
524  this->getArray()%=v;
525  return (*this);
526  }
527 
531  inline Self& operator&=(const T& v) requires functions_type::isIntegerType<T> {
532  this->getArray()&=v;
533  return (*this);
534  }
535 
539  inline Self& operator|=(const T& v) requires functions_type::isIntegerType<T> {
540  this->getArray()|=v;
541  return (*this);
542  }
543 
547  inline Self& operator^=(const T& v) requires functions_type::isIntegerType<T> {
548  this->getArray()^=v;
549  return (*this);
550  }
554  inline Self& operator<<=(const T& v) requires functions_type::isIntegerType<T> {
555  this->getArray()<<=v;
556  return (*this);
557  }
558 
562  inline Self& operator>>=(const T& v) requires functions_type::isIntegerType<T> {
563  this->getArray()>>=v;
564  return (*this);
565  }
566 
567  //class type compound operatos
568  //=============================
569 
576  template<typename Q,class I>
577  inline Self& operator+=(const CORE_Array<Q,I>& X) {
578  //This=F(This,X)
579  transform([&](const auto& x,const auto&y){return x+y;},(*this),X);
580  return (*this);
581  }
582 
589  template<typename Q,class I>
590  inline Self& operator-=(const CORE_Array<Q,I>& X) {
591  //This=F(This,X)
592  transform([&](const auto& x,const auto&y){return x-y;},(*this),X);
593  return (*this);
594  }
601  template<typename Q,class I>
602  inline Self& operator*=(const CORE_Array<Q,I>& X) {
603  //This=F(This,X)
604  transform([&](const auto& x,const auto&y){return x*y;},(*this),X);
605  return (*this);
606  }
607 
608 
615  template<typename Q,class I>
616  inline Self& operator/=(const CORE_Array<Q,I>& X) {
617  //This=F(This,X)
618  transform([&](const auto& x,const auto&y){
619  if (y==0) throw CORE_Exception("core","CORE_Array<T>::/=","division by zero");
620  return x/y;},
621  (*this),X);
622  return (*this);
623  }
624 
629  inline Self& operator+=(const Self& X) {
630  this->getArray()+=X.getArray();
631  return (*this);
632  }
633 
634 
639  inline Self& operator-=(const Self& X) {
640  this->getArray()-=X.getArray();
641  return (*this);
642  }
643 
644 
649  inline Self& operator*=(const Self& X) {
650  this->getArray()*=X.getArray();
651  return (*this);
652  }
653 
658  inline Self& operator/=(const Self& X) {
659  this->getArray()/=X.getArray();
660  return (*this);
661  }
662 
663 
664 
665 
666  //transform methods
667  //=================
668 
673  template<typename LambdaFct>
674  inline void transform(LambdaFct&& F) {
675  Transform(F,(*this));
676  }
677 
683  template<typename LambdaFct>
684  inline void transform(LambdaFct&& F,
685  const CORE_Array<T,Self>& X) {
686  Transform(F,X,(*this));
687  }
688 
695  template<typename LambdaFct>
696  inline void transform(LambdaFct&& F,
697  const CORE_Array<T,Self>& X,
698  const CORE_Array<T,Self>& Y) {
699 
700  Transform(F,X,Y,*this);
701  }
702 
703  //static Transform
704  //-----------------
710  template<typename LambdaFct>
711  static inline void Transform(LambdaFct&& F,
712  Self& R) {
713  std::transform(R.cbegin(),R.cend(),R.begin(),F);
714  }
715 
716 
723  template<typename LambdaFct>
724  static inline void Transform(LambdaFct&& F,
725  const CORE_Array<T,Self>& X,
726  Self& R) {
727  R.setSize(X.getsize());
728  std::transform(X.cbegin(),X.cend(),R.begin(),F);
729  }
730 
738  template<typename LambdaFct>
739  static inline void Transform(LambdaFct&& F,
740  const CORE_Array<T,Self>& X,
741  const CORE_Array<T,Self>& Y,
742  Self& R) {
743  if (X.getSize()!=Y.getSize())
744  throw CORE_Exception("core",
745  "CORE_StdValArray::Transform(F,X,Y,R)",
746  "X ("+std::to_string(X.getSize())+") & Y ("+std::to_string(Y.getSize())+") have not same size");
747 
748 
749  R.setSize(X.getSize());
750  std::transform(X.cbegin(),X.cend(),
751  Y.cbegin(),
752  R.begin(),F);
753  }
754 
755 
756 
757 
760  inline void normalize() {
761  //compute the norm
762  T norm=0;
763  for(const auto& Vi : this->getArray()) {
764  norm+=Vi*Vi;
765  }
766  //normalize
767  if (norm>std::numeric_limits<T>::epsilon()) {
768  norm=1./sqrt(norm);
769  for(auto& Vi : this->getArray()) {
770  Vi*=norm;
771  }
772  }
773  }
774 
782  template<typename Q,class I>
783  inline void axpy(const Q& alpha, const CORE_Array<Q,I>& X,const T& beta) {
784  AXPY(alpha,X,beta,*this);
785  }
786 
787 
788 
797  template<typename Q,class I>
798  inline void AXPY(const Q& alpha, const CORE_Array<Q,I>& X,const T& beta,Self& Y) {
799  std::transform(X.cbegin(),X.cend(),
800  Y.cbegin(),
801  Y.begin(),
802  [&alpha,&beta](const auto& Xi,const auto& Yi) {
803  return beta*Yi+alpha*Xi;
804  });
805  }
806 
807 
808 
809 
810  //Data consistency
811  //=================
816  inline tBoolean isNANContained() const {
817  //loop on all values and stop the loop when the first nan value is found and return true
818  //return false otherwise
819  return (std::find_if(this->cbegin(),
820  this->cend(),
821  [](const T& v) {
822  return std::isnan(v);
823 
824  })!=this->cend());
825  }
826 
827 
828  //algebric methods
829  //================
830 
831 
832 
838  static inline Self& Sum(const Self& Ain,
839  Self& Aout) {
840  ASSERT_IN(Ain.getSize()==Aout.getSize());
841 
842  auto iAin=Ain.cbegin();
843  std::for_each(Aout.begin(),Aout.end(),
844  [&](auto& v) {
845  v+=(*iAin);
846  iAin++;
847  });
848 
849  return Aout;
850  }
851 
855  inline void sum(T& s) const {
856  s=this->getArray().sum();
857  }
861  inline void prod(T& p) const {
862  p=1;//product value
863  for(const auto& Vi : this->getArray()) p*=Vi;
864  }
865 
866 
874  template<typename Q,class I>
875  inline T& scalarProduct(const CORE_Array<Q,I>& X,T& s) const {
876  tIndex n=functions_numeric::min(this->getSize(),X.getSize());
877  auto iV=this->cbegin();
878  s=0;
879  std::for_each_n(X.cbegin(),n,[&iV,&s](const auto& Xi) {s+=Xi*(*iV);iV++;});
880  return s;
881  }
882 
887  inline tReal l2Norm2() const {
888  tReal s=0;
889  for(const auto& Vi : this->getArray()) s+=Vi*Vi;
890  return s;
891  }
899  template<typename Q,class I>
900  inline tReal l2Distance2(const CORE_Array<Q,I>& X) const {
901  //begin iterator of X
902  auto iX=X.getValues();
903  //end iterator on X
904  auto iXe=iX+X.getSize();
905 
906  //min size of X a This
907  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
908 
909  //initialize the sum to 0
910  tReal s=0;
911  //compute the sum in [0,p[
912  tReal tmp;
913  std::for_each_n(this->cbegin(),p,
914  [&iX,&s,&tmp](const auto& Vi) {
915  tmp=(Vi-(*iX));
916  tmp*=tmp;
917  s+=tmp;
918  iX++;
919  });
920 
921  //compute the sum in [p,X.getSize()[
922  while (iX!=iXe) {
923  s+=(*iX)*(*iX);
924  iX++;
925  }
926 
927  //or compute the sum in [p,This->getSize()[
928  std::for_each(this->cbegin()+p,this->cend(),
929  [&s](const auto& Vi) {
930  s+=Vi*Vi;
931  });
932  return s;
933 
934  }
939  inline tReal linfDistance(tIndex& imax) const {
940  tReal s=0;
941  //size is null
942  if (this->getSize()==0) return s;
943  //max is initialize to lowest positive real : 0
944  s=0;
945  imax=0;
946  //temporary variable
947  tIndex i=0;
948  tReal tmp;
949  for(const auto& Vi : this->getArray()) {
950  tmp=std::fabs(Vi);
951  if (tmp>s) {
952  s=tmp;
953  imax=i;
954  }
955  }
956  return s;
957  }
966  template<typename Q,class I>
967  inline tReal linfDistance(const CORE_Array<Q,I>& X,tIndex& imax) const {
968  //begin iterator of X
969  auto iX=X.getValues();
970  //end iterator on X
971  auto iXe=iX+X.getSize();
972 
973  //min size of X a This
974  tIndex p=functions_numeric::min(X.getSize(),this->getSize());
975 
976  //initialize the max to 0
977  tReal s=0;
978  imax=0;
979  tIndex i=0;
980  //compute the max in [0,p[
981  tReal tmp;
982  std::for_each_n(this->cbegin(),p,
983  [&iX,&i,&imax,&s,&tmp](const auto& Vi) {
984  tmp=std::fabs(Vi-(*iX));
985  if (tmp>s) {
986  s=tmp;
987  imax=i;
988  }
989  iX++;
990  i++;
991  });
992 
993  //compute the max in [p,X.getSize()[
994  while (iX!=iXe) {
995  tmp=std::fabs((*iX));
996  if (tmp>s) {
997  s=tmp;
998  imax=i;
999  }
1000  iX++;
1001  i++;
1002  }
1003 
1004  //or compute the max in [p,This->getSize()[
1005  std::for_each(this->cbegin()+p,this->cend(),
1006  [&imax,&s,&tmp,&i](const auto& Vi) {
1007  tmp=std::fabs(Vi);
1008  if (tmp>s) {
1009  s=tmp;
1010  imax=i;
1011  }
1012  i++;
1013  });
1014  return s;
1015  }
1016 
1017  //ordored type methods
1018 
1022  inline void min(T& m) const requires functions_type::isOrderedType<T> {
1023  m=this->getArray().min();
1024  }
1028  inline void max(T& m) const requires functions_type::isOrderedType<T> {
1029  m= this->getArray().max();
1030  }
1031 
1035  inline void directionalSort(const tUChar& order) requires functions_type::isOrderedType<T>{
1036  switch(order) {
1037  case 'i':
1038  std::sort(this->begin(),this->end(),std::less<T>());
1039  break;
1040  case 'd':
1041  std::sort(this->begin(),this->end(),std::greater<T>());
1042  break;
1043  }
1044 
1045  }
1046 
1047 };
1048 
1049 
1050 //val array
1052 
1055 
1056 
1057 
1058 
1059 #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
auto begin()
return begin iterator for writing
Definition: CORE_Collection.h:155
auto end()
return end iterator for writing
Definition: CORE_Collection.h:161
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 a standart arithmetic array type implemented with a std::valarray object of type...
Definition: CORE_StdValArray.h:14
Self & operator=(const std::vector< Q > &values)
build an array by a copy of c
Definition: CORE_StdValArray.h:141
T & scalarProduct(const CORE_Array< Q, I > &X, T &s) const
return the scalar product
Definition: CORE_StdValArray.h:875
static CORE_UniquePointer< Self > New()
return a new unique pointer of this
Definition: CORE_StdValArray.h:70
void AXPY(const Q &alpha, const CORE_Array< Q, I > &X, const T &beta, Self &Y)
compute Y=beta.Y+ alpha .X
Definition: CORE_StdValArray.h:798
static Self & Sum(const Self &Ain, Self &Aout)
sum the element of the 2 arrays
Definition: CORE_StdValArray.h:838
static void UniformRandomize(const T &min, const T &max, std::vector< T > &values)
generate a random val array
Definition: CORE_StdValArray.h:440
void initialize(const T &x)
initialize the array to the value x
Definition: CORE_StdValArray.h:429
tReal l2Norm2() const
computes the L2-Norm of this
Definition: CORE_StdValArray.h:887
void copy(const tIndex &n, const std::vector< Q > &Vs)
initialize the array to the values of vector
Definition: CORE_StdValArray.h:300
void normalize()
normalize the array
Definition: CORE_StdValArray.h:760
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_StdValArray.h:724
Self & operator=(const T &v)
fill the values of the array with v
Definition: CORE_StdValArray.h:95
CORE_StdValArray(const tIndex &n)
build an instance of class of size n
Definition: CORE_StdValArray.h:33
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_StdValArray.h:739
CORE_StdValArray()
build an instance of class
Definition: CORE_StdValArray.h:27
void axpy(const Q &alpha, const CORE_Array< Q, I > &X, const T &beta)
compute This=beta.This+ alpha .X
Definition: CORE_StdValArray.h:783
void copy(const Self &cpy)
copy the container
Definition: CORE_StdValArray.h:233
void prod(T &p) const
return the product of all the elements
Definition: CORE_StdValArray.h:861
void copy(CORE_ValArray< Q, I > &&cpy)
copy the conatiner : mv is destroyed after this
Definition: CORE_StdValArray.h:224
static void UniformRandomize(const T &min, const T &max, std::valarray< T > &values)
generate a random val array
Definition: CORE_StdValArray.h:449
static void Copy(const tIndex &n, std::initializer_list< T > &&X, std::valarray< T > &R)
copy the array R=X
Definition: CORE_StdValArray.h:358
static void Copy(const tIndex &n, std::initializer_list< T > X, std::valarray< T > &R)
copy the array R=X
Definition: CORE_StdValArray.h:377
void copy(Self &&cpy)
copy the conatiner : mv is destroyed after this
Definition: CORE_StdValArray.h:240
Self & operator=(const std::array< Q, N > &values)
build an array by a copy of c
Definition: CORE_StdValArray.h:120
Self & operator-=(const Self &X)
array add operator : This -=X
Definition: CORE_StdValArray.h:639
static void UniformRandomize(const T &min, const T &max, std::array< T, N > &values)
generate a random val array
Definition: CORE_StdValArray.h:460
void copy(const CORE_Array< Q, I > &X)
copy the array
Definition: CORE_StdValArray.h:194
void copy(const CORE_ValArray< Q, I > &cpy)
copy the container
Definition: CORE_StdValArray.h:214
static void Copy(const std::valarray< T > &X, std::valarray< T > &R)
copy 2 valarray with same type
Definition: CORE_StdValArray.h:316
static void Copy(const tIndex &n, const std::vector< Q > &X, std::valarray< T > &R)
copy the array R=X
Definition: CORE_StdValArray.h:398
void transform(LambdaFct &&F, const CORE_Array< T, Self > &X)
transform the transform element with the lambda function Ti = F(const Xi)
Definition: CORE_StdValArray.h:684
static void Copy(const tIndex &n, const Q *X, std::valarray< T > &R)
copy the array
Definition: CORE_StdValArray.h:413
tReal linfDistance(tIndex &imax) const
compute the L infinity norm of This
Definition: CORE_StdValArray.h:939
Self & operator=(const Self &&values)
build an array by a copy of c (in mirror with the copy operator)
Definition: CORE_StdValArray.h:155
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: CORE_StdValArray.h:59
Self & operator*=(const CORE_Array< Q, I > &X)
array multiply operator This *=X
Definition: CORE_StdValArray.h:602
Self & operator/=(const CORE_Array< Q, I > &X)
array divisor operator This /=X
Definition: CORE_StdValArray.h:616
Self & operator=(const CORE_Array< Q, I1 > &values)
build an array by a copy of c
Definition: CORE_StdValArray.h:166
static void Copy(const CORE_Array< Q, I > &X, std::valarray< T > &R)
copy 2 array
Definition: CORE_StdValArray.h:326
virtual ~CORE_StdValArray()
destroy an instance of class
Definition: CORE_StdValArray.h:40
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_StdValArray.h:696
Self & operator-=(const T &v)
sub operator
Definition: CORE_StdValArray.h:491
Self & operator=(const Self &values)
build an array by a copy of c
Definition: CORE_StdValArray.h:148
static void Copy(const tIndex &n, const std::valarray< Q > &X, std::valarray< T > &R)
copy the first n values of a std::valarray
Definition: CORE_StdValArray.h:340
void copy(const tIndex &n, const Q *Vs)
initialize the array to the values of pointer of size n
Definition: CORE_StdValArray.h:252
static void Transform(LambdaFct &&F, Self &R)
apply the transform element with the lambda function Ri = F(const Ri)
Definition: CORE_StdValArray.h:711
void sum(T &s) const
return the sum of all the elements
Definition: CORE_StdValArray.h:855
Self & operator/=(const T &v)
divisor operator
Definition: CORE_StdValArray.h:508
Self & operator=(const std::valarray< Q > &values)
build an array by a copy of c
Definition: CORE_StdValArray.h:131
Self & operator*=(const Self &X)
array add operator : This *=X
Definition: CORE_StdValArray.h:649
Self & operator*=(const T &v)
multiplicator operator
Definition: CORE_StdValArray.h:500
void transform(LambdaFct &&F)
transform the transform element with the lambda function Ti = F(const Ti)
Definition: CORE_StdValArray.h:674
Self & operator+=(const Self &X)
array add operator : This +=X
Definition: CORE_StdValArray.h:629
Self & operator=(std::initializer_list< T > &&values)
build an array by a copy of c
Definition: CORE_StdValArray.h:109
void copy(const tIndex &n, const std::initializer_list< T > &Vs)
initialize the array to the values of list
Definition: CORE_StdValArray.h:260
void copy(const tIndex &n, const std::array< Q, N > &Vs)
initialize the array to the values of array of size N
Definition: CORE_StdValArray.h:279
void copy(const tIndex &n, const std::valarray< Q > &Vs)
initialize the array to the values of val array
Definition: CORE_StdValArray.h:290
Self & operator-=(const CORE_Array< Q, I > &X)
array sub operator This -=X
Definition: CORE_StdValArray.h:590
tReal l2Distance2(const CORE_Array< Q, I > &X) const
compute the square of distance of this to X
Definition: CORE_StdValArray.h:900
Self & operator=(const std::initializer_list< T > &values)
build an array by a copy of c
Definition: CORE_StdValArray.h:102
void copy(const tIndex &n, std::initializer_list< T > &&Vs)
initialize the array to the values of list
Definition: CORE_StdValArray.h:268
void uniformRandomize(const T &min, const T &max)
randomize the vector in [min,max]
Definition: CORE_StdValArray.h:471
Self & operator+=(const T &v)
add operator
Definition: CORE_StdValArray.h:484
tReal linfDistance(const CORE_Array< Q, I > &X, tIndex &imax) const
compute the L infinity distance of this to X
Definition: CORE_StdValArray.h:967
Self & operator%=(const T &v) requires functions_type
modulo operator
Definition: CORE_StdValArray.h:523
Self & operator=(const CORE_Array< Q, I1 > &&values)
build an array by a copy of c (in mirror with the copy operator)
Definition: CORE_StdValArray.h:176
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: CORE_StdValArray.h:816
Self & operator/=(const Self &X)
array add operator : This /=X
Definition: CORE_StdValArray.h:658
void copy(CORE_Array< Q, I > &&X)
copy the array
Definition: CORE_StdValArray.h:204
this class describes an arithmetic array type implemented with a std::valarray object with implementa...
Definition: CORE_ValArray.h:70
constexpr auto cend() const
return end iterator for reading
Definition: CORE_ValArray.h:205
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