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 != 14 || ARMA_VERSION_MINOR != 0
40#error Unexpected Armadillo version. Please check that our internal fiddling done below 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]; [[fallthrough]];
64 case 7: m(lin, 6) = data[6]; [[fallthrough]];
65 case 6: m(lin, 5) = data[5]; [[fallthrough]];
66 case 5: m(lin, 4) = data[4]; [[fallthrough]];
67 case 4: m(lin, 3) = data[3]; [[fallthrough]];
68 case 3: m(lin, 2) = data[2]; [[fallthrough]];
69 case 2: m(lin, 1) = data[1]; [[fallthrough]];
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]; [[fallthrough]];
85 case 7: m(6, col) = data[6]; [[fallthrough]];
86 case 6: m(5, col) = data[5]; [[fallthrough]];
87 case 5: m(4, col) = data[4]; [[fallthrough]];
88 case 4: m(3, col) = data[3]; [[fallthrough]];
89 case 3: m(2, col) = data[2]; [[fallthrough]];
90 case 2: m(1, col) = data[1]; [[fallthrough]];
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 assert(m.n_alloc == 0);
114 arma::access::rw(m.mem) = data;
115 arma::access::rw(m.mem_state) = 2;
116 arma::access::rw(m.n_rows) = nlin;
117 arma::access::rw(m.n_cols) = ncol;
118 arma::access::rw(m.n_elem) = nlin * ncol;
131 assert(m.vec_state == 0);
134 arma::access::rw(m.mem) = NULL;
135 arma::access::rw(m.mem_state) = 0;
136 arma::access::rw(m.n_rows) = 0;
137 arma::access::rw(m.n_cols) = 0;
138 arma::access::rw(m.n_elem) = 0;
140 else if(m.mem_state == 0)
143 arma::access::rw(m.mem) = NULL;
147 assert(m.n_alloc == 0);
165 assert(m.vec_state == 0);
166 assert(m.mem_state == 2);
167 assert(m.n_alloc == 0);
169 arma::access::rw(m.n_rows) = nlin;
170 arma::access::rw(m.n_cols) = ncol;
171 arma::access::rw(m.n_elem) = nlin * ncol;
175 char format =
'g',
int precision = -1);
Class representing a category with multiple logging levels.
Definition gmLog.h:58
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of support functions and macros for information logging.
GmLogLevel
Available log levels list.
Definition gmLog.h:36
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
Groups utilitary routines for working with matrices.
Definition gmMatrixUtils.cpp:31
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 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
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:160
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
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 resetMatrixMemory(GmMatrix &m)
Updates a matrix that was prepared with setMatrixMemory() to a common empty matrix....
Definition gmMatrixUtils.h:126
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
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
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
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
bool hasSharedMemory(GmMatrix &m)
Is this matrix operating over a shared memory (set by setMatrixMemory())?
Definition gmMatrixUtils.h:151
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