X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=src%2Ftest%2Futils.c;fp=src%2Ftest%2Futils.c;h=0000000000000000000000000000000000000000;hb=df3ef2db3d9d01161973a67b4f7d25e1da4d502b;hp=a6370b0dbfa4a7a7647506cb029328fcb5c7d761;hpb=5deedb4ce4b94294f07f9f604ba37a5cbf3425af;p=valse.git diff --git a/src/test/utils.c b/src/test/utils.c deleted file mode 100644 index a6370b0..0000000 --- a/src/test/utils.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -#include -#include - -// 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= 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