remove utils.c, prepare testing 'R-only'
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 14 Jan 2017 03:27:48 +0000 (04:27 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 14 Jan 2017 03:27:48 +0000 (04:27 +0100)
19 files changed:
src/test/generate_test_data/MATLAB_test_helpers/Octave.m [deleted file]
src/test/generate_test_data/MATLAB_test_helpers/README [deleted file]
src/test/generate_test_data/MATLAB_test_helpers/covariance.m [deleted file]
src/test/generate_test_data/R_test_helpers/checkOutput.R [deleted file]
src/test/generate_test_data/R_test_helpers/covariance.R [deleted file]
src/test/generate_test_data/R_test_helpers/testEMGLLF.R [deleted file]
src/test/generate_test_data/helpers/EMGLLF.m [moved from src/test/generate_test_data/MATLAB_test_helpers/EMGLLF.m with 100% similarity]
src/test/generate_test_data/helpers/EMGrank.m [moved from src/test/generate_test_data/MATLAB_test_helpers/EMGrank.m with 100% similarity]
src/test/generate_test_data/helpers/basicInitParameters.m [moved from src/test/generate_test_data/MATLAB_test_helpers/basicInitParameters.m with 100% similarity]
src/test/generate_test_data/helpers/checkOutput.R [new file with mode: 0644]
src/test/generate_test_data/helpers/constructionModelesLassoMLE.m [moved from src/test/generate_test_data/MATLAB_test_helpers/constructionModelesLassoMLE.m with 100% similarity]
src/test/generate_test_data/helpers/constructionModelesLassoRank.m [moved from src/test/generate_test_data/MATLAB_test_helpers/constructionModelesLassoRank.m with 100% similarity]
src/test/generate_test_data/helpers/covariance.R [new file with mode: 0644]
src/test/generate_test_data/helpers/generateIO.m [moved from src/test/generate_test_data/MATLAB_test_helpers/generateIO.m with 100% similarity]
src/test/generate_test_data/helpers/generateIOdefault.m [moved from src/test/generate_test_data/MATLAB_test_helpers/generateIOdefault.m with 100% similarity]
src/test/generate_test_data/helpers/selectiontotale.m [moved from src/test/generate_test_data/MATLAB_test_helpers/selectiontotale.m with 100% similarity]
src/test/testEMGLLF.R [new file with mode: 0644]
src/test/utils.c [deleted file]
src/test/utils.h [deleted file]

diff --git a/src/test/generate_test_data/MATLAB_test_helpers/Octave.m b/src/test/generate_test_data/MATLAB_test_helpers/Octave.m
deleted file mode 100644 (file)
index 8f105d2..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-% Run this file if using Octave
-if exist('OCTAVE_VERSION', 'builtin') ~= 0
-       pkg load statistics %for random()
-       more off %to prevent bufferizing output
-end
diff --git a/src/test/generate_test_data/MATLAB_test_helpers/README b/src/test/generate_test_data/MATLAB_test_helpers/README
deleted file mode 100644 (file)
index e94c0a0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subset of select/ project: only files required to generate tests outputs
diff --git a/src/test/generate_test_data/MATLAB_test_helpers/covariance.m b/src/test/generate_test_data/MATLAB_test_helpers/covariance.m
deleted file mode 100644 (file)
index 839c33c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-%covariance matrix for tests on synthetic data: A(i,j) = a^|i-j|
-function[A] = covariance(p,a)
-
-       A = a*ones(p,p);
-       for i=1:p
-               A(i,:) = A(i,:) .^ abs(i-(1:p));
-       end
-
-end
diff --git a/src/test/generate_test_data/R_test_helpers/checkOutput.R b/src/test/generate_test_data/R_test_helpers/checkOutput.R
deleted file mode 100644 (file)
index 1faddaa..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-checkOutput = function(varName, matrix, refMatrix, tol){
-  print('Checking %s\n',varName);
-  maxError = max(max(max(max(abs(matrix - refMatrix)))));
-  if(maxError >= tol){
-    print('Inaccuracy: max(abs(error)) = %g >= %g\n',maxError,tol)
-  }
-  else{
-    print('OK\n')
-  }
-}
\ No newline at end of file
diff --git a/src/test/generate_test_data/R_test_helpers/covariance.R b/src/test/generate_test_data/R_test_helpers/covariance.R
deleted file mode 100644 (file)
index 2dea7f2..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-covariance= function(p,a){
-  A = matrix(a, p,p)
-  for{i in 1:p}{
-    for{k  in 1:p}{
-      A[i,]= A[i,]^abs(i-k) 
-    }
-  }
-  return(A=A)
-}
\ No newline at end of file
diff --git a/src/test/generate_test_data/R_test_helpers/testEMGLLF.R b/src/test/generate_test_data/R_test_helpers/testEMGLLF.R
deleted file mode 100644 (file)
index 0eb3483..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-testEMGLLF = function(){
-  testFolder = 'data/'
-  
-  #get dimensions
-  dimensions = read.table(strcat(testFolder,'dimensions'), header=FALSE)
-  n = dimensions[1]
-  p = dimensions[2]
-  m = dimensions[3]
-  k = dimensions[4]
-  
-  #get all input arrays
-  phiInit = read.table(strcat(testFolder,'phiInit'), header=FALSE)
-  rhoInit = read.table(strcat(testFolder,'rhoInit'), header=FALSE)
-  piInit = t(read.table(strcat(testFolder,'piInit'), header=FALSE))
-  gamInit = read.table(strcat(testFolder,'gamInit'), header=FALSE)
-  mini = read.table(strcat(testFolder,'mini'), header=FALSE)
-  maxi = read.table(strcat(testFolder,'maxi'), header=FALSE)
-  gamma = read.table(strcat(testFolder,'gamma'), header=FALSE)
-  lambda = read.table(strcat(testFolder,'lambda'), header=FALSE)
-  X = rread.table(strcat(testFolder,'X'), header=FALSE)
-  Y = read.table(strcat(testFolder,'Y'), header=FALSE)
-  tau = read.table(strcat(testFolder,'tau'), header=FALSE)
-  
-  #run EMGLLF.c
-  EMG = .Call("EMGLLF_core",phiInit,rhoInit,piInit1,gamInit,mini,maxi,gamma,lambda,X,Y,tau)
-  phi = EMG$phi
-  rho = EMG$rho
-  pi = EMG$pi
-  LLF = EMG$LLF
-  S = EMG$S
-  
-  #get all stored outputs
-  ref_phi =read.table(strcat(testFolder,'phi'), header=FALSE)
-  ref_rho = read.table(strcat(testFolder,'rho'), header=FALSE)
-  ref_pi = read.table(strcat(testFolder,'pi'), header=FALSE)
-  ref_LLF = read.table(strcat(testFolder,'LLF'), header=FALSE)
-  ref_S = read.table(strcat(testFolder,'S'), header=FALSE)
-  
-  #check that output correspond to stored output
-  tol = 1e-5;
-  checkOutput('phi',phi,ref_phi,tol);
-  checkOutput('rho',rho,ref_rho,tol);
-  checkOutput('pi',pi,ref_pi,tol);
-  checkOutput('LLF',LLF,ref_LLF,tol);
-  checkOutput('S',S,ref_S,tol);
-}
diff --git a/src/test/generate_test_data/helpers/checkOutput.R b/src/test/generate_test_data/helpers/checkOutput.R
new file mode 100644 (file)
index 0000000..187536a
--- /dev/null
@@ -0,0 +1,12 @@
+checkOutput = function(varName, array, refArray, tol)
+{
+       print(paste("Checking ",varName,sep=""))
+       maxError = max(abs(array - refArray))
+       if(maxError >= tol)
+       {
+               print(paste("Inaccuracy: max(abs(error)) = ",maxError," >= ",tol,sep=""))
+       } else
+       {
+               print("OK")
+       }
+}
diff --git a/src/test/generate_test_data/helpers/covariance.R b/src/test/generate_test_data/helpers/covariance.R
new file mode 100644 (file)
index 0000000..15cd693
--- /dev/null
@@ -0,0 +1,8 @@
+covariance = function(p,a)
+{
+       A = matrix(a, p,p)
+       for (i in 1:p)
+               A[i,] = A[i,]^abs(i-(1:p))
+
+       return (A)
+}
diff --git a/src/test/testEMGLLF.R b/src/test/testEMGLLF.R
new file mode 100644 (file)
index 0000000..9ba7058
--- /dev/null
@@ -0,0 +1,50 @@
+testEMGLLF = function()
+{
+       testFolder = "data/"
+       array_delimiter = " "
+
+       #get dimensions
+       dimensions = read.table(paste(testFolder,"dimensions",sep=""), header=FALSE,
+               sep=array_delimiter)
+       n = dimensions[1]
+       p = dimensions[2]
+       m = dimensions[3]
+       k = dimensions[4]
+
+       #get all input arrays
+       phiInit = read.table(paste(testFolder,"phiInit",sep=""), header=FALSE, sep=array_delimiter)
+       rhoInit = read.table(paste(testFolder,"rhoInit",sep=""), header=FALSE, sep=array_delimiter)
+       piInit = read.table(paste(testFolder,"piInit",sep=""), header=FALSE, sep=array_delimiter)
+       gamInit = read.table(paste(testFolder,"gamInit",sep=""), header=FALSE, sep=array_delimiter)
+       mini = read.table(paste(testFolder,"mini",sep=""), header=FALSE, sep=array_delimiter)
+       maxi = read.table(paste(testFolder,"maxi",sep=""), header=FALSE, sep=array_delimiter)
+       gamma = read.table(paste(testFolder,"gamma",sep=""), header=FALSE, sep=array_delimiter)
+       lambda = read.table(paste(testFolder,"lambda",sep=""), header=FALSE, sep=array_delimiter)
+       X = read.table(paste(testFolder,"X",sep=""), header=FALSE, sep=array_delimiter)
+       Y = read.table(paste(testFolder,"Y",sep=""), header=FALSE, sep=array_delimiter)
+       tau = read.table(paste(testFolder,"tau",sep=""), header=FALSE, sep=array_delimiter)
+
+       #run EMGLLF.c
+       EMG = .Call("EMGLLF_core",phiInit,rhoInit,piInit1,gamInit,mini,maxi,gamma,lambda,X,Y,tau,
+               PACKAGE="valse")
+       phi = EMG$phi
+       rho = EMG$rho
+       pi = EMG$pi
+       LLF = EMG$LLF
+       S = EMG$S
+
+       #get all stored outputs
+       ref_phi = read.table(paste(testFolder,"phi",sep=""), header=FALSE, sep=array_delimiter)
+       ref_rho = read.table(paste(testFolder,"rho",sep=""), header=FALSE, sep=array_delimiter)
+       ref_pi = read.table(paste(testFolder,"pi",sep=""), header=FALSE, sep=array_delimiter)
+       ref_LLF = read.table(paste(testFolder,"LLF",sep=""), header=FALSE, sep=array_delimiter)
+       ref_S = read.table(paste(testFolder,"S",sep=""), header=FALSE, sep=array_delimiter)
+
+       #check that output correspond to stored output
+       tol = 1e-5;
+       checkOutput("phi",phi,ref_phi,tol);
+       checkOutput("rho",rho,ref_rho,tol);
+       checkOutput("pi",pi,ref_pi,tol);
+       checkOutput("LLF",LLF,ref_LLF,tol);
+       checkOutput("S",S,ref_S,tol);
+}
diff --git a/src/test/utils.c b/src/test/utils.c
deleted file mode 100644 (file)
index a6370b0..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
-// Check if array == refArray
-void compareArray(const char* ID, const void* array, const void* refArray, int size,
-       int isinteger)
-{
-       float EPS = 1e-5; //precision
-       printf("Checking %s\n",ID);
-       float maxError = 0.0;
-       for (int i=0; i<size; i++)
-       {
-               float error = isinteger
-                       ? fabs(((int*)array)[i] - ((int*)refArray)[i])
-                       : fabs(((float*)array)[i] - ((float*)refArray)[i]);
-               if (error >= maxError)
-                       maxError = error;
-       }
-       if (maxError >= EPS)
-               printf("    Inaccuracy: max(abs(error)) = %g >= %g\n",maxError,EPS);
-       else
-               printf("    OK\n");
-}
-
-void compareArray_real(const char* ID, const void* array, const void* refArray, int size)
-{
-       return compareArray(ID, array, refArray, size, 0);
-}
-
-void compareArray_int(const char* ID, const void* array, const void* refArray, int size)
-{
-       return compareArray(ID, array, refArray, size, 1);
-}
-
-// Read array by columns (as in MATLAB) and return by-rows encoding
-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));
-       strcat(fullFileName, "data/");
-       strcat(fullFileName, fileName);
-
-       // first pass to know how many elements to allocate
-       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), countSpaces);
-       int n = atoi(buffer) + 1;
-       free(buffer);
-       pclose(countSpaces);
-
-       // open file for reading
-       FILE* file = fopen(fullFileName, "r");
-       free(fullFileName);
-
-       int d = 1;
-       size_t elementSize = isinteger
-               ? sizeof(int)
-               : sizeof(float);
-
-       // read all values, and convert them to by-rows matrices format
-       void* array = malloc(n*elementSize);
-       char curChar = ' ';
-       char bufferNum[64];
-       for (int u=0; u<n; u++)
-       {
-               // read number (as a string)
-               int bufferIndex = 0;
-               while (!feof(file) && curChar!=' ')
-               {
-                       curChar = fgetc(file);
-                       bufferNum[bufferIndex++] = curChar;
-               }
-               bufferNum[bufferIndex] = 0;
-               // transform string into float, and store it at appropriate location
-               if (isinteger)
-                       ((int*)array)[u] = atoi(bufferNum);
-               else
-                       ((float*)array)[u] = atof(bufferNum);
-               // position to next non-separator character
-               curChar = fgetc(file);
-       }
-       fclose(file);
-
-       return array;
-}
-
-int* readArray_int(const char* fileName)
-{
-       return (int*)readArray(fileName, 1);
-}
-
-float* readArray_real(const char* fileName)
-{
-       return (float*)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];
-}
diff --git a/src/test/utils.h b/src/test/utils.h
deleted file mode 100644 (file)
index cbffc24..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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);