24 #ifndef _GEMA_MATRIX_UTILS_H_ 25 #define _GEMA_MATRIX_UTILS_H_ 27 #ifndef GM_MATRIX_DEFINED 30 #define GM_MATRIX_DEFINED 39 #if ARMA_VERSION_MAJOR != 5 || ARMA_VERSION_MINOR != 200 40 #error Unexpected Armadillo version. Please check that our internal fiddling done bellow is still valid 51 inline void fill(
GmMatrix& m,
const double* data,
int nlin,
int ncol)
53 m.set_size(nlin, ncol);
54 memcpy(m.memptr(), data, nlin * ncol *
sizeof(double));
63 case 8: m(lin, 7) = data[7];
64 case 7: m(lin, 6) = data[6];
65 case 6: m(lin, 5) = data[5];
66 case 5: m(lin, 4) = data[4];
67 case 4: m(lin, 3) = data[3];
68 case 3: m(lin, 2) = data[2];
69 case 2: m(lin, 1) = data[1];
70 case 1: m(lin, 0) = data[0];
73 for (
unsigned int i = 0; i < m.n_cols; i++)
84 case 8: m(7, col) = data[7];
85 case 7: m(6, col) = data[6];
86 case 6: m(5, col) = data[5];
87 case 5: m(4, col) = data[4];
88 case 4: m(3, col) = data[3];
89 case 3: m(2, col) = data[2];
90 case 2: m(1, col) = data[1];
91 case 1: m(0, col) = data[0];
94 for (
unsigned int i = 0; i < m.n_rows; i++)
111 assert(m.vec_state == 0);
112 assert(m.mem_state == 2 || (m.mem_state == 0 && m.n_elem == 0 && m.mem == NULL));
113 arma::access::rw(m.mem) = data;
114 arma::access::rw(m.mem_state) = 2;
115 arma::access::rw(m.n_rows) = nlin;
116 arma::access::rw(m.n_cols) = ncol;
117 arma::access::rw(m.n_elem) = nlin * ncol;
130 assert(m.vec_state == 0);
133 arma::access::rw(m.mem) = NULL;
134 arma::access::rw(m.mem_state) = 0;
135 arma::access::rw(m.n_rows) = 0;
136 arma::access::rw(m.n_cols) = 0;
137 arma::access::rw(m.n_elem) = 0;
139 else if(m.mem_state == 0)
142 arma::access::rw(m.mem) = NULL;
163 assert(m.vec_state == 0);
164 assert(m.mem_state == 2);
166 arma::access::rw(m.n_rows) = nlin;
167 arma::access::rw(m.n_cols) = ncol;
168 arma::access::rw(m.n_elem) = nlin * ncol;
172 char format =
'g',
int precision = -1);
Groups utilitary routines for working with matrices.
Definition: gmMatrixUtils.cpp:30
void setMatrixMemory(GmMatrix &m, double *data, int nlin, int ncol)
Updates the memory area used internally by a matrix. DANGEROUS. Should be used only by the bold ones ...
Definition: gmMatrixUtils.h:106
QString toString(const GmMatrix &m, int fieldWidth, char format, int precision)
Serializes the matrix to a string using the specified precision fields. Lines are surrounded by [] an...
Definition: gmMatrixUtils.cpp:51
void resetMatrixMemory(GmMatrix &m)
Updates a matrix that was prepared with setMatrixMemory() to a common empty matrix....
Definition: gmMatrixUtils.h:125
void fill(GmMatrix &m, const double *data, int nlin, int ncol)
Copy the contents of data to matrix m. If m size is different from nlin, ncol the matrix is resized....
Definition: gmMatrixUtils.h:51
void fillFromLuaTable(GmMatrix &m, LuaTable &t)
Resizes and fills the matrix m to receive the data stored in a lua table.
Definition: gmMatrixUtils.cpp:95
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition: gmMatrixUtils.h:32
void fillColumn(GmMatrix &m, const double *data, int col)
Fills the specified column of a matrix m with the specified data.
Definition: gmMatrixUtils.h:79
void fillLine(GmMatrix &m, const double *data, int lin)
Fills the specified line of a matrix m with the specified data.
Definition: gmMatrixUtils.h:58
bool updateFromLuaTable(GmMatrix &m, LuaTable &t)
Updates the matrix m with the data stored in a lua table. The matrix size is left unchanged.
Definition: gmMatrixUtils.cpp:284
void print(const GmMatrix &m, const GmLogCategory &logger, GmLogLevel level, int fieldWidth, char format, int precision)
Prints the matrix using the specified logger, level and precision fields.
Definition: gmMatrixUtils.cpp:34
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
void setMatrixSize(GmMatrix &m, int nlin, int ncol)
Updates the logical matrix size WITHOUT changin the used memory area. DANGEROUS. Should be used only ...
Definition: gmMatrixUtils.h:158
GmLogLevel
Available log levels list.
Definition: gmLog.h:36
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition: gmMatrix.h:38
bool hasSharedMemory(GmMatrix &m)
Is this matrix operating over a shared memory (set by setMatrixMemory())?
Definition: gmMatrixUtils.h:149
QString toColMajorString(const GmMatrix &m, int fieldWidth, char format, int precision)
Serializes the matrix to a "linear" string, using the specified precision fields, with values ordered...
Definition: gmMatrixUtils.cpp:72
Declaration of support functions and macros for information logging.