GemaCoreLib
The GeMA Core library
Functions
GmMatrixUtils Namespace Reference

Groups utilitary routines for working with matrices. More...

Functions

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.
 
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 [] and values separated by ', '.
 
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 in column major format. Values are separated by ', '.
 
void fillFromLuaTable (GmMatrix &m, LuaTable &t)
 Resizes and fills the matrix m to receive the data stored in a lua table. More...
 
bool fillFromLuaTable (GmMatrix &m, LuaTable &t, int nlin, int ncol)
 Resizes and fills the matrix m to receive the data stored in a lua table. More...
 
bool updateFromLuaTable (GmMatrix &m, LuaTable &t)
 Updates the matrix m with the data stored in a lua table. The matrix size is left unchanged. More...
 
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. Assumes that data is layed out in COLUMN MAJOR FORMAT.
 
void fillLine (GmMatrix &m, const double *data, int lin)
 Fills the specified line of a matrix m with the specified data.
 
void fillColumn (GmMatrix &m, const double *data, int col)
 Fills the specified column of a matrix m with the specified data.
 
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 who KNOWS what they are doing. More...
 
void resetMatrixMemory (GmMatrix &m)
 Updates a matrix that was prepared with setMatrixMemory() to a common empty matrix. If the matrix is already a common matrix, resets it AND sets its memory pointer to NULL to become compatible with the checks by setMatrixMemory()
 
bool hasSharedMemory (GmMatrix &m)
 Is this matrix operating over a shared memory (set by setMatrixMemory())?
 
void setMatrixSize (GmMatrix &m, int nlin, int ncol)
 Updates the logical matrix size WITHOUT changin the used memory area. DANGEROUS. Should be used only by the bold ones who KNOWS what they are doing. More...
 

Detailed Description

Groups utilitary routines for working with matrices.

Function Documentation

◆ fillFromLuaTable() [1/2]

GMC_API_EXPORT void GmMatrixUtils::fillFromLuaTable ( GmMatrix m,
LuaTable t 
)

Resizes and fills the matrix m to receive the data stored in a lua table.

In general, the table should be a list with subtables, each containing the values for
one matrix line.  The first row determines the number of columns in the matrix.
Missing values are filled with zeroes.

If the table is a simple vector, a matrix with n lines and 1 column will be created.

◆ fillFromLuaTable() [2/2]

GMC_API_EXPORT bool GmMatrixUtils::fillFromLuaTable ( GmMatrix m,
LuaTable t,
int  nlin,
int  ncol 
)

Resizes and fills the matrix m to receive the data stored in a lua table.

In general, the table should be a list with subtables, each containing the values for one matrix line. The first row determines the number of columns in the matrix.

if nlin / ncol are different from -1, the resulting matrix dimension should match the given values. If not, false is returned and the returned matrix is undefined.

If the table is a simple vector and both nlin and ncol are defined, the vector is interpreted as if its values are organized per column and checks done accordingly. if one of the values is -1, tries to infer its value from the table size and the other. If both are -1, a matrix with a single column is returned.

Also returns false for mal-formed matrices.

◆ setMatrixMemory()

void GmMatrixUtils::setMatrixMemory ( GmMatrix m,
double *  data,
int  nlin,
int  ncol 
)
inline

Updates the memory area used internally by a matrix. DANGEROUS. Should be used only by the bold ones who KNOWS what they are doing.

Makes the matrix use the supplied memory and sets the matrix size. To be minimally safe, accepts only an empty matrix, without allocated memory, or a matrix pointing to another external memory area.

◆ setMatrixSize()

void GmMatrixUtils::setMatrixSize ( GmMatrix m,
int  nlin,
int  ncol 
)
inline

Updates the logical matrix size WITHOUT changin the used memory area. DANGEROUS. Should be used only by the bold ones who KNOWS what they are doing.

To be minimally safe, accepts only a matrix pointing to another external memory area.

◆ updateFromLuaTable()

GMC_API_EXPORT bool GmMatrixUtils::updateFromLuaTable ( GmMatrix m,
LuaTable t 
)

Updates the matrix m with the data stored in a lua table. The matrix size is left unchanged.

The table can be a list with subtables, each containing the values for one matrix line or a flat table with values organized in column major order.

If the number of values in the table is incompatible with the current matrix size, the matrix is left unchanged and the function returns false.