1 #ifndef CORE_StdPtrArray_H
2 #define CORE_StdPtrArray_H
4 #include "CORE_PtrArray.h"
7 #include "functions_numeric.h"
69 static inline CORE_UniquePointer<Self>
New() {
102 copy(values.size(),values);
110 copy(values.size(),values);
119 template<
size_t N,
typename Q>
165 template<
typename Q,
class I1>
175 template<
typename Q,
class I1>
194 template<
typename Q,
class I>
205 template<
typename Q,
class I>
208 Copy(cpy.getSize(),cpy.getValues(),this->getValues());
228 Copy(cpy.getSize(),cpy.getValues(),this->getValues());
238 inline void copy(
const tIndex& n ,
const Q* Vs) {
248 inline void copy(
const tIndex& n,
const std::initializer_list<T>& Vs) {
249 tIndex p=functions_numeric::min(n,Vs.size());
257 inline void copy(
const tIndex& n,std::initializer_list<T>&& Vs) {
258 tIndex p=functions_numeric::min(n,Vs.size());
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);
272 Copy(p,Vs.getData(),this->getValues());
281 inline void copy(
const tIndex& n,
const std::valarray<Q>& Vs) {
282 tIndex p=functions_numeric::min(n,Vs.size());
292 inline void copy(
const tIndex&n ,
const std::vector<Q>& Vs) {
293 tIndex p=functions_numeric::min(n,Vs.size());
295 Copy(Vs.size(),Vs,this->getValues());
312 inline static void Copy(
const tIndex& n,
const Q* X,T* R) {
320 if (
sizeof(T)==
sizeof(Q)) {
321 memcpy(iR,iX,
sizeof(T)*n);
345 inline static void Copy(
const tIndex& n,
const std::vector<Q>& X,T* R) {
369 inline static void Copy(
const tIndex& n,std::initializer_list<T> X,T* R) {
397 if (fabs(v)<std::numeric_limits<T>::epsilon()) {
403 const T* iRe=iR+this->
getSize();
422 T alpha=(max-min)/RAND_MAX;
432 (*iV)=alpha*((T)std::rand())+min;
482 if (fabs(v)<std::numeric_limits<T>::epsilon()) {
484 "CORE_StdPtrArray/=",
496 inline Self&
operator%=(
const T& v) requires functions_type::isIntegerType<T> {
497 transform([&v](
const auto& x){
return x%v;});
504 inline Self& operator&=(
const T& v) requires functions_type::isIntegerType<T> {
505 transform([&v](
const auto& x){
return x&v;});
512 inline Self& operator|=(
const T& v) requires functions_type::isIntegerType<T> {
513 transform([&v](
const auto& x){
return x|v;});
520 inline Self& operator^=(
const T& v) requires functions_type::isIntegerType<T> {
521 transform([&v](
const auto& x){
return x^v;});
527 inline Self& operator<<=(
const T& v) requires functions_type::isIntegerType<T> {
528 transform([&v](
const auto& x){
return x<<v;});
535 inline Self& operator>>=(
const T& v) requires functions_type::isIntegerType<T> {
536 transform([&v](
const auto& x){
return x>>v;});
546 template<
typename Q,
class I>
549 tIndex p=functions_numeric::min(X.
getSize(),this->getSize());
558 template<
typename Q,
class I>
560 tIndex p=functions_numeric::min(X.
getSize(),this->getSize());
568 template<
typename Q,
class I>
571 tIndex p=functions_numeric::min(X.
getSize(),this->getSize());
581 template<
typename Q,
class I>
583 tIndex p=functions_numeric::min(X.
getSize(),this->getSize());
596 template<
typename LambdaFct>
605 template<
typename LambdaFct>
616 template<
typename LambdaFct>
628 template<
typename LambdaFct>
631 std::transform(R.cbegin(),R.cend(),R.begin(),F);
640 template<
typename LambdaFct>
644 R.setSize(X.getsize());
645 std::transform(X.
cbegin(),X.
cend(),R.begin(),F);
654 template<
typename LambdaFct>
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");
676 inline static void Add(
const Q& X,
const tIndex& n,T* R) {
682 const T* iRe=iR;iRe+=n;
695 inline static void Add(
const tIndex& n,
const Q* X,T* R) {
705 const T* iRe=iR;iRe+=n;
720 inline static void Sub(
const tIndex& n,
const Q* X,T* R) {
730 const T* iRe=iR;iRe+=n;
747 requires functions_type::isArithmeticType<Q>
748 inline static void Multiply(
const Q& X,
const tIndex& n,T* R) {
756 const T* iRe=iR;iRe+=n;
772 inline static void Multiply(
const tIndex& n,
const Q* X,T* R) {
782 const T* iRe=iR;iRe+=n;
797 inline static void Divide(
const tIndex& n,
const Q* X,T* R) {
799 Q eps=std::numeric_limits<Q>::epsilon();
808 const T* iRe=iR;iRe+=n;
812 throw CORE_Excpetion(
"core",
"CORE_StdPtrArray::Divide(n,X,X)",
813 "division by 0 at index "+std::to_string(iX-X));
835 template<
typename Q,
size_t N>
852 while (iV!=iVe) {norm+=(*iV)*(*iV);iV++;}
855 if (norm>std::numeric_limits<T>::epsilon()) {
860 while (iV!=iVe) {(*iV)*=norm;iV++;}
871 template<
typename Q,
class I>
873 tIndex p=functions_numeric::min(X.
getSize(),this->getSize());
888 inline void AXPY(
const tIndex& n,
const Q& alpha,
const Q* X,
const T& beta,T* Y) {
893 (*iY)=beta*(*iY)+alpha*(*iX);
921 if (std::isnan(*iR))
return true;
936 inline void sum(T& s)
const {
946 inline static T
Sum(
const tIndex& n,
const T* values) {
968 inline static T
Prod(
const tIndex& n,
const T* values) {
987 template<
typename Q,
class I>
1002 template<
typename Q>
1014 const Q* iXe=iX;iXe+=n;
1039 template<
typename Q,
class I>
1060 template<
typename Q,
class I>
1063 this->getSize(),this->getValues(),
1076 template<
typename Q>
1078 const tIndex& nY,
const T* Ys) {
1079 tIndex p=functions_numeric::min(nX,nY);
1120 template<
typename Q>
1122 const tIndex& nY,
const T* Ys,
1124 tIndex p=functions_numeric::min(nX,nY);
1135 tmp=std::fabs((*iX)-(*iY));
1180 inline void min(T& m)
const requires functions_type::isOrderedType<T> {
1188 inline static T Min(
const tIndex& n ,
const T* values) requires functions_type::isOrderedType<T> {
1193 minValue=((*iR)<minValue)?(*iR):minValue;
1201 inline void max(T& m)
const requires functions_type::isOrderedType<T> {
1211 inline static T Max(
const tIndex& n ,
const T* values) requires functions_type::isOrderedType<T> {
1216 maxValue=((*iR)>maxValue)?(*iR):maxValue;
1227 inline void directionalSort(
const tUChar& order) requires functions_type::isOrderedType<T>{
1230 std::sort(this->
begin(),this->
end(),std::less<T>());
1233 std::sort(this->
begin(),this->
end(),std::greater<T>());
1252 #ifndef DEFAULT_ARRAY
1253 #define DEFAULT_ARRAY
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