From 7ea8c1e58b3ab98eda5b003ccdffe5e35222bb4f Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Thu, 12 Jan 2017 16:21:25 +0100 Subject: [PATCH] test almost working --- .../{.test.EMGLLF.c.swp => .Makefile.swp} | Bin 12288 -> 12288 bytes src/test/.utils.c.swp | Bin 12288 -> 0 bytes src/test/Makefile | 18 ++-- src/test/test.ConstructionModelesLassoMLE.c | 90 ++++++++--------- src/test/test.EMGLLF.c | 55 +++++------ src/test/test.EMGrank.c | 52 +++++----- src/test/test.constructionModelesLassoRank.c | 70 +++++++------- src/test/test.selectiontotale.c | 84 ++++++++-------- src/test/utils.c | 91 +++++++++++------- src/test/utils.h | 17 ++++ 10 files changed, 261 insertions(+), 216 deletions(-) rename src/test/{.test.EMGLLF.c.swp => .Makefile.swp} (79%) delete mode 100644 src/test/.utils.c.swp create mode 100644 src/test/utils.h diff --git a/src/test/.test.EMGLLF.c.swp b/src/test/.Makefile.swp similarity index 79% rename from src/test/.test.EMGLLF.c.swp rename to src/test/.Makefile.swp index 176ac00789fa190350c8e35d63ce68e5f447f061..bfa54d3242d716f99d03e59d79aec9385f9d18f4 100644 GIT binary patch literal 12288 zcmeI2Pfyf96u{q-ctAvrUObMn2sLSoaDhgQuqB`R(j`4)x2GQabvElv0UlQYWs}t^~LZ@y$+!d{k6#X*L zI2j-V0~zS0EqitpW~T3ETYc=-O?Lg-=0K_FA~HY*$N(8217v^NDZ-(A*6(S8U=WVyhSupLsk$#zFq?Of_y|? zBd?GI@sS#`fJ`8_ksHVmQbMvi&!J~3nGBEtGC&5%02v?yWPl9(M+1)YsJ6EH%wwUH zj7t&5jAsqNaI(kj7AsE%{-TA=MzyhFK|bo`u}4979K{^R)vA|ppqpzK6Lg%fZ4*!({bWE5YVcwPC@yqdYe5@KcwRw@e93M;DkfnumQbZwWhE zNWoKl(Rf3pp%fnb-B~Q@WG#P@n5$T)NiWM?R}oI5gHUU=9>%-HEN6ubGG(>Ck{o9* zdV?hTQ(^U>+NX4k7-T}MH3*iA+(25htE68%7(C; z4efVi#KR;yxj}dqgaO$b?@g`};b;ZL!fu*XZsrTr_H&on@;K@+#EeSZp|Y(de)4S@ zYSUADUC6hWiD)xhr_p>n?#<0H`$??q&R$n`cqg@6y*OLgb|knAlhAA+sF<4DoWoBS CK4?1t literal 12288 zcmeI2&x;&I6vrzD$%k4>4A!JbqYQkz_)Y(mD5LtSAYBR-7|FF7e zHHwJnCE`JE>RAK@Z{k7y3j{CX5A+gGo}$s4r{K4K%uM%gFH0^$;5B@@tLnY#SMOV| zdl|OZI~SJE@e>OjhT|^A?p@pJo!@_hwYC@w#{;R&_#VgbawfG(lRey6FdPg5EweNa zw!%>^gIq^JA@jnX7M?nH=Iq(i3(;P;Av-BR3f!y$<6`6C6LW0w_%ZvaA8p>x@40*R zX757&qyQ;E3XlS%04YEUkOHItDR2ubP-Oeqn^^yCK8NT1b>FtD@6v@7AO%PPQh*d7 z1xNu>fD|AFNC8rS6d(m|K?TAAWBLGNKODs3@&EtH@BeFeGWHAj8GHr41fPNr!MorJ z=!3_>QE(9ad6==^z^~v7@D{iT9s+aV`W$25gU`SfpujWWX|MzYI0Ehi*Y05KTkru` z2akY7a0DCx{~TiMZ}16tAG`zJ204hp3V0Hn1RW57!{CqGkq`JBd<;GUFN0IyQScym z0NiLW_7nIHd;`7)?|}$h1ZTi$&;x6ff7;9{3DO*}@taay?e9yL`G|oaTPiY-qUehuhwVK_g;9bG3v*1}fZf}}7 zFTmJ#qx>;k!$EZtd`e;P3F9=7Z`Xu^1;KE3;k@H45(a8wxmj`es;b7!Oy6bdnl%wK zg@BoI@yvBwZkehHh)LB*dYDc_`F2e#SP%?n7tJ=}opNHlCZ?HO4Vn#0`MGvYP5z+TqqmhVA#KP`K0|sFf!ycLX=nB?wU&gLQsg^B2&$yWRaI+U5UBoI;!c>UB zNF0h$7_SdP(Gz`9gkymOf||o69*#yPYZr|N!7jd&C!z}-Tef89V@yq>mX*7mtJh?@ zVJ-7U4Oi8!qO1O9ox8Z(a;$o9?&1n1cC5r!+b;f4aEE{G%D3fjMLNH_^4#i5cc(f~ z)+EZIvac`yR>6QREhj_Y8_Tbde#zdevG=BS?zXcUz>Up(?8aAJ?2z?XP6}>hpV(DW zw3=pMW<>>6tr(czz0G~4d6#k?-cs^)#aZL(3?)xr&NZ&yQu4(Hnwqci^%mpn--iPg z%OuCg>A5Mz_?0e-lW$_`%<$skOEXhkH61URva0D=$&^%09b*G4>x6ig=a) diff --git a/src/test/.utils.c.swp b/src/test/.utils.c.swp deleted file mode 100644 index 61f8f0a0a69a776daa26eed84cb892c58b0f0ff6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHN&yN&E7%fOdTR@E-Jb18J1KYDZyEBVolx4()g*f4t2r6MASkqm-)1jw&QeC~v z2!wd^;?2awc=iwQpaJFTQ4bzGXgnZSLt;3YnE1Zx?%A1z4T*3esZJiV^L2e+y?XV& z>fO+t<_GO#{EgWr!}T0v--wknKYDkWzrvWvL#ZkLfU7&`OC6``0mE3M8-@)n`)Sr# z5lJQ+nGPC8W~PywILT&%2NiJlodQmQhfrWUdv*7mZS_|scJLRTfBzwBxm2fsQ@|OPzTP64NYQ@|gkjMZ3SAYNCdX}-zfUCe|;5_g)Fa>M{o&xSX!`MyW zQy>M-0v`ekz(3m=y9@jQ{0{sEd;(kpjsR`o9pKJ3#{L4X1K$DP0vc!m^T1}{##Y9@ z1O~uKU>`6KYyoaR&Dfv7ufTQSE8q%{0B3C0bkFlSD8^9O9=RgE(1O9%Bv0s26 zfDrfycoTRTcnSFTNpJ(c1_poz7J&s|H_!xbLBF4Xo51$~>3JP+ms7wg;1qBQJaPrD zGEYmBYsEWyL2EIXXI`YG^n1c2qGLlf#8%QcoT|p~7B6m}P7f4Wqr>YwjC)dLc$qD$ zbJbald-#mAwlZ>AYO01gf+WqPAH|8J0BCrg@4qKSGF2O$dMQ7T*@Q_WzmrFi)W`E4 zC3q6=z7w-zs3XEjRrSbs4Pl#k7q{5YMIB%q@0M@ z23ETei~Bnw2{Ej2eAljO(2mw5pB(>wPOT4^b%FY14Rx_#K0>_W4Q;d(Ay;{?BQ^I$ z#zmHa+Za(v4Yy>g`@j_*WtJOH9&0T87*K?(0Y#w0t(CMkKzaFwc=O!kF_ zM>G#0vIq>`xFpH2t=#Xeo{B$~Ja0AUdA`r2MkH_~ex9C2O-d+N4`(gC{@QuSZG&s; zgR%$~9Wdfe2-On_eBf6_r(`1Gd_xnGNh=94isNO?T%r%iQ$ea$q&D1iWserp8O-Q( zHKV4|aUe5JeiVlK#M{d=RKt#wC9U)KR}mN=E1=sK3?G>q#D*?Mg^C@YYK?T}QcNqg z3XuU~k|*9*bSr+c;?Ru{)#m1zT}*?n*?TX3`o!W1J0gm8W_Vv@8LjK0N>_Oo=m|Bb z7}`5lH?$Gz+S4Y=ljJb$eO&aca);YT4^440Ii`=&zEu9`kUF2x6C?(D7Hzoh9;H=< z?mJ*26h<^`0orOzG%`IV^lh{j6uY};8buOfP}QBDtCyQX18e10D=9--bsul%O6>CF z>}J><`i&I!G1-+KX^0)vbea zWMg$}xjLW2QVYhIa4qEm*p2a~62&@-)s^K&Lu;jJX(VUu|1fH9z=*_tRFpg%`N~B8 z1jlva$T?-5Q$B!3@3oZ(aBPTRuosrUB6 zvndb+qvzzzo_XGApv8iie!+kn?elBMp=SGO%$*N!gF5w_<;Jm5Rv+GK4ZDN=2a{1Z A1^@s6 diff --git a/src/test/Makefile b/src/test/Makefile index c4931ad..796b424 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -1,32 +1,34 @@ CC = gcc CFLAGS = -g -std=gnu99 -Wno-implicit-function-declaration -LDFLAGS = -Lobj/ -lvalse_core +LDFLAGS = -lm -lgsl -lcblas -lgomp +LDFLAGS_TEST = -Lobj/ -lvalse_core LIB = valse_core.so LIB_SRC = $(wildcard ../sources/*.c) LIB_OBJ = $(LIB_SRC:.c=.o) +INCLUDES = -I../sources all: $(LIB) test.EMGLLF test.EMGrank test.constructionModelesLassoMLE test.EMGrank test.constructionModelesLassoRank test.selectionTotale $(LIB): $(LIB_OBJ) - $(CC) -o $@ $^ + $(CC) -shared -o $@ $^ $(LDFLAGS) test.EMGLLF: test.EMGLLF.o - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $^ $(LDFLAGS) $(TEST_LDFLAGS) test.constructionModelesLassoMLE: test.constructionModelesLassoMLE.o - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $^ $(LDFLAGS) $(TEST_LDFLAGS) test.EMGrank: test.EMGrank.o - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $^ $(LDFLAGS) $(TEST_LDFLAGS) test.constructionModelesLassoRank: test.constructionModelesLassoRank.o - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $^ $(LDFLAGS) $(TEST_LDFLAGS) test.selectionTotale: test.selectionTotale.o - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $^ $(LDFLAGS) $(TEST_LDFLAGS) %.o: %.c - $(CC) -o $@ -c $< $(CFLAGS) + $(CC) -o $@ -c $< $(CFLAGS) $(INCLUDES) clean: rm -f *.o ../sources/*.o diff --git a/src/test/test.ConstructionModelesLassoMLE.c b/src/test/test.ConstructionModelesLassoMLE.c index a6c0cce..198d5a8 100644 --- a/src/test/test.ConstructionModelesLassoMLE.c +++ b/src/test/test.ConstructionModelesLassoMLE.c @@ -4,97 +4,97 @@ int main(int argc, char** argv) { // read dimensions - const Int nbDims = 5; - Int* dimensions = readArray_int("dimensions",&nbDims,1); - mwSize n = dimensions[0]; - mwSize p = dimensions[1]; - mwSize m = dimensions[2]; - mwSize k = dimensions[3]; - mwSize L = dimensions[4]; + const int nbDims = 5; + int* dimensions = readArray_int("dimensions",&nbDims,1); + int n = dimensions[0]; + int p = dimensions[1]; + int m = dimensions[2]; + int k = dimensions[3]; + int L = dimensions[4]; free(dimensions); - mwSize lengthOne = 1; + int lengthOne = 1; //////////// // INPUTS // //////////// // phiInit - const mwSize dimPhiInit[] = {p, m, k}; - Real* phiInit = readArray_real("phiInit",dimPhiInit,3); + const int dimPhiInit[] = {p, m, k}; + float* phiInit = readArray_real("phiInit",dimPhiInit,3); // rhoInit - const mwSize dimRhoInit[] = {m, m, k}; - Real* rhoInit = readArray_real("rhoInit",dimRhoInit,3); + const int dimRhoInit[] = {m, m, k}; + float* rhoInit = readArray_real("rhoInit",dimRhoInit,3); // piInit - Real* piInit = readArray_real("piInit",&k,1); + float* piInit = readArray_real("piInit",&k,1); // gamInit - const mwSize dimGamInit[] = {n, k}; - Real* gamInit = readArray_real("gamInit",dimGamInit,2); + const int dimGamInit[] = {n, k}; + float* gamInit = readArray_real("gamInit",dimGamInit,2); // min number of iterations - Int* pmini = readArray_int("mini",&lengthOne,1); - Int mini = *pmini; + int* pmini = readArray_int("mini",&lengthOne,1); + int mini = *pmini; free(pmini); // max number of iterations - Int* pmaxi = readArray_int("maxi",&lengthOne,1); - Int maxi = *pmaxi; + int* pmaxi = readArray_int("maxi",&lengthOne,1); + int maxi = *pmaxi; free(pmaxi); // gamma - Real* pgamma = readArray_real("gamma",&lengthOne,1); - Real gamma = *pgamma; + float* pgamma = readArray_real("gamma",&lengthOne,1); + float gamma = *pgamma; free(pgamma); // lambda - Real* glambda = readArray_real("glambda",&L,1); + float* glambda = readArray_real("glambda",&L,1); // X - const mwSize dimX[] = {n, p}; - Real* X = readArray_real("X",dimX,2); + const int dimX[] = {n, p}; + float* X = readArray_real("X",dimX,2); // Y - const mwSize dimY[] = {n, m}; - Real* Y = readArray_real("Y",dimY,2); + const int dimY[] = {n, m}; + float* Y = readArray_real("Y",dimY,2); // seuil - Real* pseuil = readArray_real("seuil",&lengthOne,1); - Real seuil = *pseuil; + float* pseuil = readArray_real("seuil",&lengthOne,1); + float seuil = *pseuil; free(pseuil); // tau - Real* ptau = readArray_real("tau",&lengthOne,1); - Real tau = *ptau; + float* ptau = readArray_real("tau",&lengthOne,1); + float tau = *ptau; free(ptau); // A1 - const mwSize dimA[] = {p, m+1, L}; - Int* A1 = readArray_int("A1",dimA,3); + const int dimA[] = {p, m+1, L}; + int* A1 = readArray_int("A1",dimA,3); // A2 - Int* A2 = readArray_int("A2",dimA,3); + int* A2 = readArray_int("A2",dimA,3); ///////////// // OUTPUTS // ///////////// // phi - const mwSize dimPhi[] = {dimPhiInit[0], dimPhiInit[1], dimPhiInit[2], L}; - Real* phi = (Real*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]*sizeof(Real)); + const int dimPhi[] = {dimPhiInit[0], dimPhiInit[1], dimPhiInit[2], L}; + float* phi = (float*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]*sizeof(float)); // rho - const mwSize dimRho[] = {dimRhoInit[0], dimRhoInit[1], dimRhoInit[2], L}; - Real* rho = (Real*)malloc(dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]*sizeof(Real)); + const int dimRho[] = {dimRhoInit[0], dimRhoInit[1], dimRhoInit[2], L}; + float* rho = (float*)malloc(dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]*sizeof(float)); // pi - const mwSize dimPi[] = {k, L}; - Real* pi = (Real*)malloc(dimPi[0]*dimPi[1]*sizeof(Real)); + const int dimPi[] = {k, L}; + float* pi = (float*)malloc(dimPi[0]*dimPi[1]*sizeof(float)); // lvraisemblance - const mwSize dimLvraisemblance[] = {L, 2}; - Real* lvraisemblance = (Real*)malloc(dimLvraisemblance[0]*dimLvraisemblance[1]*sizeof(Real)); + const int dimLvraisemblance[] = {L, 2}; + float* lvraisemblance = (float*)malloc(dimLvraisemblance[0]*dimLvraisemblance[1]*sizeof(float)); ///////////////////////////////////////// // Call to constructionModelesLassoMLE // @@ -116,25 +116,25 @@ int main(int argc, char** argv) free(glambda); // Compare to reference outputs - Real* ref_phi = readArray_real("phi",dimPhi,4); + float* ref_phi = readArray_real("phi",dimPhi,4); compareArray_real("phi", phi, ref_phi, dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]); free(phi); free(ref_phi); // rho - Real* ref_rho = readArray_real("rho",dimRho,4); + float* ref_rho = readArray_real("rho",dimRho,4); compareArray_real("rho", rho, ref_rho, dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]); free(rho); free(ref_rho); // pi - Real* ref_pi = readArray_real("pi",dimPi,2); + float* ref_pi = readArray_real("pi",dimPi,2); compareArray_real("pi", pi, ref_pi, dimPi[0]*dimPi[1]); free(pi); free(ref_pi); // lvraisemblance - Real* ref_lvraisemblance = readArray_real("lvraisemblance",dimLvraisemblance,2); + float* ref_lvraisemblance = readArray_real("lvraisemblance",dimLvraisemblance,2); compareArray_real("lvraisemblance", lvraisemblance, ref_lvraisemblance, dimLvraisemblance[0]*dimLvraisemblance[1]); free(lvraisemblance); free(ref_lvraisemblance); diff --git a/src/test/test.EMGLLF.c b/src/test/test.EMGLLF.c index 60516bc..e938b3a 100644 --- a/src/test/test.EMGLLF.c +++ b/src/test/test.EMGLLF.c @@ -1,5 +1,6 @@ #include "EMGLLF.h" -#include "ioutils.h" +#include "utils.h" +#include int main(int argc, char** argv) { @@ -7,34 +8,34 @@ int main(int argc, char** argv) // INPUTS // //////////// - Int* dimensions = readArray_int("dimensions"); - mwSize n = dimensions[0]; - mwSize p = dimensions[1]; - mwSize m = dimensions[2]; - mwSize k = dimensions[3]; + int* dimensions = readArray_int("dimensions"); + int n = dimensions[0]; + int p = dimensions[1]; + int m = dimensions[2]; + int k = dimensions[3]; free(dimensions); - Real* phiInit = readArray_real("phiInit"); - Real* rhoInit = readArray_real("rhoInit"); - Real* piInit = readArray_real("piInit"); - Real* gamInit = readArray_real("gamInit"); - Int mini = read_int("mini"); - Int maxi = read_int("maxi"); - Real gamma = read_real("gamma"); - Real lambda = read_real("lambda"); - Real* X = readArray_real("X"); - Real* Y = readArray_real("Y"); - Real tau = read_real("tau"); + float* phiInit = readArray_real("phiInit"); + float* rhoInit = readArray_real("rhoInit"); + float* piInit = readArray_real("piInit"); + float* gamInit = readArray_real("gamInit"); + int mini = read_int("mini"); + int maxi = read_int("maxi"); + float gamma = read_real("gamma"); + float lambda = read_real("lambda"); + float* X = readArray_real("X"); + float* Y = readArray_real("Y"); + float tau = read_real("tau"); ///////////// // OUTPUTS // ///////////// - Real* phi = (Real*)malloc(p*m*k*sizeof(Real)); - Real* rho = (Real*)malloc(m*m*k*sizeof(Real)); - Real* pi = (Real*)malloc(k*sizeof(Real)); - Real* LLF = (Real*)malloc(maxi*sizeof(Real)); - Real* S = (Real*)malloc(p*m*k*sizeof(Real)); + float* phi = (float*)malloc(p*m*k*sizeof(float)); + float* rho = (float*)malloc(m*m*k*sizeof(float)); + float* pi = (float*)malloc(k*sizeof(float)); + float* LLF = (float*)malloc(maxi*sizeof(float)); + float* S = (float*)malloc(p*m*k*sizeof(float)); //////////////////// // Call to EMGLLF // @@ -52,27 +53,27 @@ int main(int argc, char** argv) free(Y); // Compare to reference outputs - Real* ref_phi = readArray_real("phi"); + float* ref_phi = readArray_real("phi"); compareArray_real("phi", phi, ref_phi, p*m*k); free(phi); free(ref_phi); - Real* ref_rho = readArray_real("rho"); + float* ref_rho = readArray_real("rho"); compareArray_real("rho", rho, ref_rho, m*m*k); free(rho); free(ref_rho); - Real* ref_pi = readArray_real("pi"); + float* ref_pi = readArray_real("pi"); compareArray_real("pi", pi, ref_pi, k); free(pi); free(ref_pi); - Real* ref_LLF = readArray_real("LLF", maxi); + float* ref_LLF = readArray_real("LLF", maxi); compareArray_real("LLF", LLF, ref_LLF); free(LLF); free(ref_LLF); - Real* ref_S = readArray_real("S"); + float* ref_S = readArray_real("S"); compareArray_real("S", S, ref_S, p*m*k); free(S); free(ref_S); diff --git a/src/test/test.EMGrank.c b/src/test/test.EMGrank.c index 1227738..c6edbc2 100644 --- a/src/test/test.EMGrank.c +++ b/src/test/test.EMGrank.c @@ -4,62 +4,62 @@ int main(int argc, char** argv) { // read dimensions - const Int nbDims = 4; - Int* dimensions = readArray_int("dimensions",&nbDims,1); - mwSize n = dimensions[0]; - mwSize p = dimensions[1]; - mwSize m = dimensions[2]; - mwSize k = dimensions[3]; + const int nbDims = 4; + int* dimensions = readArray_int("dimensions",&nbDims,1); + int n = dimensions[0]; + int p = dimensions[1]; + int m = dimensions[2]; + int k = dimensions[3]; free(dimensions); - mwSize lengthOne = 1; + int lengthOne = 1; //////////// // INPUTS // //////////// // Rho - const mwSize dimRho[] = {m, m, k}; - Real* Rho = readArray_real("Rho",dimRho,3); + const int dimRho[] = {m, m, k}; + float* Rho = readArray_real("Rho",dimRho,3); // Pi - Real* Pi = readArray_real("Pi",&k,1); + float* Pi = readArray_real("Pi",&k,1); // min number of iterations - Int* pmini = readArray_int("mini",&lengthOne,1); - Int mini = *pmini; + int* pmini = readArray_int("mini",&lengthOne,1); + int mini = *pmini; free(pmini); // max number of iterations - Int* pmaxi = readArray_int("maxi",&lengthOne,1); - Int maxi = *pmaxi; + int* pmaxi = readArray_int("maxi",&lengthOne,1); + int maxi = *pmaxi; free(pmaxi); // X - const mwSize dimX[] = {n, p}; - Real* X = readArray_real("X",dimX, 2); + const int dimX[] = {n, p}; + float* X = readArray_real("X",dimX, 2); // Y - const mwSize dimY[] = {n, m}; - Real* Y = readArray_real("Y",dimY, 2); + const int dimY[] = {n, m}; + float* Y = readArray_real("Y",dimY, 2); // tau - Real* ptau = readArray_real("tau",&lengthOne,1); - Real tau = *ptau; + float* ptau = readArray_real("tau",&lengthOne,1); + float tau = *ptau; free(ptau); // tau - Int* rank = readArray_int("rank",&k,1); + int* rank = readArray_int("rank",&k,1); ///////////// // OUTPUTS // ///////////// // phi - const mwSize dimPhi[] = {p, m, k}; - Real* phi = (Real*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*sizeof(Real)); + const int dimPhi[] = {p, m, k}; + float* phi = (float*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*sizeof(float)); // LLF - Real* LLF = (Real*)malloc(1*sizeof(Real)); + float* LLF = (float*)malloc(1*sizeof(float)); ////////////////////////// // Main call to EMGrank // @@ -77,13 +77,13 @@ int main(int argc, char** argv) free(rank); // Compare to reference outputs - Real* ref_phi = readArray_real("phi",dimPhi, 3); + float* ref_phi = readArray_real("phi",dimPhi, 3); compareArray_real("phi", phi, ref_phi, dimPhi[0]*dimPhi[1]*dimPhi[2]); free(phi); free(ref_phi); // LLF - Real* ref_LLF = readArray_real("LLF",&lengthOne,1); + float* ref_LLF = readArray_real("LLF",&lengthOne,1); compareArray_real("LLF", LLF, ref_LLF, 1); free(LLF); free(ref_LLF); diff --git a/src/test/test.constructionModelesLassoRank.c b/src/test/test.constructionModelesLassoRank.c index 2232e9e..1060e20 100644 --- a/src/test/test.constructionModelesLassoRank.c +++ b/src/test/test.constructionModelesLassoRank.c @@ -4,63 +4,63 @@ int main(int argc, char** argv) { // read dimensions - const Int nbDims = 5; - Int* dimensions = readArray_int("dimensions",&nbDims,1); - mwSize n = dimensions[0]; - mwSize p = dimensions[1]; - mwSize m = dimensions[2]; - mwSize k = dimensions[3]; - mwSize L = dimensions[4]; + const int nbDims = 5; + int* dimensions = readArray_int("dimensions",&nbDims,1); + int n = dimensions[0]; + int p = dimensions[1]; + int m = dimensions[2]; + int k = dimensions[3]; + int L = dimensions[4]; free(dimensions); - mwSize lengthOne = 1; + int lengthOne = 1; //////////// // INPUTS // //////////// // piInit - const mwSize dimPi[] = {k, L}; - Real* Pi = readArray_real("Pi",dimPi,2); + const int dimPi[] = {k, L}; + float* Pi = readArray_real("Pi",dimPi,2); // rhoInit - const mwSize dimRho[] = {m, m, k, L}; - Real* Rho = readArray_real("Rho",dimRho,4); + const int dimRho[] = {m, m, k, L}; + float* Rho = readArray_real("Rho",dimRho,4); // min number of iterations - Int* pmini = readArray_int("mini",&lengthOne,1); - Int mini = *pmini; + int* pmini = readArray_int("mini",&lengthOne,1); + int mini = *pmini; free(pmini); // max number of iterations - Int* pmaxi = readArray_int("maxi",&lengthOne,1); - Int maxi = *pmaxi; + int* pmaxi = readArray_int("maxi",&lengthOne,1); + int maxi = *pmaxi; free(pmaxi); // X - const mwSize dimX[] = {n, p}; - Real* X = readArray_real("X",dimX,2); + const int dimX[] = {n, p}; + float* X = readArray_real("X",dimX,2); // Y - const mwSize dimY[] = {n, m}; - Real* Y = readArray_real("Y",dimY,2); + const int dimY[] = {n, m}; + float* Y = readArray_real("Y",dimY,2); // tau - Real* ptau = readArray_real("tau",&lengthOne,1); - Real tau = *ptau; + float* ptau = readArray_real("tau",&lengthOne,1); + float tau = *ptau; free(ptau); // A1 - const mwSize dimA[] = {p, L}; - Int* A1 = readArray_int("A1",dimA,2); + const int dimA[] = {p, L}; + int* A1 = readArray_int("A1",dimA,2); // rangmin - Int* prangmin = readArray_int("rangmin",&lengthOne,1); - Int rangmin = *prangmin; + int* prangmin = readArray_int("rangmin",&lengthOne,1); + int rangmin = *prangmin; free(prangmin); // rangmax - Int* prangmax = readArray_int("rangmax",&lengthOne,1); - Int rangmax = *prangmax; + int* prangmax = readArray_int("rangmax",&lengthOne,1); + int rangmax = *prangmax; free(prangmax); ///////////// @@ -68,13 +68,13 @@ int main(int argc, char** argv) ///////////// // phi - mwSize Size = (mwSize)pow(rangmax-rangmin+1, k); - const mwSize dimPhi[] = {p, m, k, L*Size}; - Real* phi = (Real*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]*sizeof(Real)); + int Size = (int)pow(rangmax-rangmin+1, k); + const int dimPhi[] = {p, m, k, L*Size}; + float* phi = (float*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]*sizeof(float)); // lvraisemblance - const mwSize dimLvraisemblance[] = {L*Size, 2}; - Real* lvraisemblance = (Real*)malloc(dimLvraisemblance[0]*dimLvraisemblance[1]*sizeof(Real)); + const int dimLvraisemblance[] = {L*Size, 2}; + float* lvraisemblance = (float*)malloc(dimLvraisemblance[0]*dimLvraisemblance[1]*sizeof(float)); ////////////////////////////////////////////// // Main call to constructionModelesLassoMLE // @@ -92,13 +92,13 @@ int main(int argc, char** argv) free(A1); // Compare to reference outputs - Real* ref_phi = readArray_real("phi",dimPhi, 4); + float* ref_phi = readArray_real("phi",dimPhi, 4); compareArray_real("phi", phi, ref_phi, dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]); free(phi); free(ref_phi); // lvraisemblance - Real* ref_lvraisemblance = readArray_real("lvraisemblance",dimLvraisemblance,2); + float* ref_lvraisemblance = readArray_real("lvraisemblance",dimLvraisemblance,2); compareArray_real("lvraisemblance", lvraisemblance, ref_lvraisemblance, dimLvraisemblance[0]*dimLvraisemblance[1]); free(lvraisemblance); free(ref_lvraisemblance); diff --git a/src/test/test.selectiontotale.c b/src/test/test.selectiontotale.c index 45cb461..ebfdf19 100644 --- a/src/test/test.selectiontotale.c +++ b/src/test/test.selectiontotale.c @@ -1,72 +1,72 @@ #include "selectiontotale.h" #include "ioutils.h" -mwSize main(mwSize argc, char** argv) +int main(int argc, char** argv) { // read dimensions - const Int nbDims = 5; - Int* dimensions = readArray_int("dimensions",&nbDims,1); - mwSize n = dimensions[0]; - mwSize p = dimensions[1]; - mwSize m = dimensions[2]; - mwSize k = dimensions[3]; - mwSize L = dimensions[4]; + const int nbDims = 5; + int* dimensions = readArray_int("dimensions",&nbDims,1); + int n = dimensions[0]; + int p = dimensions[1]; + int m = dimensions[2]; + int k = dimensions[3]; + int L = dimensions[4]; free(dimensions); - mwSize lengthOne = 1; + int lengthOne = 1; //////////// // INPUTS // //////////// // phiInit - const mwSize dimPhiInit[] = {p, m, k}; - Real* phiInit = readArray_real("phiInit",dimPhiInit,3); + const int dimPhiInit[] = {p, m, k}; + float* phiInit = readArray_real("phiInit",dimPhiInit,3); // rhoInit - const mwSize dimRhoInit[] = {m, m, k}; - Real* rhoInit = readArray_real("rhoInit",dimRhoInit,3); + const int dimRhoInit[] = {m, m, k}; + float* rhoInit = readArray_real("rhoInit",dimRhoInit,3); // piInit - Real* piInit = readArray_real("piInit",&k,1); + float* piInit = readArray_real("piInit",&k,1); // gamInit - const mwSize dimGamInit[] = {n, k}; - Real* gamInit = readArray_real("gamInit",dimGamInit, 2); + const int dimGamInit[] = {n, k}; + float* gamInit = readArray_real("gamInit",dimGamInit, 2); // min number of iterations - Int* pmini = readArray_int("mini",&lengthOne,1); - Int mini = *pmini; + int* pmini = readArray_int("mini",&lengthOne,1); + int mini = *pmini; free(pmini); // max number of iterations - Int* pmaxi = readArray_int("maxi",&lengthOne,1); - Int maxi = *pmaxi; + int* pmaxi = readArray_int("maxi",&lengthOne,1); + int maxi = *pmaxi; free(pmaxi); // gamma - Real* pgamma = readArray_real("gamma",&lengthOne,1); - Real gamma = *pgamma; + float* pgamma = readArray_real("gamma",&lengthOne,1); + float gamma = *pgamma; free(pgamma); // lambda - Real* glambda = readArray_real("glambda",&L,1); + float* glambda = readArray_real("glambda",&L,1); // X - const mwSize dimX[] = {n, p}; - Real* X = readArray_real("X",dimX,2); + const int dimX[] = {n, p}; + float* X = readArray_real("X",dimX,2); // Y - const mwSize dimY[] = {n, m}; - Real* Y = readArray_real("Y",dimY,2); + const int dimY[] = {n, m}; + float* Y = readArray_real("Y",dimY,2); // seuil - Real* pseuil = readArray_real("seuil",&lengthOne,1); - Real seuil = *pseuil; + float* pseuil = readArray_real("seuil",&lengthOne,1); + float seuil = *pseuil; free(pseuil); // tau - Real* ptau = readArray_real("tau",&lengthOne,1); - Real tau = *ptau; + float* ptau = readArray_real("tau",&lengthOne,1); + float tau = *ptau; free(ptau); ///////////// @@ -74,19 +74,19 @@ mwSize main(mwSize argc, char** argv) ///////////// // A1 - const mwSize dimA[] = {p, m+1, L}; - Int* A1 = (Int*)malloc(dimA[0]*dimA[1]*dimA[2]*sizeof(Int)); + const int dimA[] = {p, m+1, L}; + int* A1 = (int*)malloc(dimA[0]*dimA[1]*dimA[2]*sizeof(int)); // A2 - Int* A2 = (Int*)malloc(dimA[0]*dimA[1]*dimA[2]*sizeof(Int)); + int* A2 = (int*)malloc(dimA[0]*dimA[1]*dimA[2]*sizeof(int)); // rho - const mwSize dimRho[] = {m, m, k, L}; - Real* Rho = (Real*)malloc(dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]*sizeof(Real)); + const int dimRho[] = {m, m, k, L}; + float* Rho = (float*)malloc(dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]*sizeof(float)); // pi - const mwSize dimPi[] = {k, L}; - Real* Pi = (Real*)malloc(dimPi[0]*dimPi[1]*sizeof(Real)); + const int dimPi[] = {k, L}; + float* Pi = (float*)malloc(dimPi[0]*dimPi[1]*sizeof(float)); ////////////////////////////////////////////// // Main call to constructionModelesLassoMLE // @@ -107,25 +107,25 @@ mwSize main(mwSize argc, char** argv) free(Y); // Compare to reference outputs - Int* ref_A1 = readArray_int("A1",dimA, 3); + int* ref_A1 = readArray_int("A1",dimA, 3); compareArray_int("A1", A1, ref_A1, dimA[0]*dimA[1]*dimA[2]); free(A1); free(ref_A1); // A2 - Int* ref_A2 = readArray_int("A2",dimA, 3); + int* ref_A2 = readArray_int("A2",dimA, 3); compareArray_int("A2", A2, ref_A2, dimA[0]*dimA[1]*dimA[2]); free(A2); free(ref_A2); // Rho - Real* ref_Rho = readArray_real("Rho",dimRho, 4); + float* ref_Rho = readArray_real("Rho",dimRho, 4); compareArray_real("Rho", Rho, ref_Rho, dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]); free(Rho); free(ref_Rho); // Pi - Real* ref_Pi = readArray_real("Pi",dimPi, 2); + float* ref_Pi = readArray_real("Pi",dimPi, 2); compareArray_real("Pi", Pi, ref_Pi, dimPi[0]*dimPi[1]); free(Pi); free(ref_Pi); diff --git a/src/test/utils.c b/src/test/utils.c index 7cdf740..8895cda 100644 --- a/src/test/utils.c +++ b/src/test/utils.c @@ -1,15 +1,15 @@ // Check if array == refArray void compareArray(const char* ID, const void* array, const void* refArray, int size, - int isInteger) + int isinteger) { - Real EPS = 1e-5; //precision + float EPS = 1e-5; //precision printf("Checking %s\n",ID); - Real maxError = 0.0; - for (mwSize i=0; i= maxError) maxError = error; } @@ -30,52 +30,77 @@ void compareArray_int(const char* ID, const void* array, const void* refArray, i } // Read array by columns (as in MATLAB) and return by-rows encoding -void* readArray(const char* fileName, int isInteger) +void* readArray(const char* fileName, int isinteger) { // need to prepend '../data/' (not really nice code...) - char* fullFileName = (char*)calloc(5+strlen(fileName)+1,sizeof(char)); + char* fullFileName = (char*)calloc(5+strlen(fileName)+1, sizeof(char)); strcat(fullFileName, "data/"); strcat(fullFileName, fileName); - FILE* file = fopen(fullFileName, "r"); - free(fullFileName); // first pass to know how many elements to allocate - // /////................... TODO + char* command = (char*)calloc(12+strlen(fullFileName)+8+1, sizeof(char)); + strcat(command, "grep -o ' ' "); + strcat(command, fullFileName); + strcat(command, " | wc -l"); + FILE *countSpaces = popen(command, "r"); + char* buffer = (char*)calloc(32, sizeof(char)); + fgets(buffer, sizeof(buffer), command); + int n = atoi(buffer) + 1; + free(buffer); + pclose(countSpaces); + + // open file for reading + FILE* file = fopen(fullFileName, "r"); + free(fullFileName); int d = 1; - for (int i=0; i