From af4e0dad95e1d96098f133948c7e0bfaca509099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20BOURGOIN?= <helene.bourgoin@ensiie.fr> Date: Fri, 4 Oct 2019 14:45:36 +0200 Subject: [PATCH] Replace matlab.h --- sgi2018/src/tools/matlab.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/sgi2018/src/tools/matlab.h b/sgi2018/src/tools/matlab.h index 27d163c..bd34c3f 100644 --- a/sgi2018/src/tools/matlab.h +++ b/sgi2018/src/tools/matlab.h @@ -144,9 +144,12 @@ long uniform() { // generate an uniformaly distributed random number sampled from [-1;1] inline number randu() { + printf("randu 1 "); //on le veut entre -1 et 1 / pour l'instant on l'a entre 0 et 1 - number result = uniform()/2147483647; //(double)0x7FFFFFFF; + //number result = uniform()/2147483647.0; //(double)0x7FFFFFFF; + number result = (uniform()-1073741823.5)/1073741823.5; // number result = (uniform() - (number)3xFFFFFFF.8)/(number)3xFFFFFFF.8); + printf("result : %f \n",result); return result; // throw std::logic_error("Function not yet implemented."); } @@ -155,6 +158,7 @@ inline number randu() // their real and imaginary parts are uniformaly distributed random number sampled from [-1;1] ComplexVector randu(int size) { + printf("randu 2 "); ComplexVector complexVector(size); std::complex<number> mycomplex; for(int i = 0; i < size; i++) @@ -162,6 +166,7 @@ ComplexVector randu(int size) std::complex<number> mycomplex(randu(), randu()); complexVector(i) = mycomplex; } + printf("randu 2 return "); return complexVector; //throw std::logic_error("Function not yet implemented."); @@ -171,12 +176,16 @@ ComplexVector randu(int size) // sampled from a distribution with mean 0 and std 1 inline number randn() { - - number res; - number U0 = uniform()/2147483647;//(double)0x7FFFFFFF; - number U1 = uniform()/2147483647;//(double)0x7FFFFFFF; + // printf("randn 1 "); + + number res=0; + printf(" randn 1 : %f ",res); + number U0 = uniform()/2147483647.0;//(double)0x7FFFFFFF; + number U1 = uniform()/2147483647.0;//(double)0x7FFFFFFF; + printf("u0: %f ---- ",U0); + printf("u1 : %f ----- ",U1); res = sqrt(-2 * log(U0)) * cos(2 * M_PI * U1); - + printf("result randn 1 : %f \n",res); return res; // throw std::logic_error("Function not yet implemented."); @@ -186,6 +195,7 @@ inline number randn() // their real and imaginary parts are sampled from a normal distribution with mean 0 and std 1 ComplexVector randn(int size) { + printf("randn 2 "); // NOTE: this can be built on the previous function ComplexVector complexVector(size); std::complex<number> mycomplex; @@ -194,6 +204,7 @@ ComplexVector randn(int size) std::complex<number> mycomplex(randn(), randn()); complexVector(i) = mycomplex; } + printf("randn 2 return \n"); return complexVector; //throw std::logic_error("Function not yet implemented."); } -- GitLab