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
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 //
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);
#include "EMGLLF.h"
-#include "ioutils.h"
+#include "utils.h"
+#include <stdlib.h>
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 //
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);
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 //
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);
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);
/////////////
/////////////
// 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 //
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);
#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);
/////////////
/////////////
// 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 //
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);
// 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<size; i++)
+ float maxError = 0.0;
+ for (int i=0; i<size; i++)
{
- Real error = isInteger
- ? fabs(((Int*)array)[i] - ((Int*)refArray)[i])
- : fabs(((Real*)array)[i] - ((Real*)refArray)[i]);
+ float error = isinteger
+ ? fabs(((int*)array)[i] - ((int*)refArray)[i])
+ : fabs(((float*)array)[i] - ((float*)refArray)[i]);
if (error >= maxError)
maxError = error;
}
}
// 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<nbDims; i++)
- totalDim *= dimensions[i];
- size_t elementSize = isInteger
- ? sizeof(Int)
- : sizeof(Real);
-
+ size_t elementSize = isinteger
+ ? sizeof(int)
+ : sizeof(float);
+
// read all values, and convert them to by-rows matrices format
- void* matlabArray = malloc(totalDim*elementSize);
+ void* array = malloc(n*elementSize);
char curChar = ' ';
char bufferNum[64];
- for (mwSize u=0; u<totalDim; u++)
+ for (int u=0; u<n; u++)
{
- // position to next non-separator character
- while (!feof(file) && (curChar==' ' || curChar=='\n' || curChar=='\t' || curChar==','))
- curChar = fgetc(file);
// read number (as a string)
int bufferIndex = 0;
- while (!feof(file) && curChar!=' ' && curChar!='\n' && curChar!='\t' && curChar!=',')
+ while (!feof(file) && curChar!=' ')
{
- bufferNum[bufferIndex++] = curChar;
curChar = fgetc(file);
+ bufferNum[bufferIndex++] = curChar;
}
bufferNum[bufferIndex] = 0;
- // transform string into Real, and store it at appropriate location
- if (isInteger)
- ((Int*)matlabArray)[u] = atoi(bufferNum);
+ // transform string into float, and store it at appropriate location
+ if (isinteger)
+ ((int*)array)[u] = atoi(bufferNum);
else
- ((Real*)matlabArray)[u] = atof(bufferNum);
+ ((float*)array)[u] = atof(bufferNum);
+ // position to next non-separator character
+ curChar = fgetc(file);
}
fclose(file);
-
- void* brArray = matlabToBrArray(matlabArray, dimensions, nbDims, isInteger);
- free(matlabArray);
- return brArray;
+
+ return array;
}
+int* readArray_int(const char* fileName)
+{
+ return (int*)readArray(fileName, 1);
+}
+
+float* readArray_real(const char* fileName)
+{
+ return (int*)readArray(fileName, 0);
+}
+
+int read_int(const char* fileName)
+{
+ return readArray_int(fileName)[0];
+}
+
+float read_real(const char* fileName)
+{
+ return readArray_real(fileName)[0];
+}
--- /dev/null
+// Check if array == refArray
+void compareArray(const char* ID, const void* array, const void* refArray, int size, int isInteger);
+
+void compareArray_real(const char* ID, const void* array, const void* refArray, int size);
+
+void compareArray_int(const char* ID, const void* array, const void* refArray, int size);
+
+// Read array by columns (as in MATLAB) and return by-rows encoding
+void* readArray(const char* fileName, int isInteger);
+
+int* readArray_int(const char* fileName);
+
+float* readArray_real(const char* fileName);
+
+int read_int(const char* fileName);
+
+float read_real(const char* fileName);