5 template<
typename T,
class I>
6 requires functions_type::isArithmeticType<T>
11 tBoolean ok=
true,succeeds=
true;
14 tReal eps=std::numeric_limits<float>::epsilon();
21 tMemSize memPtrA=
sizeof(T*)+
sizeof(tIndex)*2+8+
sizeof(
CORE_Object)+n*
sizeof(T);
29 tMemSize memValA=
sizeof(std::valarray<T>)+
sizeof(
CORE_Object)+n*
sizeof(T);
37 std::cout<<
"\t\t\t memory size verification [FAILED] \n";
39 std::cout<<
"\t\t\t memory size verification [OK] \n";
41 succeeds=succeeds&& ok;
48 std::cout<<
" A:"<<A<<
" ";
49 std::cout<<
"\t\t\t initialize to {1} [FAILED] \n";
51 std::cout<<
"\t\t\t initialization to {1} [OK] \n";
53 succeeds=succeeds&& ok;
57 for(
auto i=0;
const auto& v: A) {
62 std::cout<<
" A:"<<A<<
" ";
63 std::cout<<
"\t\t\t initialize to {1,2,3,4} [FAILED] \n";
65 std::cout<<
"\t\t\t initialization to {1,2,3,4} [OK] \n";
67 succeeds=succeeds&& ok;
75 }
catch(std::exception& e) {
79 std::cout<<
" A:"<<A<<
" ";
80 std::cout<<
"\t\t\t out bounds access detected [FAILED] \n";
82 std::cout<<
"\t\t\t out bounds access detected [OK] \n";
84 succeeds=succeeds&& ok;
93 std::cout<<
" A:"<<A<<
" ";
94 std::cout<<
"\t\t\t testing sum() & initialize(const T& v) [FAILED] \n";
96 std::cout<<
"\t\t\t testing sum() & initialize(const T& v) [OK] \n";
98 succeeds=succeeds&& ok;
104 std::cout<<
" A:"<<A<<
" ";
105 std::cout<<
"\t\t\t testing prod() [FAILED] \n";
107 std::cout<<
"\t\t\t testing prod() [OK] \n";
109 succeeds=succeeds&& ok;
113 for (tIndex i=0;i<n;i++) ok=ok && (
Equals(A[i],3));
115 std::cout<<
" A:"<<A<<
" ";
116 std::cout<<
"\t\t\t testing +=(const T& v) [FAILED] \n";
118 std::cout<<
"\t\t\t testing +=(const T& v) [OK] \n";
120 succeeds=succeeds&& ok;
123 CORE_UniquePointer<CORE_Array<T,I>> pB=I::New();
124 if (pB.get()==
null) {
125 std::cout<<
"New Instanced has failed";
130 B.uniformRandomize();
135 [&](
const auto & a) {
136 ok= ok && Equals(a,*b);
137 ok =ok && (a>=0) && (a<=1);
142 std::cout<<
" A:"<<A<<
" B="<<B<<
" ";
143 std::cout<<
"\t\t\t testing =(const CORE_Array& v) [FAILED] \n";
145 std::cout<<
"\t\t\t testing =(const CORE_Array& v) [OK] \n";
147 succeeds=succeeds&& ok;
152 ok=ok && (fabs(d)<eps);
154 std::cout<<
" A:"<<A<<
" B="<<B<<
" ";
155 std::cout<<
" linfMax:"<<d<<
" imax:"<<imax<<
"\n";
156 std::cout<<
"\t\t\t testing linfDistance [FAILED] \n";
158 std::cout<<
"\t\t\t testing linfDistance [OK] \n";
160 succeeds=succeeds&& ok;
164 ok=ok && (fabs(d)<eps);
166 std::cout<<
" A:"<<A<<
" B="<<B<<
" ";
167 std::cout<<
" l2:"<<d<<
"\n";
168 std::cout<<
"\t\t\t testing l2Distance [FAILED] \n";
170 std::cout<<
"\t\t\t testing l2Distance [OK] \n";
172 succeeds=succeeds&& ok;
179 ok= ok &&
Equals(A[2],B[1]);
181 std::cout<<
" A:"<<A<<
" B="<<B<<
" ";
182 std::cout<<
" 1<->2 swaping \n";
183 std::cout<<
"\t\t\t testing swaping element [FAILED] \n";
185 std::cout<<
"\t\t\t testing swaping element [OK] \n";
187 succeeds=succeeds&& ok;
191 auto lambda=[](
const tInteger& x) {
return x*x;};
195 for(
const auto Ci : C.getArray()) {
196 ok = ok && (
Equals(Ci,i*i));
200 std::cout<<
" C:"<<C<<
"\n";
201 std::cout<<
"\t\t\t testing transform(x^2) [FAILED] \n";
203 std::cout<<
"\t\t\t testing transform(x^2) [OK] \n";
205 succeeds=succeeds && ok;
209 succeeds = uniformRandomTest<T>(A,B) && succeeds;
215 ok = ok && (
Equals(A[i],i*i));
218 std::cout<<
" A:"<<A<<
" C:"<<C<<
"\n";
219 std::cout<<
"\t\t\t testing A.copy(C) [FAILED] \n";
221 std::cout<<
"\t\t\t testing A.copy(C) [OK] \n";
223 succeeds=ok & succeeds;
229 ok = ok && (
Equals(A[i],2));
232 std::cout<<
" A:"<<A<<
" C:"<<C<<
"\n";
233 std::cout<<
"\t\t\t testing A=C [FAILED] \n";
235 std::cout<<
"\t\t\t testing A=C [OK] \n";
237 succeeds=ok & succeeds;
245 tIndex N=256*256*256*3;
247 tReal alpha=1,beta=2;
248 std::cout<<
"\t\t\t testing Y:=beta.Y+alpha X for a size N="<<N<<
" randomizing... "<<std::flush;
256 B.uniformRandomize();
258 std::cout<<
" computing Y... "<<std::flush;
260 A.
axpy(alpha,B,beta);
261 tULLInt duration=timer.
stop();
262 std::cout<<
" time:"<<duration<<
" ms \n";
269 template<
typename T,
class I>
281 tIndex p,N=128*128*128;
312 tReal Pi=4.*((tReal)p)/((tReal)N);
314 tULLInt duration=timer.
stop();
315 tReal err=fabs(1-(Pi/M_PI));
317 std::cout<<
"\t\t\t Pi:"<<std::setprecision(12)<<Pi<<
" M_PI:"<<M_PI<<
" err="<<err<<
" (errMax="<<errMax<<
") p="<<p<<
" N="<<N<<
" in "<<duration<<
"ms ";
318 tBoolean ok=(err<errMax);
320 std::cout<<
" [FAILED] \n";
322 std::cout<<
" [OK] \n";
332 template<
typename T,
typename K,K D,
class S,
class I>
334 tBoolean ok=
true,succeeds=
true;
340 A={1,2,3,4,5,6,7,8,9,10};
344 for (
const auto &Ai : A) {
345 ok = ok && (
Equals(Ai,i));
349 std::cout<<
"error in copy initializer \n";
351 std::cout<<
"A="<<A<<
"\n";
352 std::cout<<
"\t\t\t testing A={1,2,3,4,5,6,7,8,9} [FAILED] \n";
354 std::cout<<
"\t\t\t testing A={1,2,3,4,5,6,7,8,9} [OK] \n";
357 succeeds=succeeds&& ok;
360 std::array<tReal,3> V={1,1,1};
366 ok=ok &&
Equals(A(i,k),1./sqrt(3.));
371 std::cout<<
" error in setting value to normalized of ("<<V[0]<<
","<<V[1]<<
","<<V[2]<<
")\n";
372 std::cout<<
"\t\t\t testing initialize(std::array<D>) [FAILED] \n";
374 std::cout<<
"\t\t\t testing initialize(std::array<D>) [OK] \n";
376 succeeds=succeeds&& ok;
383 std::cout<<
" A:"<<A<<
" ";
384 std::cout<<
"\t\t\t testing nan detection [FAILED] \n";
386 std::cout<<
"\t\t\t testing nan detection [OK] \n";
389 succeeds=succeeds&& ok;
394 ok=ok &&
Equals(A(1,0),1);
396 std::cout<<
" A:"<<A<<
" ";
397 std::cout<<
"\t\t\t testing +=1 [FAILED] \n";
399 std::cout<<
"\t\t\t testing +=1 [OK] \n";
401 succeeds=succeeds&& ok;
419 std::cout<<
"error in setting size/elements of A \n";
430 nD.
transform([](
const tReal& r) {
return (r<=1);});
436 tReal Pi=6.*((tReal)p)/((tReal)N);
438 tULLInt duration=timer.
stop();
439 tReal err=fabs(1-(Pi/M_PI));
441 std::cout<<
"\t\t\t Pi:"<<Pi<<
" err="<<err<<
" (errrMax="<<errMax<<
") with PI="<<M_PI<<
" with "<<N<<
" random values computed in "<<duration<<
"ms ";
444 std::cout<<
" [FAILED] \n";
446 std::cout<<
" [OK] \n";
448 succeeds=succeeds&& ok;
457 std::cout<<
" error in getElementsNumber() & setSize() \n";
468 ok=(fabs(r-1)<1.e-12);
472 std::cout<<
"\n error in normalization of A at index "<<i<<
" A=("<<A(i,0)<<
","<<A(i,1)<<
","<<A(i,2)<<
") norm:"<<r<<
"\n";
473 std::cout<<
"\t\t\t testing field normalization [FAILED] \n";
475 std::cout<<
"\t\t\t testing field normalization [OK] \n";
477 succeeds=succeeds&& ok;
487 std::cout<<
"error in setting setElementsNumber() & getSize() \n";
490 std::array<tReal,D> C= {1,1,1};
492 auto similitude=[&r,&C](
auto& Xi) {
493 auto iCid=C.cbegin();
494 std::for_each_n(&Xi,D,
495 [&r,&iCid](
auto &Xid){
506 r+=(A(i,k)-C[k])*(A(i,k)-C[k]);
509 ok=(fabs(r-2)<1.e-12);
514 std::cout<<
"\n error in similitude of A at index "<<i<<
" A=("<<A(i,0)<<
","<<A(i,1)<<
","<<A(i,2)<<
") |A-C(1,1,1)|:"<<r<<
"\n";
515 std::cout<<
"\t\t\t testing similitude transformation [FAILED] \n";
517 std::cout<<
"\t\t\t testing similitude transformation [OK] \n";
520 succeeds=succeeds&& ok;
525 A.
copy({1,2,3,4,5,6});
527 CORE_UniquePointer<CORE_Field<T,K,D,S,I>> pB=I::New();
528 if (pB.get()==
null) {
529 std::cout<<
"New Instanced has failed";
538 std::cout<<
"\n error <A,B>="<<s<<
" A="<<A<<
" B="<<B<<
"\n";
539 std::cout<<
"\t\t\t testing scalar product [FAILED] \n";
541 std::cout<<
"\t\t\t testing scalar product [OK] \n";
543 succeeds=succeeds&& ok;
551 std::cout<<
"\n error |B|="<<nD<<
" B="<<B<<
" \n";
552 std::cout<<
"\t\t\t testing norm2 [FAILED] \n";
554 std::cout<<
"\t\t\t testing norm2 [OK] \n";
556 succeeds=succeeds&& ok;
563 tReal alpha=1,beta=2;
564 std::cout<<
"\t\t\t testing Y:=beta.Y+alpha X for a size N="<<N<<
" ";
569 B.setElementsNumber(N);
570 B.uniformRandomize(0,1);
573 A.
axpy(alpha,B,beta);
574 duration=timer.
stop();
575 std::cout<<
" time:"<<duration<<
" ms \n";
this class describes an array of values T of dynamical size with algebrical operators and I is an imp...
Definition: CORE_Array.h:91
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
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
tReal linfDistance(const CORE_Array< Q, I1 > &X, tIndex &i) const
compute the Linfinitty norm
Definition: CORE_Array.h:684
void prod(T &p) const
return the produc of all the elements
Definition: CORE_Array.h:628
void copy(const tIndex &n, const Q *vs)
initialize the array to the values of pointer of size n
Definition: CORE_Array.h:304
const T * getValues() const
get the values of the array for reading
Definition: CORE_Array.h:206
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
void uniformRandomize()
randomize the field
Definition: CORE_Array.h:397
tReal l2Distance(const CORE_Array< Q, I1 > &X) const
compute the L2 distance
Definition: CORE_Array.h:668
this class describes the chono class by default write on standart output
Definition: CORE_Chrono.h:14
tULLInt stop()
stop the chrono and return the duration time in micro seconds as an int
Definition: CORE_Chrono.h:95
void start()
start the chrono
Definition: CORE_Chrono.h:89
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
void setSize(const tIndex &n)
set the size of the container
Definition: CORE_Collection.h:104
constexpr auto cend() const
return end iterator for reading
Definition: CORE_Collection.h:149
this class describes an field. A field is composed by
Definition: CORE_Field.h:49
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
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: CORE_Field.h:782
void copy(const tIndex &n, const Q *vs)
initialize the field to the values of pointer of size n
Definition: CORE_Field.h:447
void uniformRandomize(const T &min, const T &max)
randomize the field
Definition: CORE_Field.h:561
void elementsTransform(LambdaFct &&F)
apply the transform element with the lambda function Xid = F(Xid)
Definition: CORE_Field.h:733
void mod2(CORE_Array< T, I1 > &X) const
return the norm2 array per each element
Definition: CORE_Field.h:793
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:135
void initialize(const T &v)
initialize the field to v
Definition: CORE_Field.h:533
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:161
T & scalarProduct(const CORE_Field< Q, K, D, S1, I1 > &X, T &s) const
return the scalar product
Definition: CORE_Field.h:836
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:121
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
void setSize(const tIndex &n)
set the number of values of the container
Definition: CORE_Field.h:144
abstract base class for most classes.
Definition: CORE_Object.h:65
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
CORE_Object()
build an instance of the object
Definition: CORE_Object.cpp:9
static void Normalize(std::array< Q, N > &a)
normalize the array
Definition: CORE_StdPtrArray.h:836
this class describes a standart arithmetic array type implemented with a std::valarray object of type...
Definition: CORE_StdValArray.h:14
void sum(T &s) const
return the sum of all the elements
Definition: CORE_StdValArray.h:855
void transform(LambdaFct &&F)
transform the transform element with the lambda function Ti = F(const Ti)
Definition: CORE_StdValArray.h:674
tBoolean uniformRandomTest(CORE_Array< T, I > &A, CORE_Array< T, I > &B) const
randomizer test
Definition: CORE_Test.hpp:270
tBoolean testArray(const CORE_Run &runner, const CORE_OptionsList &options) const
test the numeric array
Definition: CORE_Test.cpp:754
requires functions_type::isRealType< T > static functions_type::isRealType< Q > tBoolean Equals(const T &a, const Q &b)
retrun true if the two values are equals
Definition: CORE_Test.h:226
tBoolean testField(const CORE_Run &runner, const CORE_OptionsList &options) const
test the numeric field
Definition: CORE_Test.cpp:773
tIndex getSize() const
return the size of the array for writing
Definition: CORE_ValArray.h:147