![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
gMat2D implements a matrix of generic size More...
#include <gmat2d.h>
Public Member Functions | |
BaseArray< T > & | add (const BaseArray< T > &) |
In-place addition to a vector. | |
bool | allEqualsTo (const T &val) const |
Returns true if all elements of the matrix are equals to a value val . | |
gVec< T > * | argmax (int order) |
Returns a vector containing the largest elements along the columns if order == COLUMNWISE or along the rows if order == ROWWISE. | |
gVec< T > * | argmin (int order) |
Returns a vector containing the smallest elements along the columns if order == COLUMNWISE or along the rows if order == ROWWISE. | |
void | asarray (T *v, unsigned long n) const |
Copies n elements from this vector to a new buffer v . | |
gVec< T > | asvector () const |
Returns a vector containing the linearized matrix. | |
const T * | begin () const |
Returns a const pointer to the begin of vector buffer. | |
T * | begin () |
Returns a non-const pointer to the begin of vector buffer. | |
bool | closeTo (const BaseArray< T > &, T tolerance) const |
Checks if vector values are element by element close to a given array. | |
unsigned long | cols () const |
Returns the number of columns. | |
gMat2D< bool > & | compare (T &threshold, std::string logical_operator=GreaterEq) const |
Compares each element of the matrix with the threshold and returns a matrix with elements set to true or false depending on the comparison operator passed as parameter. | |
BaseArray< T > & | divide (const BaseArray< T > &) |
In-place element by element division by a vector. | |
const T * | end () const |
Returns a const pointer to the end of vector buffer. | |
T * | end () |
Returns a non-const pointer to the end of vector buffer. | |
const T * | getData () const |
Returns a const pointer to the vector buffer. | |
T * | getData () |
Returns a non-const pointer to the vector buffer. | |
unsigned long | getSize () const |
Returns vector length. | |
gMat2D (unsigned long r=0, unsigned long c=0) | |
Initializes a r-by-c matrix. | |
gMat2D (T *buf, unsigned long r, unsigned long c, bool owner) | |
Initializes an r-by-c matrix from a data buffer. | |
gMat2D (const gMat2D< T > &other) | |
Constructor form an existing gMat2D. | |
template<class Archive > | |
void | load (Archive &, const unsigned int) |
Deserializes the vector from a generic archive. | |
void | load (const std::string &fileName) |
Deserializes the matrix from file. | |
void | lowertriangular (gMat2D< T > &lo) const |
Clears the upper triangle of a matrix. | |
const T & | max () const |
Returns a reference to the element with the largest value in the vector. | |
gVec< T > * | max (int order) |
Returns a vector containing the largest elements along the columns if order == COLUMNWISE or along the rows if order == ROWWISE. | |
const T & | min () const |
Returns a reference to the element with the smallest value in the vector. | |
gVec< T > * | min (int order) |
Returns a vector containing the smallest elements along the columns if order == COLUMNWISE or along the rows if order == ROWWISE. | |
BaseArray< T > & | multiply (const BaseArray< T > &) |
In-place element by element multiplication by a vector. | |
T & | operator() (unsigned long row, unsigned long col) |
Provides access to the elements of the matrix in a Matlab style: M(r,c) | |
gVec< T > | operator() (unsigned long i) |
Returns a vector containing the elements at the i-th column. | |
gVec< T > | operator() (unsigned long i) const |
Returns a vector containing the elements at the i-th column. | |
gMat2D< T > | operator* (T) const |
Returns a matrix containing the multiplication of the matrix by a scalar. | |
gMat2D< T > | operator* (const gMat2D< T > &) const |
Returns the element-by-element multiplication between two matrices. | |
BaseArray< T > & | operator*= (T) |
Multiplies all elements by a scalar. | |
gMat2D< T > & | operator*= (const gMat2D< T > &) |
In-place element-by-element multiplication by a matrix. | |
gMat2D< T > | operator+ (T) const |
Returns a matrix containing the sum between the matrix and a scalar. | |
gMat2D< T > | operator+ (const gMat2D< T > &) const |
Returns the element-by-element sum of two vectors. | |
BaseArray< T > & | operator+= (T) |
Adds a value to all elements. | |
gMat2D< T > & | operator+= (const gMat2D< T > &) |
In-place element-by-element addition to a matrix. | |
gMat2D< T > | operator- () const |
Inverts elements sign. | |
gMat2D< T > | operator- (T val) const |
Returns a matrixr containing the difference between the matrix and a scalar. | |
gMat2D< T > | operator- (const gMat2D< T > &v) const |
Returns the element-by-element difference between two matrices. | |
BaseArray< T > & | operator-= (T) |
Subtracts a value to all elements. | |
gMat2D< T > & | operator-= (const gMat2D< T > &v) |
In-place element-by-element subtraction to a matrix. | |
gMat2D< T > | operator/ (T val) const |
Returns a matrix containing the division of the matrix by a scalar. | |
gMat2D< T > | operator/ (const gMat2D< T > &) const |
Returns the element-by-element division between two matrices. | |
BaseArray< T > & | operator/= (T) |
Divides all elements by a scalar. | |
gMat2D< T > & | operator/= (const gMat2D< T > &) |
In-place element-by-element division by a matrix. | |
gMat2D< bool > & | operator< (T threshold) const |
Compares each element of the matrix with the threshold and returns a matrix with elements set to true where element < threshold, or false where element >= threshold. | |
gMat2D< bool > & | operator<= (T threshold) const |
Compares each element of the matrix with the threshold and returns a matrix with elements set to true where element <= threshold, or false where element > threshold. | |
gMat2D< T > & | operator= (const gMat2D< T > &other) |
Assignment operator. | |
gMat2D< T > & | operator= (const T &val) |
Sets all elements of the matrix to the value specified in val . | |
gMat2D< bool > & | operator== (T threshold) const |
Compares each element of the matrix with the threshold and returns a matrix with elements set to true where element == threshold, or false where element != threshold. | |
gMat2D< bool > & | operator> (T threshold) const |
Compares each element of the matrix with the threshold and returns a matrix with elements set to true where element > threshold, or false where element <= threshold. | |
gMat2D< bool > & | operator>= (T threshold) const |
Compares each element of the matrix with the threshold and returns a matrix with elements set to true where element >= threshold, or false where element < threshold. | |
gVec< T > | operator[] (unsigned long i) const |
Returns a vector containing the elements at the i-th row. | |
gVec< T > | operator[] (unsigned long i) |
Returns a vector containing the elements at the i-th row. | |
void | randomize () |
Initializes the vector with pseudo-random values. | |
void | readCSV (const std::string &fileName, bool colMajor=true) |
Read the matrix from a CSV file. | |
gMat2D< T > & | reciprocal () const |
Returns matrix element-by-element multiplicative inverse. | |
void | reshape (unsigned long r, unsigned long c) |
Reshapes the matrix to r-by-c size. | |
void | resize (unsigned long n) |
Resizes the vector to length n . | |
void | resize (unsigned long r, unsigned long c) |
Resizes the matrix to r-by-c size. | |
unsigned long | rows () const |
Returns the number of rows. | |
template<class Archive > | |
void | save (Archive &, const unsigned int) const |
Serializes the vector to a generic archive. | |
void | save (const std::string &fileName) const |
Serializes the matrix to file. | |
void | saveCSV (const std::string &fileName) const |
Saves the matrix into a CSV file. | |
void | set (const T *v, unsigned long n, unsigned long start=0) |
Copies n elements of a given vector v to this vector starting from start . | |
void | setColumn (gVec< T > &vec, unsigned long i) |
Sets the elements at the i-th columns. | |
void | setDiag (gVec< T > &vec) |
Sets the elements on the matrix diagonal. | |
BaseArray< T > & | setReciprocal () |
In-place multiplicative inverse of each element. | |
void | setRow (gVec< T > &vec, unsigned long i) |
Sets the elements at the i-th row. | |
void | submatrix (const gMat2D< T > &other, unsigned long r, unsigned long c) |
Copies a r-by-c submatrix into a new matrix. | |
BaseArray< T > & | subtract (const BaseArray< T > &) |
In-place subtraction to a vector. | |
T | sum () const |
Returns the sum of all elements in the vector. | |
gVec< T > * | sum (int order) const |
Returns a vector containing the sums of the elements along the columns if order == COLUMNWISE or along the rows if order == ROWWISE. | |
void | transpose (gMat2D< T > &transposed) const |
Transpose the matrix. | |
void | uppertriangular (gMat2D< T > &up) const |
Clears the lower triangle of a matrix. | |
virtual std::string | what () const |
Returns a string description of the matrix. | |
gVec< T > & | where (const gMat2D< bool > &comparison) const |
Returns a vector containing all matrix elements where comparison matrix == true. | |
Static Public Member Functions | |
static gMat2D< T > | diag (gVec< T > &diagonal) |
Returns a squared matrix initialized in the diagonal with values from diagonal . | |
static gMat2D< T > | eye (unsigned long n=0) |
Returns a n-by-n identity matrix. | |
static gMat2D< T > | rand (unsigned long r=0, unsigned long c=0) |
Returns a r-by-c matrix initialized with pseudo-random values. | |
static gMat2D< T > | zeros (unsigned long r=0, unsigned long c=0) |
Returns a r-by-c matrix of all zeros. | |
Static Public Attributes | |
static const std::string | Equal = "==" |
String for == operator. | |
static const std::string | Greater = ">" |
String for > operator. | |
static const std::string | GreaterEq = ">=" |
String for >= operator. | |
static const std::string | Less = "<" |
String for < operator. | |
static const std::string | LessEq = "<=" |
String for <= operator. | |
Protected Member Functions | |
void | alloc (unsigned long n) |
Allocates the n elements data buffer. | |
Protected Attributes | |
T * | data |
Pointer to the data buffer. | |
bool | isowner |
Flag indicating whether vector has ownership of (and has to deallocate in destructor) the pointed buffer or not. | |
unsigned long | numcols |
Number of columns. | |
unsigned long | numrows |
Number of rows. | |
unsigned long | size |
Data buffer length. | |
Friends | |
class | boost::serialization::access |
template<typename U > | |
void | dot (const gMat2D< U > &, const gMat2D< U > &, gMat2D< U > &) |
General Matrix-Matrix multiplication of two matrices. | |
template<typename U > | |
void | dot (const gMat2D< U > &, const gVec< U > &, gVec< U > &) |
General Matrix-Vector multiplication of a matrix with a vector. | |
template<typename U > | |
gMat2D< U > | operator* (U val, const gMat2D< U > &v) |
Returns a matrix containing the multiplication of a matrix by a scalar. | |
template<typename U > | |
gMat2D< U > | operator+ (U val, const gMat2D< U > &v) |
Returns a matrix containing the sum between a matrix and a scalar. | |
template<typename U > | |
gMat2D< U > | operator- (U val, const gMat2D< U > &v) |
Returns a matrix containing the difference between a matrix and a scalar. | |
template<typename U > | |
gMat2D< U > | operator/ (U val, const gMat2D< U > &v) |
Returns a matrix containing the division of a matrix by a scalar. | |
template<typename U > | |
std::ostream & | operator<< (std::ostream &, const gMat2D< U > &) |
Writes matrix information and data to a stream. | |
template<typename U > | |
bool | operator== (const BaseArray< U > &, const U &) |
Checks if all elements in a vector are equal to a given value. |
T | Cells type. |
gurls::gMat2D< T >::gMat2D | ( | T * | buf, |
unsigned long | r, | ||
unsigned long | c, | ||
bool | owner | ||
) |
void gurls::gMat2D< T >::reshape | ( | unsigned long | r, |
unsigned long | c | ||
) |
Warning: r*c must be equals to numrows * numcols
Definition at line 160 of file gmat2d.hpp.
{ if (r*c != this->size) throw gException(gurls::Exception_Invalid_Reshape_Arguments); this->numcols = c; this->numrows = r; }
void gurls::gMat2D< T >::submatrix | ( | const gMat2D< T > & | other, |
unsigned long | r, | ||
unsigned long | c | ||
) |
The input parameter other
is supposed to be already initialized with a number of rows equal to r and columns equal to c.
Definition at line 89 of file gmat2d.hpp.
void gurls::gMat2D< T >::transpose | ( | gurls::gMat2D< T > & | transposed | ) | const |
The input parameter transposed
is supposed to be already initialized with a number of rows and columns equal to the number of columns and rows, respectively, of this matrix.
Definition at line 99 of file gmat2d.hpp.
{ if(this->numrows != transposed.numcols || this->numcols != transposed.numrows) throw gException(gurls::Exception_Inconsistent_Size); gurls::transpose(this->data, this->numrows, this->numcols, transposed.data); }