From: Benjamin Auder Date: Thu, 12 Jan 2017 15:21:25 +0000 (+0100) Subject: test almost working X-Git-Url: https://git.auder.net/variants/Chakart/doc/scripts/assets/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=7ea8c1e58b3ab98eda5b003ccdffe5e35222bb4f;p=valse.git test almost working --- 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 176ac00..bfa54d3 100644 Binary files a/src/test/.test.EMGLLF.c.swp and b/src/test/.Makefile.swp differ diff --git a/src/test/.utils.c.swp b/src/test/.utils.c.swp deleted file mode 100644 index 61f8f0a..0000000 Binary files a/src/test/.utils.c.swp and /dev/null differ 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