prepare structure for R package
[valse.git] / src / sources / utils / ioutils.h
1 #ifndef select_ioutils_H
2 #define select_ioutils_H
3
4 #include <stdlib.h>
5 #include <math.h>
6 #include <stdint.h>
7 #include <uchar.h> //for type wchar16_t
8
9 // Include header for mwSize type
10 #ifdef Octave
11 #include <mex.h>
12 #else
13 #include <tmwtypes.h>
14 #endif
15
16 // CHUNK_SIZE = number of lambda values to be treated sequentially by a single core
17 #define CHUNK_SIZE 1
18
19 // integer type chosen in MATLAB (to be tuned: 32 bits should be enough)
20 typedef int64_t Int;
21
22 // real number type chosen in MATLAB (default: double)
23 typedef double Real;
24
25 #ifndef M_PI
26 #define M_PI 3.141592653589793
27 #endif
28
29 // Fill an array with zeros
30 #define zeroArray(array, size)\
31 {\
32 for (Int u=0; u<size; u++)\
33 array[u] = 0;\
34 }
35
36 // Copy an 1D array
37 #define copyArray(array, copy, size)\
38 {\
39 for (Int u=0; u<size; u++)\
40 copy[u] = array[u];\
41 }
42
43 // Check if array == refArray
44 void compareArray(const char* ID, const void* array, const void* refArray, mwSize size, int isInteger);
45
46 #define compareArray_int(ID, array, refArray, size)\
47 compareArray(ID, array, refArray, size, 1)
48 #define compareArray_real(ID, array, refArray, size)\
49 compareArray(ID, array, refArray, size, 0)
50
51 // Auxiliary to convert from ours ("by-rows") encoding to MATLAB
52 void* brToMatlabArray(const void* brArray, const mwSize* dimensions, int nbDims, int isInteger);
53
54 #define brToMatlabArray_int(brArray, dimensions, nbDims)\
55 (Int*)brToMatlabArray(brArray, dimensions, nbDims, 1)
56 #define brToMatlabArray_real(brArray, dimensions, nbDims)\
57 (Real*)brToMatlabArray(brArray, dimensions, nbDims, 0)
58
59 // Auxiliary to convert from MATLAB encoding to ours ("by-rows")
60 void* matlabToBrArray(const void* matlabArray, const mwSize* dimensions, int nbDims, int isInteger);
61
62 #define matlabToBrArray_int(matlabArray, dimensions, nbDims)\
63 (Int*)matlabToBrArray(matlabArray, dimensions, nbDims, 1)
64 #define matlabToBrArray_real(matlabArray, dimensions, nbDims)\
65 (Real*)matlabToBrArray(matlabArray, dimensions, nbDims, 0)
66
67 // Read array by columns (as in MATLAB) and return by-rows encoding
68 void* readArray(const char* fileName, const mwSize* dimensions, int nbDims, int isInteger);
69
70 #define readArray_int(fileName, dimensions, nbDims)\
71 (Int*)readArray(fileName, dimensions, nbDims, 1)
72 #define readArray_real(fileName, dimensions, nbDims)\
73 (Real*)readArray(fileName, dimensions, nbDims, 0)
74
75 #endif