GemaLuaCoreLib
The GeMA Lua Core library
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
GmLuaMatrix Class Reference

A proxy class to export GmMatrix and GmVector methods to the Lua environment. More...

#include <gmLuaMatrix.h>

Inheritance diagram for GmLuaMatrix:
Inheritance graph
[legend]
Collaboration diagram for GmLuaMatrix:
Collaboration graph
[legend]

Public Member Functions

 GmLuaMatrix (GmMatrix &mat, const GmLogCategory &logger)
 Constructor. Wrapps an existing matrix.
 
 GmLuaMatrix (GmVector &vec, const GmLogCategory &logger)
 Constructor. Wrapps an existing vector.
 
 GmLuaMatrix (int nlin, int ncol, const double *data, const GmLogCategory &logger)
 Creates a new matrix, owned by the proxy, with the given size and initialized with a copy of data (which should be in column MAJOR format). If data is NULL the matrix will be initialized with zeros.
 
 GmLuaMatrix (LuaTable &tab, const GmLogCategory &logger)
 Creates a new matrix, owned by the proxy, initialized with the data found in the given Lua table (which could be a vector or a matrix).
 
virtual ~GmLuaMatrix ()
 Destructor.
 
virtual const char * typeName () const
 Returns the object type as will be stored in the object metatable.
 
virtual QString toString () const
 Default method used by the __tostring metamethod to capture the result of tostring() over an object.
 
virtual void fillMetatable (lua_State *L, int index)
 Prepares the object metatable for calling methods.
 
virtual void * getClassMetatableID ()
 Returns an unique identifier to identify an user object as a GmLuaMesh object.
 
GmMatrixmatrix () const
 Returns a reference for the internal matrix.
 
- Public Member Functions inherited from GmLuaObject
virtual ~GmLuaObject ()
 Destrutor.
 
virtual void populateMetatable (lua_State *L, int index)
 Fills the object metatable to allow for the proxy to export its methods.
 
QVariant ptrToVariant ()
 Constructs a QVariant storing a POINTER to the current object.
 
void ref ()
 Increments the object reference count. Use with care.
 

Private Member Functions

int nlin (lua_State *L)
 Returns the number of lines in the matrix.
 
int ncol (lua_State *L)
 Returns the number of columns in the matrix.
 
int size (lua_State *L)
 Returns the size (number of lines * columns) in the matrix.
 
int at (lua_State *L)
 Returns the value at the requested position given by line and column (or just line for vectors) More...
 
int set (lua_State *L)
 Sets the value at the requested position given by line and column (or just line for vectors) to the third (second) value. Alternativelly can also be used to fill a matrix with a scalar value or replace the whole matrix with values given in a table or matrix, without resizing the matrix (the table can be a structured table or a linear table in column major format) More...
 
int col (lua_State *L)
 Returns the matrix data in the given column as a column vector.
 
int line (lua_State *L)
 Returns the matrix data in the given row as a row vector (relly a matrix with a single row)
 
int setCol (lua_State *L)
 Updates the data in the given column with the data in the given vector or Lua table.
 
int setLine (lua_State *L)
 Updates the data in the given row with the data in the given row matrix or Lua table.
 
int t (lua_State *L)
 Returns a new matrix with the transpose of the current matrix.
 
int det (lua_State *L)
 Returns the determinant of the current matrix.
 
int equal (lua_State *L)
 Check to see if two matrix are equal comparing values using GmDoubleCmp::equal.
 
int print (lua_State *L)
 Prints the current matrix. Receives as an optional parameter a string with the numeric format to be applied.
 
int toTable (lua_State *L)
 Returns the matrix contents serialized in a Lua table, per column.
 
int toString (lua_State *L)
 Returns the current matrix serialized as a string. Receives as an optional. More...
 
int solve (lua_State *L)
 Solves the linear system Ax = b, where A is the current matrix, b is a parameter and x the result. Solved using Armadillo "solve()" method. More...
 
int inv (lua_State *L)
 Returns the inverse of the given square matrix. Solved using Armadillo "i()" method. Returns nil if the matrix is singular and can not be inverted.
 
int dot (lua_State *L)
 Returns the dot product of the column vector object by another column vector.
 
int cross (lua_State *L)
 Returns the cross product between two column vectors with 3 lines each.
 
int norm (lua_State *L)
 Returns the norm of the column vector object.
 
int eig_sym (lua_State *L)
 Returns the set of eigen value and eigen vectors of the square matrix object. The matrix MUST be symmetric (but that is NOT checked).
 
int eq (lua_State *L)
 Object metamethod for ==. Called with a pair of matrices. Always returns a boolean. More...
 
int unm (lua_State *L)
 Object metamethod for unary -. Called with a matrix. Always returns a new matrix.
 

Static Private Member Functions

static int add (lua_State *L)
 Static metamethod for addition. Can be called with 2 matrices or a matrix and a number. Always returns a new matrix.
 
static int sub (lua_State *L)
 Static metamethod for subtraction. Can be called with 2 matrices or a matrix and a number. Always returns a new matrix.
 
static int mul (lua_State *L)
 Static metamethod for multiplication. Can be called with 2 matrices or a matrix and a number. Always returns a new matrix.
 
static int div (lua_State *L)
 Static metamethod for division. Can be called with 2 matrices or a matrix and a number. Always returns a new matrix.
 
static int mod (lua_State *L)
 Static metamethod for componenet wise matrix multiplication. Can be called with 2 matrices or a matrix and a number. Always returns a new matrix.
 
static GmLuaMatrixgetOperand (lua_State *L, int index, char op, double *v)
 Checks that the value at the given index is a number or a matrix. If it is a number, returns NULL and fills v with the given value. If it is a matrix, returns the matrix and leaves v untouched. More...
 
static GmLuaMatrixcheckAndCreate (lua_State *L, char op, GmLuaMatrix *m1, GmLuaMatrix *m2, bool mul)
 Checks that the matrices have compatible sizes and creates the result matrix. More...
 

Private Attributes

GmMatrix_newMat
 A new matrix (owned by the proxy) 'wrapped' by this proxy object.
 
GmMatrix_mat
 A reference to the exported matrix, either external or pointing to _newMat.
 

Additional Inherited Members

- Protected Member Functions inherited from GmLuaObject
 GmLuaObject (const GmLogCategory &logger)
 Construtor protegido. Somente classes derivadas devem ser instanciadas.
 
- Protected Attributes inherited from GmLuaObject
const GmLogCategory_logger
 A logger used by the proxy when needed.
 
QAtomicInteger< int > _refCount
 Lua objects are reference counted to enable sharing them among different states. This is needed to allow for passing objects as parameters in a parallel call. The garbage collection method releases memory only for the last reference.
 

Detailed Description

A proxy class to export GmMatrix and GmVector methods to the Lua environment.

Member Function Documentation

◆ at()

int GmLuaMatrix::at ( lua_State *  L)
private

Returns the value at the requested position given by line and column (or just line for vectors)

Following Lua convention, lines and columns are indexed from 1

◆ checkAndCreate()

GmLuaMatrix * GmLuaMatrix::checkAndCreate ( lua_State *  L,
char  op,
GmLuaMatrix m1,
GmLuaMatrix m2,
bool  mul 
)
staticprivate

Checks that the matrices have compatible sizes and creates the result matrix.

Parameters m1 and m2 migth be NULL (but at least one of them should be a valid matrix). The mul flag, when true, states that validation should be made for a matrix multiplication and not for an element by element operation.

Does not return on errors, calling luaL_error() using the op parameter in the message.

◆ eq()

int GmLuaMatrix::eq ( lua_State *  L)
private

Object metamethod for ==. Called with a pair of matrices. Always returns a boolean.

Does an element wise comparisson using ==. Matrices with different sizes are accepeted and return false;

◆ getOperand()

GmLuaMatrix * GmLuaMatrix::getOperand ( lua_State *  L,
int  index,
char  op,
double *  v 
)
staticprivate

Checks that the value at the given index is a number or a matrix. If it is a number, returns NULL and fills v with the given value. If it is a matrix, returns the matrix and leaves v untouched.

Does not return on errors, calling luaL_error() using the op parameter in the message.

◆ set()

int GmLuaMatrix::set ( lua_State *  L)
private

Sets the value at the requested position given by line and column (or just line for vectors) to the third (second) value. Alternativelly can also be used to fill a matrix with a scalar value or replace the whole matrix with values given in a table or matrix, without resizing the matrix (the table can be a structured table or a linear table in column major format)

Following Lua convention, lines and columns are indexed from 1

◆ solve()

int GmLuaMatrix::solve ( lua_State *  L)
private

Solves the linear system Ax = b, where A is the current matrix, b is a parameter and x the result. Solved using Armadillo "solve()" method.

Accepts non square matrices. The number of rows in A must be equal to b Returns nil if unable to solve the system.

◆ toString()

int GmLuaMatrix::toString ( lua_State *  L)
private

Returns the current matrix serialized as a string. Receives as an optional.

parameter a string with the numeric format to be applied


The documentation for this class was generated from the following files: