5 #include "CORE_Collection.h"
8 #include "CORE_ConstantStrideIterator.h"
11 #include "CORE_StrideIterator.h"
14 #include "functions_numeric.h"
90 template <
typename T,
class I>
180 inline constexpr
auto csend()
const {
192 inline const T&
get(
const tIndex& i)
const {
198 inline T&
get(
const tIndex& i) {
207 return static_cast<const I*
>(
this)->
getValues();
213 return static_cast<I*
>(
this)->
getValues();
231 copy(values.size(),values);
238 template<
size_t N,
typename Q>
250 copy(values.size(),values);
259 copy(values.size(),values);
265 template<
typename Q,
class I1>
280 template<
typename Q,
class I1>
304 inline void copy(
const tIndex& n ,
const Q* vs) {
305 static_cast<I*
>(
this)->
copy(n,vs);
313 template<
typename Q,
size_t N>
314 inline void copy(
const tIndex& n,
const std::array<Q,N>& vs) {
315 static_cast<I*
>(
this)->
copy(n,vs);
323 inline void copy(
const tIndex& n,
const std::valarray<Q>& vs) {
324 static_cast<I*
>(
this)->
copy(n,vs);
333 inline void copy(
const tIndex& n,
const std::vector<Q>& vs) {
334 static_cast<I*
>(
this)->
copy(n,vs);
342 inline void copy(
const tIndex& n,
const std::initializer_list<T>& vs) {
343 static_cast<I*
>(
this)->
copy(n,vs);
349 inline void copy(
const tIndex& n,std::initializer_list<T>&& vs) {
350 static_cast<I*
>(
this)->
copy(n,vs);
357 template<
typename Q,
class I1>
359 static_cast<I*
>(
this)->
copy(cpy);
365 template<
typename Q,
class I1>
367 static_cast<I
>(*this)->copy(cpy);
398 if (std::is_floating_point_v<T>)
421 return (*
static_cast<I*
>(
this))+=v;
428 return (*
static_cast<I*
>(
this))-=v;
435 return (*
static_cast<I*
>(
this))*=v;
442 return (*
static_cast<I*
>(
this))/=v;
451 inline I&
operator%=(
const T& v) requires functions_type::isIntegerType<T> {
452 return (*
static_cast<I
>(
this))%=v;
458 inline I& operator&=(
const T& v) requires functions_type::isIntegerType<T> {
459 return (*
static_cast<I
>(
this))&=v;
465 inline I& operator|=(
const T& v)requires functions_type::isIntegerType<T> {
466 return (*
static_cast<I
>(
this))|=v;
472 inline I& operator^=(
const T& v) requires functions_type::isIntegerType<T> {
473 return (*
static_cast<I
>(
this))^=v;
478 inline I& operator<<=(
const T& v) requires functions_type::isIntegerType<T> {
479 return (*
static_cast<I
>(
this))<<=v;
485 inline I& operator>>=(
const T& v) requires functions_type::isIntegerType<T> {
486 return (*
static_cast<I
>(
this))>>=v;
496 template<
typename Q,
class I1>
498 return (*
static_cast<I*
>(
this))+=v;
503 template<
typename Q,
class I1>
505 return (*
static_cast<I*
>(
this))-=v;
510 template<
typename Q,
class I1>
512 return (*
static_cast<I*
>(
this))*=v;
517 template<
typename Q,
class I1>
519 return (*
static_cast<I*
>(
this))/=v;
531 template<
typename LambdaFct>
540 template<
typename LambdaFct>
551 template<
typename LambdaFct>
566 static_cast<I*
>(
this)->
swap(a);
572 inline void swap(
const tIndex& i,
const tIndex& j) {
573 static_cast<I*
>(
this)->
swap(i,j);
592 template<
typename Q,
class I1>
594 static_cast<I*
>(
this)->
axpy(alpha,X,beta);
622 inline void sum(T& s)
const {
623 return static_cast<const I*
>(
this)->
sum(s);
629 static_cast<const I*
>(
this)->
prod(p);
636 template<
typename Q,
class I1>
646 return static_cast<const I*
>(
this)->
l2Norm2();
659 template<
typename Q,
class I1>
661 return static_cast<const I*
>(
this)->
l2Distance2(X);
667 template<
typename Q,
class I1>
677 return static_cast<const I*
>(
this)->
linfNorm(i);
683 template<
typename Q,
class I1>
695 inline void min(T& m)
const requires functions_type::isOrderedType<T>{
696 static_cast<const I*
>(
this)->min(m);
702 inline void max(T& m)
const requires functions_type::isOrderedType<T> {
703 return static_cast<const I*
>(
this)->min(m);
709 inline void sort() requires functions_type::isOrderedType<T> {
710 directionalSort(
'i');
716 inline void directionalSort(
const tUChar& order) requires functions_type::isOrderedType<T> {
717 static_cast<I*
>(
this)->directionalSort(order);
726 virtual tString
toString()
const override {
732 inline tString
toString(
const tIndex& nPrintedValues)
const {
735 std::stringstream ss;
737 if ((nPrintedValues==0) || (nPrintedValues>=n)) {
739 const T* eValues=values;
741 while (values!=eValues) {
742 ss<<std::setprecision(12)<<(*values)<<
",";
747 for (tInteger k=0;k<=nPrintedValues;k++) {
748 index=((n-1)*k)/nPrintedValues;
749 ss<<index<<
":"<<std::setprecision(12)<<values[index]<<
",";
752 ss.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
I & operator-=(const T &v)
sub operator
Definition: CORE_Array.h:427
auto sbegin()
return begin stride iterator for writing
Definition: CORE_Array.h:158
I & operator*=(const T &v)
multiplicator operator
Definition: CORE_Array.h:434
Self & operator=(const CORE_Array< Q, I1 > &cpy)
build an array by a copy of cpy
Definition: CORE_Array.h:266
void swap(const tIndex &i, const tIndex &j)
swap the two elements of the array
Definition: CORE_Array.h:572
Self & operator=(const T &v)
fill the values of the array with v
Definition: CORE_Array.h:223
virtual void setUniformRandomizeSeed(const tULLInt &seed)
set the uniform randomize seed
Definition: CORE_Array.h:386
Self & operator=(const std::vector< Q > &values)
build an array by a copy of c
Definition: CORE_Array.h:258
Self & operator=(const std::array< Q, N > &values)
build an array by a copy of c
Definition: CORE_Array.h:239
Self & operator=(CORE_Array< Q, I1 > &&cpy)
build an array by a copy of cpy
Definition: CORE_Array.h:281
I & operator*=(const CORE_Array< Q, I1 > &v)
array multiply operator
Definition: CORE_Array.h:511
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: CORE_Array.h:127
CORE_Array()
instanciation method of a class
Definition: CORE_Array.h:103
void sum(T &s) const
Computes the sum of all the elements.
Definition: CORE_Array.h:622
const T & get(const tIndex &i) const
get the i-th element for reading
Definition: CORE_Array.h:192
I & operator/=(const CORE_Array< Q, I1 > &v)
array divisor operator
Definition: CORE_Array.h:518
void transform(LambdaFct &&F)
transform the transform element with the lambda function Ti = F(Ti)
Definition: CORE_Array.h:532
void initialize(const T &v)
randomize the field
Definition: CORE_Array.h:378
tReal linfDistance(const CORE_Array< Q, I1 > &X, tIndex &i) const
compute the Linfinitty norm
Definition: CORE_Array.h:684
auto send()
return end N-stride iterator for writing
Definition: CORE_Array.h:165
T * getValues()
get the values of the array
Definition: CORE_Array.h:212
T & get(const tIndex &i)
get the i-th element for writting
Definition: CORE_Array.h:198
void copy(const CORE_Array< Q, I1 > &cpy)
copy the container
Definition: CORE_Array.h:358
void copy(CORE_Array< Q, I1 > &&cpy)
copy the conatiner : mv is destroyed after this
Definition: CORE_Array.h:366
tReal l2Norm() const
compute the L2 norm
Definition: CORE_Array.h:652
tReal l2Norm2() const
compute the L2 norm squared
Definition: CORE_Array.h:645
void transform(LambdaFct &&F, const Self &X, const Self &Y)
transform the transform element with the lambda function Ti = F(Xi,Yi)
Definition: CORE_Array.h:552
void copy(const tIndex &n, const std::valarray< Q > &vs)
initialize the array to the values of val array
Definition: CORE_Array.h:323
void uniformRandomize(const T &min, const T &max)
randomize the field
Definition: CORE_Array.h:407
void prod(T &p) const
return the produc of all the elements
Definition: CORE_Array.h:628
void copy(const tIndex &n, const std::vector< Q > &vs)
initialize the array to the values of vector
Definition: CORE_Array.h:333
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: CORE_Array.h:607
I & operator%=(const T &v) requires functions_type
modulo operator
Definition: CORE_Array.h:451
void copy(const tIndex &n, const Q *vs)
initialize the array to the values of pointer of size n
Definition: CORE_Array.h:304
void normalize()
normalize the array
Definition: CORE_Array.h:579
void setUniformRandomizeSeed()
set the uniform randomize seed
Definition: CORE_Array.h:391
Self & operator=(Self &&cpy)
build an array by a copy of cpy
Definition: CORE_Array.h:288
const T * getValues() const
get the values of the array for reading
Definition: CORE_Array.h:206
constexpr auto csbegin() const
return begin N-stride const iterator for writing
Definition: CORE_Array.h:173
void transform(LambdaFct &&F, const Self &X)
transform the transform element with the lambda function Ti = F(Xi)
Definition: CORE_Array.h:541
I & operator-=(const CORE_Array< Q, I1 > &v)
array sub operator
Definition: CORE_Array.h:504
constexpr auto csend() const
return end N-stride const iterator for writing
Definition: CORE_Array.h:180
Self & operator=(const std::valarray< Q > &values)
build an array by a copy of c
Definition: CORE_Array.h:249
tReal l2Distance2(const CORE_Array< Q, I1 > &X) const
compute the L2 distance squared
Definition: CORE_Array.h:660
void copy(const tIndex &n, const std::initializer_list< T > &vs)
initialize the array to the values of list
Definition: CORE_Array.h:342
tReal linfNorm(tIndex &i) const
compute the L infinity norm
Definition: CORE_Array.h:676
I & operator+=(const T &v)
add operator
Definition: CORE_Array.h:420
I & operator/=(const T &v)
divisor operator
Definition: CORE_Array.h:441
void axpy(const Q &alpha, const CORE_Array< Q, I1 > &X, const T &beta)
compute This=beta.This+ alpha .X
Definition: CORE_Array.h:593
void swap(Self &a)
swap the contents of the array
Definition: CORE_Array.h:565
virtual ~CORE_Array()
destroy an instance of class
Definition: CORE_Array.h:111
T & scalarProduct(const CORE_Array< Q, I1 > &X, T &s) const
return the scalar product
Definition: CORE_Array.h:637
void uniformRandomize()
randomize the field
Definition: CORE_Array.h:397
Self & operator=(const Self &cpy)
build an array by a copy of cpy
Definition: CORE_Array.h:273
void copy(const tIndex &n, const std::array< Q, N > &vs)
initialize the array to the values of array of size N
Definition: CORE_Array.h:314
void copy(const tIndex &n, std::initializer_list< T > &&vs)
initialize the array to the values of list
Definition: CORE_Array.h:349
Self & operator=(std::initializer_list< T > values)
build an array by a copy of c
Definition: CORE_Array.h:230
tReal l2Distance(const CORE_Array< Q, I1 > &X) const
compute the L2 distance
Definition: CORE_Array.h:668
this class describes a general container of values of type T where implemented class is I
Definition: CORE_Collection.h:49
tIndex getSize() const
return the size of the container
Definition: CORE_Collection.h:111
virtual tString toString() const override
return the string representation of the object node
Definition: CORE_Collection.h:257
this class describes a const iterator with a constant stride
Definition: CORE_ConstantStrideIterator.h:12
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
this class describes a const iterator with a constant stride 2 templates parameter:
Definition: CORE_StrideIterator.h:12