5 #include "CORE_Collection.h"
8 #include "CORE_Array.h"
14 #include "functions_string.h"
48 template <
typename T,
typename K,K D,
class S,
class I>
104 mem+=mStorage.getContentsMemorySize();
122 mStorage.setSize(n*D);
130 mStorage.fitToSize(n*D);
136 return mStorage.getSize()/D;
145 mStorage.setSize(D*(n/D));
154 mStorage.resize(D*(n/D));
162 return mStorage.getSize();
195 inline const T&
operator()(
const tInteger& i,
const K& d)
const {
196 return mStorage[D*i+d];
203 return mStorage[D*i+d];
210 return &mStorage[D*i];
216 return &mStorage[D*i];
230 inline constexpr
auto cend()
const {
268 inline constexpr
auto crend()
const {
295 inline constexpr
auto csend()
const {
308 inline const T&
get(
const tIndex& i,
const K& d)
const {
309 return mStorage[i*D+d];
315 inline T&
get(
const tIndex& i,
const K& d) {
316 return mStorage[i*D+d];
324 return mStorage.getValues();
330 return mStorage.getValues();
359 mStorage.
copy(D*(values.size()/D),values);
366 mStorage.
copy(D*(values.size()/D),values);
373 template<
size_t N,
typename Q>
375 mStorage.
copy(D*(N/D),values);
393 mStorage.
copy(D*(values.size()/D),values);
402 mStorage.
copy(D*(values.size()/D),values);
416 mStorage.
copy(cpy.getStorage());
422 template<
typename Q,
class S1,
class I1>
430 template<
typename Q,
class S1,
class I1>
432 mStorage.
copy(cpy.getStorage());
447 inline void copy(
const tIndex& n ,
const Q* vs) {
448 mStorage.copy(D*(n/D),vs);
455 template<
typename Q,
size_t N>
456 inline void copy(
const std::array<Q,N>& vs) {
457 mStorage.copy(D*(vs.size()/D),vs);
465 inline void copy(
const std::array<Q,D>& vs) {
473 inline void copy(
const std::valarray<Q>& vs) {
474 mStorage.copy(D*(vs.size()/D),vs);
481 inline void copy(std::valarray<Q>&& vs) {
482 mStorage.copy(D*(vs.size()/D),vs);
490 inline void copy(
const std::vector<Q>& vs) {
491 mStorage.copy(D*(vs.size()/D),vs);
498 inline void copy(
const std::initializer_list<T>& vs) {
499 mStorage.copy(D*(vs.size()/D),vs);
504 inline void copy(std::initializer_list<T>&& vs) {
505 mStorage.copy(D*(vs.size()/D),vs);
512 template<
typename Q,
class S1,
class I1>
520 template<
typename Q,
class S1,
class I1>
522 mStorage.copy(cpy->getStorage());
620 inline Self& operator&=(
const T& v) requires functions_type::isIntegerType<T> {
628 inline Self& operator|=(
const T& v) requires functions_type::isIntegerType<T> {
636 inline Self& operator^=(
const T& v) requires functions_type::isIntegerType<T> {
643 inline Self& operator<<=(
const T& v) requires functions_type::isIntegerType<T> {
651 inline Self& operator>>=(
const T& v) requires functions_type::isIntegerType<T> {
661 template<
typename T1,
class S1,
class I1>
663 mStorage+=v.getStorage();
669 template<
typename T1,
class S1,
class I1>
671 mStorage-=v.getStorage();
677 template<
typename T1,
class S1,
class I1>
679 mStorage*=v.getStorage();
685 template<
typename T1,
class S1,
class I1>
687 mStorage/=v.getStorage();
699 template<
typename LambdaFct>
708 template<
typename LambdaFct>
719 template<
typename LambdaFct>
732 template<
typename LambdaFct>
769 template<
typename Q,
class S1,
class I1>
794 static_cast<const I*
>(
this)->
mod2(X);
809 template<
typename Q,
class I1>
819 inline void sum(T& s)
const {
835 template<
class Q,
class S1,
class I1>
846 template<
class Q,
class S1,
class I1>
856 inline void min(T& m)
const requires functions_type::isOrderedType<T>{
863 inline void max(T& m)
const requires functions_type::isOrderedType<T> {
871 inline void directionalSort(
const tUChar& order) requires functions_type::isOrderedType<T>{
872 directionalSort(order,0);
879 inline void directionalSort(
const tUChar& order,
const K& k) requires functions_type::isOrderedType<T>{
882 std::sort(this->
sbegin()+k,this->
send()+k,std::less<T>());
885 std::sort(this->
sbegin()+k,this->
send()+k,std::greater<T>());
915 inline tBoolean saveToFile(
const tString& fileName)
const {
916 return saveToFile(
"",fileName,12);
932 inline tBoolean saveToFile(
const tString& comments,
const tString& filename,
const tUCInt& nDigits)
const {
933 std::ofstream f(filename.c_str(),std::ios::out);
936 tString comment=comments;
937 functions_string::replaceAll(
"\n",
"\n#",comment);
938 f<<
"#"<<comment<<
"\n";
940 f<<N<<
"\t"<<((tIndex)D)<<
"\n";
944 const T* iVe=iV+this->
getSize();
951 f<<std::setprecision(nDigits)<<(*iV)<<
"\t";
1003 inline tBoolean
loadFromFile(
const tString& filename,tString& comment,tInt& retCode) {
1004 std::ifstream f(filename.c_str(),std::ios::in);
1006 std::stringstream sscomment;
1010 while ( std::getline(f,line) ) {
1013 if (line.find(
"#")==0) {
1014 functions_string::replaceAll(
"#",
"",line);
1015 sscomment<<line<<
"\n";
1019 comment=sscomment.str();
1024 std::stringstream iss(line);
1049 const T* iVe=iV+this->
getSize();
1051 while ((iV!=iVe)&&(!f.eof())) {
1057 if (iV!=iVe) retCode=0;
1059 return (retCode==1);
1079 std::stringstream cstr;
1084 [&cstr,&k](
const auto& Vi) {
1088 std::for_each_n(&Vi,D,
1089 [&cstr](
const auto& Vid){
1092 cstr<<std::setprecision(12)<<Vid<<
",";
1097 cstr.seekp(-1, std::ios_base::end);
1100 cstr.seekp(-1, std::ios_base::end);
this class describes an array of values T of dynamical size with algebrical operators and I is an imp...
Definition: CORE_Array.h:91
this class describes a general container of values of type T where implemented class is I
Definition: CORE_Collection.h:49
this class describes a const iterator with a constant stride
Definition: CORE_ConstantStrideIterator.h:12
this class describes an field. A field is composed by
Definition: CORE_Field.h:49
Self & operator=(const T &v)
fill the values of the field with v
Definition: CORE_Field.h:351
const T * operator()(const tInteger &i) const
get the i-th element for reading. Do not verify the bounds
Definition: CORE_Field.h:209
void axpy(const Q &alpha, const CORE_Field< Q, K, D, S1, I1 > &X, const T &beta)
compute This=beta.This+ alpha .X
Definition: CORE_Field.h:770
T & operator()(const tInteger &i, const K d)
get the i-th element for writting. Do not verify the bounds
Definition: CORE_Field.h:202
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: CORE_Field.h:782
K getDimension() const
get the dimension of the field
Definition: CORE_Field.h:169
Self & operator-=(const T &v)
sub operator
Definition: CORE_Field.h:581
S & getStorage()
get the storage
Definition: CORE_Field.h:342
void copy(const CORE_Field< Q, K, D, S1, I1 > &cpy)
copy the the field
Definition: CORE_Field.h:513
Self & operator=(Self &&cpy)
build an field by a copy of cpy
Definition: CORE_Field.h:415
void initialize(const std::array< Q, D > &vs)
initialize the field to the values of array of size D
Definition: CORE_Field.h:541
constexpr auto crbegin() const
return reverse begin iterator for reading
Definition: CORE_Field.h:262
Self & operator=(CORE_Field< Q, K, D, S1, I1 > &&cpy)
build an field by a copy of cpy
Definition: CORE_Field.h:431
void transform(LambdaFct &&F, const Self &X, const Self &Y)
transform the transform element with the lambda function Ti = F(Xi,Yi)
Definition: CORE_Field.h:720
T & get(const tIndex &i, const K &d)
get the d-th coordinate of the i-th element for writting
Definition: CORE_Field.h:315
void copy(CORE_Field< Q, K, D, S1, I1 > &&cpy)
copy the field : mv is destroyed after this
Definition: CORE_Field.h:521
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:102
void swap(CORE_Array< T, I > &a)
swap the contents of the array
Definition: CORE_Field.h:741
void transform(LambdaFct &&F)
transform the transform element with the lambda function Ti = F(Ti)
Definition: CORE_Field.h:700
tReal linfNorm(tIndex &i) const
compute the L infinity norm
Definition: CORE_Field.h:802
auto rbegin()
return reverse begin iterator for writing
Definition: CORE_Field.h:249
Self & operator*=(const T &v)
multiplicator operator
Definition: CORE_Field.h:590
void copy(const tIndex &n, const Q *vs)
initialize the field to the values of pointer of size n
Definition: CORE_Field.h:447
const T * getValues() const
get the values of the array for reading
Definition: CORE_Field.h:323
void uniformRandomize(const T &min, const T &max)
randomize the field
Definition: CORE_Field.h:561
void copy(std::valarray< Q > &&vs)
initialize the field to the values of val array
Definition: CORE_Field.h:481
auto sbegin()
return begin stride iterator for writing
Definition: CORE_Field.h:276
void prod(T &p) const
return the produc of all the elements
Definition: CORE_Field.h:825
Self & operator=(const std::initializer_list< T > &values)
build an field by a copy of c
Definition: CORE_Field.h:358
Self & operator=(std::initializer_list< T > &&values)
build an field by a copy of c
Definition: CORE_Field.h:365
Self & operator*=(const CORE_Field< T1, K, D, S1, I1 > &v)
array multiply operator
Definition: CORE_Field.h:678
void elementsTransform(LambdaFct &&F)
apply the transform element with the lambda function Xid = F(Xid)
Definition: CORE_Field.h:733
Self & operator%=(const T &v) requires functions_type
modulo operator
Definition: CORE_Field.h:612
void mod2(CORE_Array< T, I1 > &X) const
return the norm2 array per each element
Definition: CORE_Field.h:793
auto send()
return end N-stride iterator for writing
Definition: CORE_Field.h:282
T & scalarProduct(const std::valarray< Q > &weights, const CORE_Field< Q, K, D, S1, I1 > &X, T &s) const
return the scalar product
Definition: CORE_Field.h:847
T * getValues()
get the values of the array
Definition: CORE_Field.h:329
auto begin()
return begin iterator for writing
Definition: CORE_Field.h:236
void copy(std::initializer_list< T > &&vs)
initialize the field to the values of list
Definition: CORE_Field.h:504
Self & operator=(const std::array< Q, N > &values)
build an field by a copy of c
Definition: CORE_Field.h:374
void setUniformRandomizeSeed()
set the uniform randomize seed
Definition: CORE_Field.h:553
Self & operator/=(const T &v)
divisor operator
Definition: CORE_Field.h:598
void copy(const std::array< Q, D > &vs)
initialize the field to the values of array of size D
Definition: CORE_Field.h:465
const T & operator()(const tInteger &i, const K &d) const
get the i-th element for reading. Do not verify the bounds
Definition: CORE_Field.h:195
const T & get(const tIndex &i, const K &d) const
get the d-th coordinate of the i-th element for reading
Definition: CORE_Field.h:308
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:135
Self & operator=(const CORE_Field< Q, K, D, S1, I1 > &cpy)
build a field by a copy of cpy
Definition: CORE_Field.h:423
virtual ~CORE_Field()
destroy an instance of class
Definition: CORE_Field.h:72
const T & operator[](const tIndex &i) const
get the i-th value for reading.
Definition: CORE_Field.h:179
tBoolean loadFromFile(const tString &filename, tString &comment, tInt &retCode)
load the field from a txt file with the format :
Definition: CORE_Field.h:1003
auto end()
return end iterator for writing
Definition: CORE_Field.h:242
void copy(const std::initializer_list< T > &vs)
initialize the field to the values of list
Definition: CORE_Field.h:498
constexpr auto csend() const
return end N-stride const iterator for writing
Definition: CORE_Field.h:295
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: CORE_Field.h:88
void transform(LambdaFct &&F, const Self &X)
transform the transform element with the lambda function Ti = F(Xi)
Definition: CORE_Field.h:709
constexpr auto csbegin() const
return begin N-stride const iterator for writing
Definition: CORE_Field.h:289
Self & operator=(const std::valarray< Q > &values)
build an field by a copy of c
Definition: CORE_Field.h:392
T & operator[](const tIndex &i)
get the i-th value for writting.
Definition: CORE_Field.h:185
Self & operator=(const Self &cpy)
build a field by a copy of cpy
Definition: CORE_Field.h:408
auto rend()
return reverse end iterator for writing
Definition: CORE_Field.h:255
void initialize(const T &v)
initialize the field to v
Definition: CORE_Field.h:533
tReal linfDistance(const CORE_Field< Q, K, D, S, I1 > &X, tIndex &i) const
compute the Linfinitty norm
Definition: CORE_Field.h:810
void sum(T &s) const
return the sum of all the elements
Definition: CORE_Field.h:819
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:161
Self & operator/=(const CORE_Field< T1, K, D, S1, I1 > &v)
array divisor operator
Definition: CORE_Field.h:686
Self & operator-=(const CORE_Field< T1, K, D, S1, I1 > &v)
array sub operator
Definition: CORE_Field.h:670
Self & operator=(const std::array< Q, D > &values)
build an field by a copy of c
Definition: CORE_Field.h:383
void fitToElementsNumber(const tInteger &n)
set the number of element of the container without erasing values
Definition: CORE_Field.h:129
void resize(const tIndex &n)
set the number of values of the container
Definition: CORE_Field.h:153
T * operator()(const tInteger &i)
get the i-th element for writting. Do not verify the bounds
Definition: CORE_Field.h:215
constexpr auto cbegin() const
return begin iterator for reading
Definition: CORE_Field.h:224
void copy(const std::valarray< Q > &vs)
initialize the field to the values of val array
Definition: CORE_Field.h:473
void swap(CORE_Field< T, K, D, S, I > &a)
swap the contents of the array
Definition: CORE_Field.h:749
Self & operator+=(const T &v)
add operator
Definition: CORE_Field.h:574
T & scalarProduct(const CORE_Field< Q, K, D, S1, I1 > &X, T &s) const
return the scalar product
Definition: CORE_Field.h:836
void setUniformRandomizeSeed(const tULLInt &seed)
set the uniform randomize seed
Definition: CORE_Field.h:548
Self & operator=(const std::vector< Q > &values)
build an field by a copy of c
Definition: CORE_Field.h:401
void copy(const std::array< Q, N > &vs)
initialize the field at eche element with Vs
Definition: CORE_Field.h:456
constexpr auto cend() const
return end iterator for reading
Definition: CORE_Field.h:230
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:121
const S & getStorage() const
get the storage
Definition: CORE_Field.h:336
void normalize()
normalize all the elements of the field return false if the method is not compatible with the floatin...
Definition: CORE_Field.h:760
constexpr auto crend() const
return reverse end iterator for reading
Definition: CORE_Field.h:268
void min(T &m) const requires functions_type
return the min value of all the elements
Definition: CORE_Field.h:856
void copy(const std::vector< Q > &vs)
initialize the field to the values of vector
Definition: CORE_Field.h:490
CORE_Field()
instanciation method of a class
Definition: CORE_Field.h:64
void setSize(const tIndex &n)
set the number of values of the container
Definition: CORE_Field.h:144
virtual tString toString() const override
return the string representation of the object node
Definition: CORE_Field.h:1078
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
this class describes a const iterator with a constant stride 2 templates parameter:
Definition: CORE_StrideIterator.h:12