ignore valgrind core files
[valse.git] / src / test / test.EMGrank.c
CommitLineData
7b272073
BA
1#include "EMGrank.h"
2#include "ioutils.h"
3
4int main(int argc, char** argv)
5{
6 // read dimensions
7ea8c1e5
BA
7 const int nbDims = 4;
8 int* dimensions = readArray_int("dimensions",&nbDims,1);
9 int n = dimensions[0];
10 int p = dimensions[1];
11 int m = dimensions[2];
12 int k = dimensions[3];
7b272073 13 free(dimensions);
7ea8c1e5 14 int lengthOne = 1;
7b272073
BA
15
16 ////////////
17 // INPUTS //
18 ////////////
19
20 // Rho
7ea8c1e5
BA
21 const int dimRho[] = {m, m, k};
22 float* Rho = readArray_real("Rho",dimRho,3);
7b272073
BA
23
24 // Pi
7ea8c1e5 25 float* Pi = readArray_real("Pi",&k,1);
7b272073
BA
26
27 // min number of iterations
7ea8c1e5
BA
28 int* pmini = readArray_int("mini",&lengthOne,1);
29 int mini = *pmini;
7b272073
BA
30 free(pmini);
31
32 // max number of iterations
7ea8c1e5
BA
33 int* pmaxi = readArray_int("maxi",&lengthOne,1);
34 int maxi = *pmaxi;
7b272073
BA
35 free(pmaxi);
36
37 // X
7ea8c1e5
BA
38 const int dimX[] = {n, p};
39 float* X = readArray_real("X",dimX, 2);
7b272073
BA
40
41 // Y
7ea8c1e5
BA
42 const int dimY[] = {n, m};
43 float* Y = readArray_real("Y",dimY, 2);
7b272073
BA
44
45 // tau
7ea8c1e5
BA
46 float* ptau = readArray_real("tau",&lengthOne,1);
47 float tau = *ptau;
7b272073
BA
48 free(ptau);
49
50 // tau
7ea8c1e5 51 int* rank = readArray_int("rank",&k,1);
7b272073
BA
52
53 /////////////
54 // OUTPUTS //
55 /////////////
56
57 // phi
7ea8c1e5
BA
58 const int dimPhi[] = {p, m, k};
59 float* phi = (float*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*sizeof(float));
7b272073
BA
60
61 // LLF
7ea8c1e5 62 float* LLF = (float*)malloc(1*sizeof(float));
7b272073
BA
63
64 //////////////////////////
65 // Main call to EMGrank //
66 //////////////////////////
67
68 EMGrank(Pi,Rho,mini,maxi,X,Y,tau,rank,
69 phi,LLF,
70 n,p,m,k);
71
72 // free input pointers
73 free(Rho);
74 free(Pi);
75 free(X);
76 free(Y);
77 free(rank);
78
79 // Compare to reference outputs
7ea8c1e5 80 float* ref_phi = readArray_real("phi",dimPhi, 3);
7b272073
BA
81 compareArray_real("phi", phi, ref_phi, dimPhi[0]*dimPhi[1]*dimPhi[2]);
82 free(phi);
83 free(ref_phi);
84
85 // LLF
7ea8c1e5 86 float* ref_LLF = readArray_real("LLF",&lengthOne,1);
7b272073
BA
87 compareArray_real("LLF", LLF, ref_LLF, 1);
88 free(LLF);
89 free(ref_LLF);
90
91 return 0;
92}