#include <matrix.h>
Collaboration diagram for SPUC::Mat< T >:
Public Member Functions | |
Mat () | |
Class constructor. | |
Mat (int inrow, int incol) | |
Create a matrix of size (inrow, incol). | |
Mat (const Mat< T > &m) | |
Create a copy of the matrix m . | |
Mat (const Vec< T > &invector) | |
Create a copy of the vector invector treated as a column vector. | |
Mat (const char *str) | |
Set matrix equal to values in string. | |
Mat (T *c_array, int rows, int cols, bool RowMajor=true) | |
Constructor taking a C-array as input. Copies all data. | |
~Mat () | |
Class destructor. | |
int | cols () const |
The number of columns. | |
int | rows () const |
The number of rows. | |
void | set_size (int inrow, int incol, bool copy=false) |
Set size of matrix. If copy = true then keep the data before resizing. | |
void | zeros () |
Set matrix equal to the all zero matrix. | |
void | clear () |
Set matrix equal to the all zero matrix. | |
void | ones () |
Set matrix equal to the all one matrix. | |
bool | set (const char *str) |
Set matrix equal to values in the string. | |
const T & | operator() (int R, int C) const |
Get element (R,C) from matrix. | |
T & | operator() (int R, int C) |
Get element (R,C) from matrix. | |
T & | operator() (int index) |
Get element index using linear addressing (by rows). | |
const T & | operator() (int index) const |
Get element index using linear addressing (by rows). | |
const Mat< T > | operator() (int r1, int r2, int c1, int c2) const |
Sub-matrix from row r1 to row r2 and columns c1 to c2 . | |
Vec< T > | get_row (int Index) const |
Get row Index . | |
Mat< T > | get_rows (int r1, int r2) const |
Get rows r1 through r2 . | |
Mat< T > | get_rows (const Vec< int > &indexlist) const |
Get the rows specified by indexlist . | |
Vec< T > | get_col (int Index) const |
Get column Index . | |
Mat< T > | get_cols (int c1, int c2) const |
Get columns c1 through c2 . | |
Mat< T > | get_cols (const Vec< int > &indexlist) const |
Get the columns specified by indexlist . | |
void | set_row (int Index, const Vec< T > &invector) |
Set row Index to invector . | |
void | set_col (int Index, const Vec< T > &invector) |
Set column Index to invector . | |
void | copy_row (int to, int from) |
Copy row from onto row to . | |
void | copy_col (int to, int from) |
Copy column from onto column to . | |
void | swap_rows (int r1, int r2) |
Swap the rows r1 and r2 . | |
void | swap_cols (int c1, int c2) |
Swap the columns c1 and c2 . | |
void | set_submatrix (int r1, int r2, int c1, int c2, const Mat< T > &m) |
Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m. | |
void | set_submatrix (int r1, int r2, int c1, int c2, const T t) |
Set all elements of submatrix defined by rows r1,r2 and columns c1,c2 to value t. | |
void | operator= (T t) |
Set all elements of the matrix equal to t . | |
void | operator= (const Mat< T > &m) |
Set matrix equal to m . | |
void | operator= (const Vec< T > &v) |
Set matrix equal to the vector v , assuming column vector. | |
void | operator= (const char *values) |
Set matrix equal to values in the string. | |
void | operator+= (const Mat< T > &m) |
Addition of matrices. | |
void | operator+= (T t) |
Addition of scalar to matrix. | |
void | operator-= (const Mat< T > &m) |
Subtraction of matrix. | |
void | operator-= (T t) |
Subtraction of scalar from matrix. | |
void | operator *= (const Mat< T > &m) |
Matrix multiplication. | |
void | operator *= (T t) |
Multiplication by a scalar. | |
void | operator/= (T t) |
Division by a scalar. | |
void | operator/= (const Mat< T > &m) |
Elementwise division with the current matrix. | |
bool | operator== (const Mat< T > &m) const |
Compare two matrices. False if wrong sizes or different values. | |
bool | operator!= (const Mat< T > &m) const |
Compare two matrices. True if different. | |
T & | _elem (int R, int C) |
Get element (R,C) from matrix without boundary check (Not recommended to use). | |
const T & | _elem (int R, int C) const |
Get element (R,C) from matrix without boundary check (Not recommended to use). | |
T & | _elem (int index) |
Get element index using linear addressing (by rows) without boundary check (Not recommended to use). | |
const T & | _elem (int index) const |
Get element index using linear addressing (by rows) without boundary check (Not recommended to use). | |
T * | _data () |
Access of the internal data structure. Don't use. May be changed! | |
const T * | _data () const |
Access to the internal data structure. Don't use. May be changed! | |
int | _datasize () const |
Access to the internal data structure. Don't use. May be changed! | |
Protected Member Functions | |
void | alloc (int rows, int cols) |
Allocate memory for the matrix. | |
void | free () |
Free the memory space of the matrix. | |
Protected Attributes | |
int | datasize |
Protected integer variables. | |
int | no_rows |
int | no_cols |
T * | data |
Protected data pointer. | |
Friends | |
Mat< T > concat_horizontal | TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Concatenate the matrices m1 and m2 horizontally. | |
Mat< T > concat_vertical | TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Concatenate the matrices m1 and m2 vertically. | |
Mat< T > | operator+TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Addition of two matrices. | |
Mat< T > | operator+TEMPLATE_FUN (const Mat< T > &m, T t) |
Addition of matrix and scalar. | |
Mat< T > | operator+TEMPLATE_FUN (T t, const Mat< T > &m) |
Addition of scalar and matrix. | |
Mat< T > | operator-TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Subtraction of m2 from m1 . | |
Mat< T > | operator-TEMPLATE_FUN (const Mat< T > &m, T t) |
Subraction of scalar from matrix. | |
Mat< T > | operator-TEMPLATE_FUN (T t, const Mat< T > &m) |
Subtract matrix from scalar. | |
Mat< T > | operator-TEMPLATE_FUN (const Mat< T > &m) |
Subraction of matrix. | |
Mat< T > | operator *TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Multiplication of two matrices. | |
Vec< T > | operator *TEMPLATE_FUN (const Mat< T > &m, const Vec< T > &v) |
Multiplication of matrix m and vector v (column vector). | |
Vec< T > | operator *TEMPLATE_FUN (const Vec< T > &v, const Mat< T > &m) |
Multiplication of transposed vector v and matrix m . | |
Mat< T > | operator *TEMPLATE_FUN (const Mat< T > &m, T t) |
Multiplication of matrix and scalar. | |
Mat< T > | operator *TEMPLATE_FUN (T t, const Mat< T > &m) |
Multiplication of scalar and matrix. | |
Mat< T > elem_mult | TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Elementwise multiplication of two matrices. | |
Mat< T > | operator/TEMPLATE_FUN (const Mat< T > &m, T t) |
Division of matrix with scalar. | |
Mat< T > elem_div | TEMPLATE_FUN (const Mat< T > &m1, const Mat< T > &m2) |
Elementwise division of matrix m1 with matrix m2 . | |
Related Functions | |
(Note that these are not member functions.) | |
typedef Mat< double > | mat |
Output stream for matrices Default Matrix Type. | |
typedef Mat< complex< double > > | cmat |
Default Complex Matrix Type. | |
typedef Mat< int > | imat |
Integer matrix. | |
typedef Mat< long_long > | llmat |
long_long matrix | |
typedef Mat< short int > | smat |
short int matrix | |
typedef Mat< bin > | bmat |
bin matrix | |
void | sub_v_vT_m (mat &m, const vec &v) |
Calculates m=m-v*v'*m. | |
void | sub_m_v_vT (mat &m, const vec &v) |
Calculates m=m-m*v*v'. | |
T | sum (const Mat< T > &m) |
Sum of all elements in the matrix. | |
T | sum_sqr (const Mat< T > &m) |
Sum of square of the elements in the matrix. | |
T | max (const Mat< T > &m) |
Maximum value of matrix. | |
T | min (const Mat< T > &m) |
Minimum value of matrix. | |
void | max_index (const Mat< T > &in, int &row, int &col) |
The index of the element of maximum value. | |
void | min_index (const Mat< T > &in, int &row, int &col) |
The index of the element of minimum value. | |
T | product (const Mat< T > &m) |
The product of all elements in the vector. | |
double | mean (const mat &m) |
The mean value. | |
complex< double > | mean (const cmat &m) |
The mean value. | |
double | mean (const smat &m) |
The mean value. | |
double | mean (const imat &m) |
The mean value. | |
Mat< T > | diag (const Vec< T > &in) |
Returns a diagonal matrix whith the elements of the vector in on the diagonal and zeros elsewhere. | |
void | diag (const Vec< T > &in, Mat< T > &m) |
Returns in the output wariable m a diagonal matrix whith the elements of the vector in on the diagonal and zeros elsewhere. | |
Vec< T > | diag (const Mat< T > &in) |
Returns the diagonal elements of the input matrix in . | |
Mat< T > | bidiag (const Vec< T > &main, const Vec< T > &sup) |
Returns a matrix with the elements of the input vector main on the diagonal and the elements of the input vector sup on the diagonal row above. | |
void | bidiag (const Vec< T > &main, const Vec< T > &sup, Mat< T > &m) |
Returns in the output variable m a matrix with the elements of the input vector main on the diagonal and the elements of the input vector sup on the diagonal row above. | |
void | bidiag (const Mat< T > &in, Vec< T > &main, Vec< T > &sup) |
Returns the main diagonal and the diagonal row above in the two output vectors main and sup . | |
Mat< T > | tridiag (const Vec< T > &main, const Vec< T > &sup, const Vec< T > &sub) |
Returns a matrix with the elements of main on the diagonal, the elements of sup on the diagonal row above, and the elements of sub on the diagonal row below. | |
void | tridiag (const Vec< T > &main, const Vec< T > &sup, const Vec< T > &sub, Mat< T > &m) |
Returns in the output matrix m a matrix with the elements of main on the diagonal, the elements of sup on the diagonal row above, and the elements of sub on the diagonal row below. | |
void | tridiag (const Mat< T > &in, Vec< T > &main, Vec< T > &sup, Vec< T > &sub) |
Returns the main diagonal, the diagonal row above, and the diagonal row below int the output vectors main , sup , and sub . | |
T | trace (const Mat< T > &in) |
The trace of the matrix, i.e. the sum of the diagonal elements. | |
void | transpose (const Mat< T > &m, Mat< T > &out) |
Transposition of the matrix returning the transposed matrix in out. | |
Mat< T > | transpose (const Mat< T > &m) |
Transposition of the matrix. | |
Mat< T > | repeat (const Mat< T > &m, int norepeats) |
Repeats each column norepeats times in sequence. | |
Mat< T > | apply_function (fT(*f)(fT), const Mat< T > &data) |
Apply arbitrary functions to a matrix. | |
Vec< T > | rvectorize (const Mat< T > &m) |
Row vectorize the matrix [(0,0) (0,1) ... (N-1,N-2) (N-1,N-1)]. | |
Vec< T > | cvectorize (const Mat< T > &m) |
Column vectorize the matrix [(0,0) (1,0) ... (N-2,N-1) (N-1,N-1)]. | |
Mat< T > | reshape (const Mat< T > &m, int rows, int cols) |
Reshape the matrix into an rows*cols matrix. | |
Mat< T > | reshape (const Vec< T > &m, int rows, int cols) |
Reshape the vector into an rows*cols matrix. | |
void | upsample (const Mat< T > &v, int usf, Mat< T > &u) |
Upsample each column by incerting (usf-1) zeros after each column. | |
Mat< T > | upsample (const Mat< T > &v, int upsamplefactor) |
Upsample each column by incerting (usf-1) zeros after each column. | |
void | lininterp (const Mat< T > &v, int usf, Mat< T > &u) |
Upsample each column by a factor of (usf-1) by linear interpolation. | |
Mat< T > | lininterp (const Mat< T > &v, int usf) |
Upsample each column by a factor of (usf-1) by linear interpolation. | |
void | lininterp (const Vec< T > &v, int usf, Vec< T > &u) |
Upsample by a factor of (usf-1) by linear interpolation. | |
Vec< T > | lininterp (const Vec< T > &v, int usf) |
Upsample by a factor of (usf-1) by linear interpolation. | |
Mat< T > | mat_1x1 (T m00) |
Matrix of size 1 by 1. | |
Mat< T > | mat_1x2 (T m00, T m01) |
Matrix of size 1 by 2. | |
Mat< T > | mat_2x1 (T m00, T m10) |
Matrix of size 2 by 1. | |
Mat< T > | mat_2x2 (T m00, T m01, T m10, T m11) |
Matrix of size 2 by 2. | |
Mat< T > | mat_1x3 (T m00, T m01, T m02) |
Matrix of size 1 by 3. | |
Mat< T > | mat_3x1 (T m00, T m10, T m20) |
Matrix of size 3 by 1. | |
Mat< T > | mat_2x3 (T m00, T m01, T m02, T m10, T m11, T m12) |
Matrix of size 2 by 3. | |
Mat< T > | mat_3x2 (T m00, T m01, T m10, T m11, T m20, T m21) |
Matrix of size 3 by 2. | |
Mat< T > | mat_3x3 (T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22) |
Matrix of size 3 by 3. |
bin
, short
, int
, double
, and double_complex
vectors and these are predefined as: bmat
, smat
, imat
, mat
, and cmat
. double
and double_complex
are usually double
and complex<double>
respectively. However, this can be changed when \ compiling the it++ (see installation notes for more details).Examples:
Matrix Constructors: When constructing a matrix without a dimensions (memory) use
mat temp;
vec temp(inmatrix);
mat a("0 0.7;5 9.3"); // that is a = [0, 0.7; 5, 9.3] mat a="0 0.7;5 9.3"; // the constructor are called implicitly
temp.set_size(new_rows, new_cols, false);
false
is used to indicate that the old values in temp
is not copied. If you like to preserve the values use true
.There are a number of methods to access parts of a matrix. Examples are
a(5,3); // Element number (5,3) a(5,9,3,5); // Sub-matrix from rows 5, 6, 7, 8, 9 the columns 3, 4, and 5 a.get_row(10); // Row 10 a.get_col(10); // Column 10
It is also possible to modify parts of a vector as e.g. in
a.set_row(5, invector); // Set row 5 to \c invector a.set_col(3, invector); // Set column 3 to \c invector a.copy_col(1, 5); // Copy column 5 to column 1 a.swap_cols(1, 5); // Swap the contents of columns 1 and 5
It is of course also possible to perform the common linear algebra methods such as addition, subtraction, and matrix multiplication. Observe though, that vectors are assumed to be column-vectors in operations with matrices.
Most elementary functions such as sin(), cosh(), log(), abs(), ..., are available as operations on the individual elements of the matrices. Please see the individual functions for more details.
|
Class constructor.
|
|
Create a matrix of size (inrow, incol).
Here is the call graph for this function: ![]() |
|
Create a copy of the matrix
Here is the call graph for this function: ![]() |
|
Create a copy of the vector
Here is the call graph for this function: ![]() |
|
Set matrix equal to values in string. Mat(const std::string &str) { init(); set(str); } Here is the call graph for this function: ![]() |
|
Constructor taking a C-array as input. Copies all data. By default the matrix is stored as a RowMajor matrix (i.e. listing elements in sequence beginning with the first column). Here is the call graph for this function: ![]() |
|
Class destructor.
Here is the call graph for this function: ![]() |
|
Access to the internal data structure. Don't use. May be changed!
|
|
Access of the internal data structure. Don't use. May be changed!
|
|
Access to the internal data structure. Don't use. May be changed!
|
|
Get element
|
|
Get element
|
|
Get element (R,C) from matrix without boundary check (Not recommended to use).
|
|
Get element (R,C) from matrix without boundary check (Not recommended to use).
|
|
Allocate memory for the matrix.
Here is the call graph for this function: ![]() |
|
Set matrix equal to the all zero matrix.
Here is the call graph for this function: ![]() |
|
The number of columns.
|
|
Copy column
|
|
Copy row
|
|
Free the memory space of the matrix.
|
|
Get column
Here is the call graph for this function: ![]() |
|
Get the columns specified by
Here is the call graph for this function: ![]() |
|
Get columns
Here is the call graph for this function: ![]() |
|
Get row
Here is the call graph for this function: ![]() |
|
Get the rows specified by
Here is the call graph for this function: ![]() |
|
Get rows
Here is the call graph for this function: ![]() |
|
Set matrix equal to the all one matrix.
|
|
Multiplication by a scalar.
|
|
Matrix multiplication.
Here is the call graph for this function: ![]() |
|
Compare two matrices. True if different.
|
|
Sub-matrix from row Value -1 indicates the last row and column, respectively. |
|
Get element
|
|
Get element
|
|
Get element (R,C) from matrix.
|
|
Get element (R,C) from matrix.
|
|
Addition of scalar to matrix.
|
|
Addition of matrices.
Here is the call graph for this function: ![]() |
|
Subtraction of scalar from matrix.
|
|
Subtraction of matrix.
Here is the call graph for this function: ![]() |
|
Elementwise division with the current matrix.
|
|
Division by a scalar.
|
|
Set matrix equal to values in the string.
Here is the call graph for this function: ![]() |
|
Set matrix equal to the vector
Here is the call graph for this function: ![]() |
|
Set matrix equal to
Here is the call graph for this function: ![]() |
|
Set all elements of the matrix equal to
|
|
Compare two matrices. False if wrong sizes or different values.
|
|
The number of rows.
|
|
Set matrix equal to values in the string.
Here is the call graph for this function: ![]() |
|
Set column
Here is the call graph for this function: ![]() |
|
Set row
Here is the call graph for this function: ![]() |
|
Set size of matrix. If copy = true then keep the data before resizing.
Here is the call graph for this function: ![]() |
|
Set all elements of submatrix defined by rows r1,r2 and columns c1,c2 to value t.
|
|
Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m.
|
|
Swap the columns
|
|
Swap the rows
|
|
Set matrix equal to the all zero matrix.
|
|
Apply arbitrary functions to a matrix.
|
|
Returns the main diagonal and the diagonal row above in the two output vectors
The input matrix |
|
Returns in the output variable
If the number of elements in the vector |
|
Returns a matrix with the elements of the input vector
If the number of elements in the vector |
|
bin matrix
|
|
Default Complex Matrix Type.
|
|
Column vectorize the matrix [(0,0) (1,0) ... (N-2,N-1) (N-1,N-1)].
|
|
Returns the diagonal elements of the input matrix
The input matrix |
|
Returns in the output wariable
The size of the output matrix |
|
Returns a diagonal matrix whith the elements of the vector
The size of the return matrix will be |
|
Integer matrix.
|
|
Upsample by a factor of (usf-1) by linear interpolation.
|
|
Upsample by a factor of (usf-1) by linear interpolation.
|
|
Upsample each column by a factor of (usf-1) by linear interpolation.
|
|
Upsample each column by a factor of (usf-1) by linear interpolation.
|
|
long_long matrix
|
|
Output stream for matrices Default Matrix Type.
|
|
Matrix of size 1 by 1.
|
|
Matrix of size 1 by 2.
|
|
Matrix of size 1 by 3.
|
|
Matrix of size 2 by 1.
|
|
Matrix of size 2 by 2.
|
|
Matrix of size 2 by 3.
|
|
Matrix of size 3 by 1.
|
|
Matrix of size 3 by 2.
|
|
Matrix of size 3 by 3.
|
|
Maximum value of matrix.
|
|
The index of the element of maximum value.
|
|
The mean value.
|
|
The mean value.
|
|
The mean value.
|
|
The mean value.
|
|
Minimum value of matrix.
|
|
The index of the element of minimum value.
|
|
Multiplication of scalar and matrix.
|
|
Multiplication of matrix and scalar.
|
|
Multiplication of transposed vector
|
|
Multiplication of matrix
|
|
Multiplication of two matrices.
|
|
Addition of scalar and matrix.
|
|
Addition of matrix and scalar.
|
|
Addition of two matrices.
|
|
Subraction of matrix.
|
|
Subtract matrix from scalar.
|
|
Subraction of scalar from matrix.
|
|
Subtraction of
|
|
Division of matrix with scalar.
|
|
The product of all elements in the vector.
|
|
Repeats each column norepeats times in sequence.
|
|
Reshape the vector into an rows*cols matrix. The data is element by element from the vector and written columnwise into the new matrix. |
|
Reshape the matrix into an rows*cols matrix. The data is taken columnwise from the original matrix and written columnwise into the new matrix. |
|
Row vectorize the matrix [(0,0) (0,1) ... (N-1,N-2) (N-1,N-1)].
|
|
short int matrix
|
|
Calculates m=m-m*v*v'.
|
|
Calculates m=m-v*v'*m.
|
|
Sum of all elements in the matrix.
|
|
Sum of square of the elements in the matrix.
|
|
Elementwise division of matrix
|
|
Elementwise multiplication of two matrices.
|
|
Concatenate the matrices
|
|
Concatenate the matrices
|
|
The trace of the matrix, i.e. the sum of the diagonal elements.
|
|
Transposition of the matrix.
|
|
Transposition of the matrix returning the transposed matrix in out.
|
|
Returns the main diagonal, the diagonal row above, and the diagonal row below int the output vectors
The input matrix |
|
Returns in the output matrix
If the length of the input vector |
|
Returns a matrix with the elements of
If the length of the input vector |
|
Upsample each column by incerting (usf-1) zeros after each column.
|
|
Upsample each column by incerting (usf-1) zeros after each column.
|
|
Protected data pointer.
|
|
Protected integer variables.
|
|
|
|
|