Main MRPT website > C++ reference
MRPT logo

mrpt::math::CMatrixTemplate< T > Class Template Reference

This template class provides the basic functionality for a general 2D any-size, resizable container of numerical or non-numerical elements. More...

#include <mrpt/math/CMatrixTemplate.h>

Inheritance diagram for mrpt::math::CMatrixTemplate< T >:
Inheritance graph
[legend]
Collaboration diagram for mrpt::math::CMatrixTemplate< T >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T value_type
 The type of the matrix elements.
typedef T & reference
typedef const T & const_reference
typedef std::size_t size_type
typedef std::ptrdiff_t difference_type

Public Member Functions

template<size_t N>
void ASSERT_ENOUGHROOM (size_t r, size_t c) const
 Checks whether the rows [r-N,r+N] and the columns [c-N,c+N] are present in the matrix.
void fillAll (const T &val)
void swap (CMatrixTemplate< T > &o)
 Swap with another matrix very efficiently (just swaps a pointer and two integer values).
void extractCol (size_t nCol, std::vector< T > &out, int startingRow=0) const
 Returns a given column to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

void extractCol (size_t nCol, CMatrixTemplate< T > &out, int startingRow=0) const
 Gets a given column to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

void swapCols (size_t nCol1, size_t nCol2)
 Swap two columns

Exceptions:
std::exception On index out of bounds.

void swapRows (size_t nRow1, size_t nRow2)
 Swap two rows

Exceptions:
std::exception On index out of bounds.

template<class F >
void extractRow (size_t nRow, std::vector< F > &out, size_t startingCol=0) const
 Gets a given row to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

template<class F >
void extractRow (size_t nRow, CMatrixTemplate< F > &out, size_t startingCol=0) const
 Gets a given row to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

 CMatrixTemplate (const CMatrixTemplate &m)
 Constructors.
 CMatrixTemplate (size_t row=3, size_t col=3)
 CMatrixTemplate (const CMatrixTemplate &m, const size_t cropRowCount, const size_t cropColCount)
 Copy constructor & crop from another matrix.
template<typename V , size_t N>
 CMatrixTemplate (size_t row, size_t col, V(&theArray)[N])
 Constructor from a given size and a C array.
template<typename V >
 CMatrixTemplate (size_t row, size_t col, const V &theVector)
 Constructor from a given size and a STL container (std::vector, std::list,.
virtual ~CMatrixTemplate ()
 Destructor.
CMatrixTemplateoperator= (const CMatrixTemplate &m)
 Assignment operator from another matrix.
template<typename V , size_t N>
CMatrixTemplateoperator= (V(&theArray)[N])
 Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this asignament).
size_t getRowCount () const
 Number of rows in the matrix.
size_t getColCount () const
 Number of columns in the matrix.
CMatrixTemplateSize size () const
 Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x)).
void setSize (size_t row, size_t col, bool zeroNewElements=false)
 Changes the size of matrix, maintaining the previous contents.
void resize (const CMatrixTemplateSize &siz, bool zeroNewElements=false)
 This method just checks has no effects in this class, but raises an exception if the expected size does not match.
T & operator() (size_t row, size_t col)
 Subscript operator to get/set individual elements.
const T & operator() (size_t row, size_t col) const
 Subscript operator to get individual elements.
T & operator() (size_t ith)
 Subscript operator to get/set an individual element from a row or column matrix.
operator() (size_t ith) const
 Subscript operator to get/set an individual element from a row or column matrix.
void set_unsafe (size_t row, size_t col, const T &v)
 Fast but unsafe method to write a value in the matrix.
const T & get_unsafe (size_t row, size_t col) const
 Fast but unsafe method to read a value from the matrix.
T & get_unsafe (size_t row, size_t col)
 Fast but unsafe method to get a reference from the matrix.
T * get_unsafe_row (size_t row)
 Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in time critical applications).
const T * get_unsafe_row (size_t row) const
 Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in critical applications).
void extractRows (size_t firstRow, size_t lastRow, CMatrixTemplate< T > &out) const
 Gets a series of contiguous rows.
void extractColumns (size_t firstCol, size_t lastCol, CMatrixTemplate< T > &out) const
 Gets a series of contiguous columns.
void insertRow (size_t nRow, const std::vector< T > &in)
 Inserts a row from a vector, replacing the current contents of that row.
void appendRow (const std::vector< T > &in)
 Appends a new row to the MxN matrix from a 1xN vector.
void appendCol (const std::vector< T > &in)
 Appends a new column to the matrix from a vector.
void insertCol (size_t nCol, const std::vector< T > &in)
 Inserts a column from a vector, replacing the current contents of that column.
template<class MAT_R >
void insertMatrix (const size_t nRow, const size_t nCol, const MAT_R &in)
 Inserts a matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.
template<class MAT_R >
void insertMatrixTranspose (const size_t nRow, const size_t nCol, const MAT_R &in)
 Inserts the transpose of a given matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.
void insertMatrix (size_t nRow, size_t nCol, const std::vector< T > &in)
 Inserts a matrix line (vector) into this matrix Notice that the matrix must "fit" into the existing size of this matrix.
void joinMatrix (const CMatrixTemplate< T > &left_up, const CMatrixTemplate< T > &right_up, const CMatrixTemplate< T > &left_down, const CMatrixTemplate< T > &right_down)
 Inserts 4 matrixes corresponding to the "four corners" into this matrix.
void extractSubmatrix (const size_t row1, const size_t row2, const size_t col1, const size_t col2, CMatrixTemplate< T > &out) const
 Get a submatrix, given its bounds.
CMatrixTemplate< T > operator() (const size_t row1, const size_t row2, const size_t col1, const size_t col2) const
 Subscript operator to get a submatrix.
void extractSubmatrixSymmetricalBlocks (const size_t block_size, const vector_size_t &block_indices, CMatrixTemplate< T > &out) const
 Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is a sequence {block_indices(i):block_indices(i)+block_size-1} for all "i" up to the size of block_indices.
void extractSubmatrixSymmetrical (const vector_size_t &indices, CMatrixTemplate< T > &out) const
 Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is the sequence of indices passed as argument.
void exchangeColumns (size_t col1, size_t col2)
 Interchanges two columns of the matrix.
void exchangeRows (size_t row1, size_t row2)
 Interchanges two rows of the matrix.
void deleteRow (size_t row)
 Deletes a row of the matrix.
void deleteColumn (size_t col)
 Deletes a column of the matrix.
template<class R >
void extractMatrix (size_t nRow, size_t nCol, CMatrixTemplate< R > &in) const
 Extract a sub matrix from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

void extractMatrix (size_t nRow, size_t nCol, std::vector< T > &in) const
 Extract a sub matrix (vector) from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

template<size_t NROWS, size_t NCOLS>
void extractMatrix (const size_t nRow, const size_t nCol, CMatrixFixedNumeric< T, NROWS, NCOLS > &outMat) const
 Extract a sub matrix from this matrix (the size of the output matrix upon call determines the size of the submatrix to extract).
std::vector< T > extractMatrix (size_t nRow, size_t nCol, size_t ncols) const
 Extract a sub matrix (vector) from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

std::string inMatlabFormat (const size_t decimal_digits=6) const
 Dump matrix in matlab format.
bool fromMatlabStringFormat (const std::string &s)
 Read a matrix from a string in Matlab-like format, for example "[1 0 2; 0 4 -1]" The string must start with '[' and end with ']'.
void removeColumns (const mrpt::vector_size_t &idxsToRemove, bool vectorIsAlreadySorted=false)
 Removes a set of columns by their indexes (0:first), given by the vector "idxsToRemove".
void getAsVector (std::vector< T > &out) const
 Returns a vector containing the matrix's values.
CMatrixTemplate< T > operator() (const std::vector< size_t > &rows, const std::vector< size_t > &cols) const
 Returns a submatrix with random indices to the matrix, à la Matlab.
void removeRowsAndCols (const std::set< size_t > &rows, const std::set< size_t > &cols)
 Removes arbitrary rows and columns from the matrix.
void insertRowsAndCols (const std::multiset< size_t > &rows, const std::multiset< size_t > &cols, const T &defaultValue=T())
 Inserts rows and columns as needed.
template<size_t N, typename ReturnType >
ReturnType getVicinity (size_t c, size_t r) const
 Method to retrieve the vicinity of an element, given its coordinates.
Import/export as text



void saveToTextFile (const std::string &file, TMatrixTextFileFormat fileFormat=MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string("")) const
 Save matrix to a text file, compatible with MATLAB text format.
void loadFromTextFile (const std::string &file)
 Load matrix from a text file, compatible with MATLAB text format.

Protected Member Functions

void realloc (size_t row, size_t col, bool newElementsToZero=false)
 Internal use only: It reallocs the memory for the 2D matrix, maintaining the previous contents if posible.

Protected Attributes

T ** m_Val
size_t m_Rows
size_t m_Cols

Detailed Description

template<class T>
class mrpt::math::CMatrixTemplate< T >

This template class provides the basic functionality for a general 2D any-size, resizable container of numerical or non-numerical elements.

NOTES:

Note:
Memory blocks for each row are 16-bytes aligned (since MRPT 0.7.0).
See also:
CMatrixTemplateNumeric

Definition at line 61 of file CMatrixTemplate.h.


Member Typedef Documentation

template<class T>
typedef const T& mrpt::math::CMatrixTemplate< T >::const_reference

Definition at line 67 of file CMatrixTemplate.h.

template<class T>
typedef std::ptrdiff_t mrpt::math::CMatrixTemplate< T >::difference_type

Definition at line 69 of file CMatrixTemplate.h.

template<class T>
typedef T& mrpt::math::CMatrixTemplate< T >::reference

Definition at line 66 of file CMatrixTemplate.h.

template<class T>
typedef std::size_t mrpt::math::CMatrixTemplate< T >::size_type

Definition at line 68 of file CMatrixTemplate.h.

template<class T>
typedef T mrpt::math::CMatrixTemplate< T >::value_type

The type of the matrix elements.

Definition at line 65 of file CMatrixTemplate.h.


Constructor & Destructor Documentation

template<class T>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( const CMatrixTemplate< T > &  m  )  [inline]

Constructors.

Definition at line 250 of file CMatrixTemplate.h.

template<class T>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( size_t  row = 3,
size_t  col = 3 
) [inline]

Definition at line 255 of file CMatrixTemplate.h.

template<class T>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( const CMatrixTemplate< T > &  m,
const size_t  cropRowCount,
const size_t  cropColCount 
) [inline]

Copy constructor & crop from another matrix.

Definition at line 262 of file CMatrixTemplate.h.

template<class T>
template<typename V , size_t N>
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( size_t  row,
size_t  col,
V(&)  theArray[N] 
) [inline]

Constructor from a given size and a C array.

The array length must match cols x row.

  const double numbers[] = {
    1,2,3,
    4,5,6 };
         CMatrixDouble   M(3,2, numbers);

Definition at line 283 of file CMatrixTemplate.h.

template<class T>
template<typename V >
mrpt::math::CMatrixTemplate< T >::CMatrixTemplate ( size_t  row,
size_t  col,
const V &  theVector 
) [inline]

Constructor from a given size and a STL container (std::vector, std::list,.

..) with the initial values. The vector length must match cols x row.

Definition at line 298 of file CMatrixTemplate.h.

template<class T>
virtual mrpt::math::CMatrixTemplate< T >::~CMatrixTemplate (  )  [inline, virtual]

Destructor.

Definition at line 313 of file CMatrixTemplate.h.


Member Function Documentation

template<class T>
void mrpt::math::CMatrixTemplate< T >::appendCol ( const std::vector< T > &  in  )  [inline]

Appends a new column to the matrix from a vector.

The length of the vector must match the number of rows of the matrix, unless it is (0,0).

Exceptions:
std::exception On size mismatch.
See also:
extractCol
appendRow

Definition at line 595 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::appendRow ( const std::vector< T > &  in  )  [inline]

Appends a new row to the MxN matrix from a 1xN vector.

The lenght of the vector must match the width of the matrix, unless it's empty: in that case the matrix is resized to 1xN.

    CMatrixDouble  M(0,0);
    vector_double  v(7),w(7);
    // ...
    M.appendRow(v);
    M.appendRow(w);
Exceptions:
std::exception On incorrect vector length.
See also:
extractRow
appendCol

Definition at line 566 of file CMatrixTemplate.h.

template<class T>
template<size_t N>
void mrpt::math::CMatrixTemplate< T >::ASSERT_ENOUGHROOM ( size_t  r,
size_t  c 
) const [inline]

Checks whether the rows [r-N,r+N] and the columns [c-N,c+N] are present in the matrix.

Definition at line 130 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::deleteColumn ( size_t  col  )  [inline]

Deletes a column of the matrix.

Definition at line 818 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::deleteRow ( size_t  row  )  [inline]

Deletes a row of the matrix.

Definition at line 808 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::exchangeColumns ( size_t  col1,
size_t  col2 
) [inline]

Interchanges two columns of the matrix.

Definition at line 791 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::exchangeRows ( size_t  row1,
size_t  row2 
) [inline]

Interchanges two rows of the matrix.

Definition at line 804 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractCol ( size_t  nCol,
CMatrixTemplate< T > &  out,
int  startingRow = 0 
) const [inline]

Gets a given column to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 171 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractCol ( size_t  nCol,
std::vector< T > &  out,
int  startingRow = 0 
) const [inline]

Returns a given column to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 153 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractColumns ( size_t  firstCol,
size_t  lastCol,
CMatrixTemplate< T > &  out 
) const [inline]

Gets a series of contiguous columns.

Exceptions:
std::logic_error On index out of bounds
See also:
extractColumn
extractRows

Definition at line 533 of file CMatrixTemplate.h.

template<class T>
std::vector<T> mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
size_t  ncols 
) const [inline]

Extract a sub matrix (vector) from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 879 of file CMatrixTemplate.h.

template<class T>
template<size_t NROWS, size_t NCOLS>
void mrpt::math::CMatrixTemplate< T >::extractMatrix ( const size_t  nRow,
const size_t  nCol,
CMatrixFixedNumeric< T, NROWS, NCOLS > &  outMat 
) const [inline]

Extract a sub matrix from this matrix (the size of the output matrix upon call determines the size of the submatrix to extract).

Exceptions:
std::exception On index out of bounds The output matrix settles the size of the submatrix to extract, and (nRow,nCol) are the indices of the first element in the submatrix: e.g. (0,0) means extract a submatrix from the top-left corner

Definition at line 870 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
std::vector< T > &  in 
) const [inline]

Extract a sub matrix (vector) from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 851 of file CMatrixTemplate.h.

template<class T>
template<class R >
void mrpt::math::CMatrixTemplate< T >::extractMatrix ( size_t  nRow,
size_t  nCol,
CMatrixTemplate< R > &  in 
) const [inline]

Extract a sub matrix from a matrix:

Exceptions:
std::exception On index out of bounds The output matrix must have been previously set to the desired size.

(by AJOGD @ JAN-2007)

Definition at line 832 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::extractColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::extractMatrix(), mrpt::math::CMatrixTemplate< TPoint3D >::extractRows(), mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::getLandmarkCov(), and mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

template<class T>
template<class F >
void mrpt::math::CMatrixTemplate< T >::extractRow ( size_t  nRow,
CMatrixTemplate< F > &  out,
size_t  startingCol = 0 
) const [inline]

Gets a given row to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 234 of file CMatrixTemplate.h.

template<class T>
template<class F >
void mrpt::math::CMatrixTemplate< T >::extractRow ( size_t  nRow,
std::vector< F > &  out,
size_t  startingCol = 0 
) const [inline]

Gets a given row to a vector (without modifying the matrix)

Exceptions:
std::exception On index out of bounds.

Definition at line 216 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractRows ( size_t  firstRow,
size_t  lastRow,
CMatrixTemplate< T > &  out 
) const [inline]

Gets a series of contiguous rows.

Exceptions:
std::logic_error On index out of bounds
See also:
extractRow
extractColumns

Definition at line 523 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractSubmatrix ( const size_t  row1,
const size_t  row2,
const size_t  col1,
const size_t  col2,
CMatrixTemplate< T > &  out 
) const [inline]

Get a submatrix, given its bounds.

See also:
extractSubmatrixSymmetricalBlocks

Definition at line 699 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::operator()().

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractSubmatrixSymmetrical ( const vector_size_t indices,
CMatrixTemplate< T > &  out 
) const [inline]

Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is the sequence of indices passed as argument.

A perfect application of this method is in extracting covariance matrices of a subset of variables from the full covariance matrix.

See also:
extractSubmatrix, extractSubmatrixSymmetricalBlocks

Definition at line 762 of file CMatrixTemplate.h.

Referenced by mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

template<class T>
void mrpt::math::CMatrixTemplate< T >::extractSubmatrixSymmetricalBlocks ( const size_t  block_size,
const vector_size_t block_indices,
CMatrixTemplate< T > &  out 
) const [inline]

Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is a sequence {block_indices(i):block_indices(i)+block_size-1} for all "i" up to the size of block_indices.

A perfect application of this method is in extracting covariance matrices of a subset of variables from the full covariance matrix.

See also:
extractSubmatrix, extractSubmatrixSymmetrical

Definition at line 725 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::fillAll ( const T &  val  )  [inline]

Fill all the elements with a given value (Note: named "fillAll" since "fill" will be used by child classes)

Definition at line 136 of file CMatrixTemplate.h.

template<class T>
bool mrpt::math::CMatrixTemplate< T >::fromMatlabStringFormat ( const std::string &  s  )  [inline]

Read a matrix from a string in Matlab-like format, for example "[1 0 2; 0 4 -1]" The string must start with '[' and end with ']'.

Rows are separated by semicolons ';' and columns in each row by one or more whitespaces ' ' or tabs.

This format is also used for CConfigFile::read_matrix.

This template method can be instantiated for matrices of the types: int, long, unsinged int, unsigned long, float, double, long double

Returns:
true on success. false if the string is malformed, and then the matrix will be resized to 0x0.
See also:
inMatlabFormat, CConfigFile::read_matrix

Definition at line 929 of file CMatrixTemplate.h.

Referenced by mrpt::poses::CPose3DQuat::fromString(), mrpt::poses::CPose3D::fromString(), mrpt::poses::CPose2D::fromString(), mrpt::poses::CPoint3D::fromString(), and mrpt::poses::CPoint2D::fromString().

template<class T>
T& mrpt::math::CMatrixTemplate< T >::get_unsafe ( size_t  row,
size_t  col 
) [inline]

Fast but unsafe method to get a reference from the matrix.

Definition at line 492 of file CMatrixTemplate.h.

template<class T>
const T& mrpt::math::CMatrixTemplate< T >::get_unsafe ( size_t  row,
size_t  col 
) const [inline]
template<class T>
const T* mrpt::math::CMatrixTemplate< T >::get_unsafe_row ( size_t  row  )  const [inline]

Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in critical applications).

Definition at line 514 of file CMatrixTemplate.h.

template<class T>
T* mrpt::math::CMatrixTemplate< T >::get_unsafe_row ( size_t  row  )  [inline]

Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in time critical applications).

Definition at line 503 of file CMatrixTemplate.h.

Referenced by mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

template<class T>
void mrpt::math::CMatrixTemplate< T >::getAsVector ( std::vector< T > &  out  )  const [inline]

Returns a vector containing the matrix's values.

Definition at line 1153 of file CMatrixTemplate.h.

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::getColCount (  )  const [inline]
template<class T>
size_t mrpt::math::CMatrixTemplate< T >::getRowCount (  )  const [inline]
template<class T>
template<size_t N, typename ReturnType >
ReturnType mrpt::math::CMatrixTemplate< T >::getVicinity ( size_t  c,
size_t  r 
) const [inline]

Method to retrieve the vicinity of an element, given its coordinates.

Current implementation allows up to then different vicinities (4, 5, 8, 9, 12, 13, 20, 21, 24 and 25) and two different return values: CMatrixTemplate<T> and vector<T>.

Definition at line 1287 of file CMatrixTemplate.h.

template<class T>
std::string mrpt::math::CMatrixTemplate< T >::inMatlabFormat ( const size_t  decimal_digits = 6  )  const [inline]

Dump matrix in matlab format.

This template method can be instantiated for matrices of the types: int, long, unsinged int, unsigned long, float, double, long double

See also:
fromMatlabStringFormat

Definition at line 898 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertCol ( size_t  nCol,
const std::vector< T > &  in 
) [inline]

Inserts a column from a vector, replacing the current contents of that column.

Exceptions:
std::exception On index out of bounds
See also:
extractCol

Definition at line 610 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertMatrix ( size_t  nRow,
size_t  nCol,
const std::vector< T > &  in 
) [inline]

Inserts a matrix line (vector) into this matrix Notice that the matrix must "fit" into the existing size of this matrix.

Exceptions:
std::exception On index out of bounds
See also:
extractCol By AJOGD @ MAR-2007

Definition at line 667 of file CMatrixTemplate.h.

template<class T>
template<class MAT_R >
void mrpt::math::CMatrixTemplate< T >::insertMatrix ( const size_t  nRow,
const size_t  nCol,
const MAT_R &  in 
) [inline]

Inserts a matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.

Parameters:
in The submatrix to insert into 'this' matrix.
nRow The row in 'this' matrix where the submatrix will be inserted (0:first).
nCol The column in 'this' matrix where the submatrix will be inserted (0:first).
Exceptions:
std::exception On index out of bounds
See also:
extractCol

Definition at line 630 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::joinMatrix(), and mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

template<class T>
template<class MAT_R >
void mrpt::math::CMatrixTemplate< T >::insertMatrixTranspose ( const size_t  nRow,
const size_t  nCol,
const MAT_R &  in 
) [inline]

Inserts the transpose of a given matrix into this matrix Notice that the matrix must "fit" into the existing size of this matrix.

Parameters:
in The submatrix to insert into 'this' matrix.
nRow The row in 'this' matrix where the submatrix will be inserted (0:first).
nCol The column in 'this' matrix where the submatrix will be inserted (0:first).
Exceptions:
std::exception On index out of bounds
See also:
extractCol

Definition at line 650 of file CMatrixTemplate.h.

Referenced by mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertRow ( size_t  nRow,
const std::vector< T > &  in 
) [inline]

Inserts a row from a vector, replacing the current contents of that row.

Exceptions:
std::exception On index out of bounds
See also:
extractRow

Definition at line 542 of file CMatrixTemplate.h.

Referenced by mrpt::math::CLevenbergMarquardtTempl< VECTORTYPE, USERPARAM >::execute().

template<class T>
void mrpt::math::CMatrixTemplate< T >::insertRowsAndCols ( const std::multiset< size_t > &  rows,
const std::multiset< size_t > &  cols,
const T &  defaultValue = T() 
) [inline]

Inserts rows and columns as needed.

For example, if the row 3 exists twice in the multiset, two rows will be inserted _before_ the third row. Any index greater than the size will cause the column or row to be inserted right after the last element. THIS FUNCTION IS NOT SECURE TO USE WITH CMatrixTemplateObjects.

Definition at line 1237 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::joinMatrix ( const CMatrixTemplate< T > &  left_up,
const CMatrixTemplate< T > &  right_up,
const CMatrixTemplate< T > &  left_down,
const CMatrixTemplate< T > &  right_down 
) [inline]

Inserts 4 matrixes corresponding to the "four corners" into this matrix.

Exceptions:
std::exception On index out of bounds
See also:
insertMatrix

Definition at line 683 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::loadFromTextFile ( const std::string &  file  )  [inline]

Load matrix from a text file, compatible with MATLAB text format.

Lines starting with '' or '#' are interpreted as comments and ignored.

See also:
saveToTextFile, CMatrixTemplate::fromMatlabStringFormat

Definition at line 1019 of file CMatrixTemplate.h.

Referenced by mrpt::math::CVectorTemplate< KFTYPE >::loadFromTextFile().

template<class T>
CMatrixTemplate<T> mrpt::math::CMatrixTemplate< T >::operator() ( const std::vector< size_t > &  rows,
const std::vector< size_t > &  cols 
) const [inline]

Returns a submatrix with random indices to the matrix, à la Matlab.

Definition at line 1161 of file CMatrixTemplate.h.

template<class T>
CMatrixTemplate<T> mrpt::math::CMatrixTemplate< T >::operator() ( const size_t  row1,
const size_t  row2,
const size_t  col1,
const size_t  col2 
) const [inline]

Subscript operator to get a submatrix.

Definition at line 715 of file CMatrixTemplate.h.

template<class T>
T mrpt::math::CMatrixTemplate< T >::operator() ( size_t  ith  )  const [inline]

Subscript operator to get/set an individual element from a row or column matrix.

Exceptions:
std::exception If the object is not a column or row matrix.

Definition at line 443 of file CMatrixTemplate.h.

template<class T>
T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  ith  )  [inline]

Subscript operator to get/set an individual element from a row or column matrix.

Exceptions:
std::exception If the object is not a column or row matrix.

Definition at line 415 of file CMatrixTemplate.h.

template<class T>
const T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  row,
size_t  col 
) const [inline]

Subscript operator to get individual elements.

Definition at line 403 of file CMatrixTemplate.h.

template<class T>
T& mrpt::math::CMatrixTemplate< T >::operator() ( size_t  row,
size_t  col 
) [inline]

Subscript operator to get/set individual elements.

Definition at line 392 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::operator()(), and mrpt::math::CMatrixTemplate< TPoint3D >::removeRowsAndCols().

template<class T>
template<typename V , size_t N>
CMatrixTemplate& mrpt::math::CMatrixTemplate< T >::operator= ( V(&)  theArray[N]  )  [inline]

Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this asignament).

         CMatrixDouble   M(3,2);
  const double numbers[] = {
    1,2,3,
    4,5,6 };
  M = numbers;

Refer also to the constructor with initialization data CMatrixTemplate::CMatrixTemplate

Reimplemented in mrpt::math::CMatrixTemplateNumeric< T >, mrpt::math::CMatrixTemplateNumeric< NUMTYPE >, mrpt::math::CMatrixTemplateNumeric< double >, mrpt::math::CMatrixTemplateNumeric< float >, mrpt::math::CMatrixTemplateNumeric< kftype >, and mrpt::math::CMatrixTemplateNumeric< KFTYPE >.

Definition at line 342 of file CMatrixTemplate.h.

template<class T>
CMatrixTemplate& mrpt::math::CMatrixTemplate< T >::operator= ( const CMatrixTemplate< T > &  m  )  [inline]

Assignment operator from another matrix.

Definition at line 320 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::realloc ( size_t  row,
size_t  col,
bool  newElementsToZero = false 
) [inline, protected]
template<class T>
void mrpt::math::CMatrixTemplate< T >::removeColumns ( const mrpt::vector_size_t idxsToRemove,
bool  vectorIsAlreadySorted = false 
) [inline]

Removes a set of columns by their indexes (0:first), given by the vector "idxsToRemove".

Parameters:
vectorIsAlreadySorted Can be set to true only when it can be assured that the vector of indices is sorted in ascending order. Otherwise, the method will sort it internally.
Note:
All the indices MUST BE UNIQUE. Behavior on duplicated indices is undefined.
Exceptions:
std::exception On index out of bounds

Definition at line 1108 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::removeRowsAndCols ( const std::set< size_t > &  rows,
const std::set< size_t > &  cols 
) [inline]

Removes arbitrary rows and columns from the matrix.

Definition at line 1178 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::resize ( const CMatrixTemplateSize siz,
bool  zeroNewElements = false 
) [inline]

This method just checks has no effects in this class, but raises an exception if the expected size does not match.

Definition at line 385 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::saveToTextFile ( const std::string &  file,
TMatrixTextFileFormat  fileFormat = MATRIX_FORMAT_ENG,
bool  appendMRPTHeader = false,
const std::string &  userHeader = std::string("") 
) const [inline]

Save matrix to a text file, compatible with MATLAB text format.

Parameters:
file The target filename.
fileFormat See TMatrixTextFileFormat. The format of the numbers in the text file.
appendMRPTHeader Insert this header to the file "% File generated by MRPT. Load with MATLAB with: VAR=load(FILENAME);"
userHeader Additional text to be written at the head of the file. Typically MALAB comments "% This file blah blah". Final end-of-line is not needed.
See also:
loadFromTextFile, CMatrixTemplate::inMatlabFormat, SAVE_MATRIX

Definition at line 1005 of file CMatrixTemplate.h.

Referenced by mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration(), and mrpt::math::CVectorTemplate< KFTYPE >::saveToTextFile().

template<class T>
void mrpt::math::CMatrixTemplate< T >::set_unsafe ( size_t  row,
size_t  col,
const T &  v 
) [inline]
template<class T>
void mrpt::math::CMatrixTemplate< T >::setSize ( size_t  row,
size_t  col,
bool  zeroNewElements = false 
) [inline]
template<class T>
CMatrixTemplateSize mrpt::math::CMatrixTemplate< T >::size (  )  const [inline]

Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x)).

Definition at line 370 of file CMatrixTemplate.h.

Referenced by mrpt::math::operator>>().

template<class T>
void mrpt::math::CMatrixTemplate< T >::swap ( CMatrixTemplate< T > &  o  )  [inline]

Swap with another matrix very efficiently (just swaps a pointer and two integer values).

Definition at line 143 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::swap(), and mrpt::math::CMatrixTemplate< TPoint3D >::swapRows().

template<class T>
void mrpt::math::CMatrixTemplate< T >::swapCols ( size_t  nCol1,
size_t  nCol2 
) [inline]

Swap two columns

Exceptions:
std::exception On index out of bounds.

Definition at line 189 of file CMatrixTemplate.h.

template<class T>
void mrpt::math::CMatrixTemplate< T >::swapRows ( size_t  nRow1,
size_t  nRow2 
) [inline]

Swap two rows

Exceptions:
std::exception On index out of bounds.

Definition at line 203 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::exchangeRows().


Member Data Documentation

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::m_Cols [protected]

Definition at line 74 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::appendCol(), mrpt::math::CMatrixTemplate< TPoint3D >::appendRow(), mrpt::math::CMatrixTemplate< TPoint3D >::CMatrixTemplate(), mrpt::math::CMatrixTemplate< TPoint3D >::deleteColumn(), mrpt::math::CMatrixTemplate< TPoint3D >::deleteRow(), mrpt::math::CMatrixTemplate< TPoint3D >::exchangeColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::extractCol(), mrpt::math::CMatrixTemplate< TPoint3D >::extractRow(), mrpt::math::CMatrixTemplate< TPoint3D >::extractRows(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrix(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrixSymmetrical(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrixSymmetricalBlocks(), mrpt::math::CMatrixTemplate< TPoint3D >::fillAll(), mrpt::math::CMatrixTemplate< TPoint3D >::fromMatlabStringFormat(), mrpt::math::CMatrixTemplate< TPoint3D >::get_unsafe(), mrpt::math::CMatrixTemplate< TPoint3D >::get_unsafe_row(), mrpt::math::CMatrixTemplate< TPoint3D >::getAsVector(), mrpt::math::CMatrixTemplate< TPoint3D >::getColCount(), mrpt::math::CMatrixTemplate< TPoint3D >::inMatlabFormat(), mrpt::math::CMatrixTemplate< TPoint3D >::insertCol(), mrpt::math::CMatrixTemplate< TPoint3D >::insertMatrix(), mrpt::math::CMatrixTemplate< TPoint3D >::insertMatrixTranspose(), mrpt::math::CMatrixTemplate< TPoint3D >::insertRow(), mrpt::math::CMatrixTemplate< TPoint3D >::insertRowsAndCols(), mrpt::math::CMatrixTemplate< TPoint3D >::operator()(), mrpt::math::CMatrixTemplate< TPoint3D >::operator=(), mrpt::math::CMatrixTemplate< TPoint3D >::realloc(), mrpt::math::CMatrixTemplate< TPoint3D >::removeColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::removeRowsAndCols(), mrpt::math::CMatrixTemplate< TPoint3D >::set_unsafe(), mrpt::math::CMatrixTemplate< TPoint3D >::size(), mrpt::math::CMatrixTemplate< TPoint3D >::swap(), and mrpt::math::CMatrixTemplate< TPoint3D >::swapCols().

template<class T>
size_t mrpt::math::CMatrixTemplate< T >::m_Rows [protected]

Definition at line 74 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::appendCol(), mrpt::math::CMatrixTemplate< TPoint3D >::appendRow(), mrpt::math::CMatrixTemplate< TPoint3D >::CMatrixTemplate(), mrpt::math::CMatrixTemplate< TPoint3D >::deleteColumn(), mrpt::math::CMatrixTemplate< TPoint3D >::deleteRow(), mrpt::math::CMatrixTemplate< TPoint3D >::exchangeColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::extractCol(), mrpt::math::CMatrixTemplate< TPoint3D >::extractColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::extractRow(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrix(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrixSymmetrical(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrixSymmetricalBlocks(), mrpt::math::CMatrixTemplate< TPoint3D >::fillAll(), mrpt::math::CMatrixTemplate< TPoint3D >::get_unsafe(), mrpt::math::CMatrixTemplate< TPoint3D >::get_unsafe_row(), mrpt::math::CMatrixTemplate< TPoint3D >::getAsVector(), mrpt::math::CMatrixTemplate< TPoint3D >::getRowCount(), mrpt::math::CMatrixTemplate< TPoint3D >::inMatlabFormat(), mrpt::math::CMatrixTemplate< TPoint3D >::insertCol(), mrpt::math::CMatrixTemplate< TPoint3D >::insertMatrix(), mrpt::math::CMatrixTemplate< TPoint3D >::insertMatrixTranspose(), mrpt::math::CMatrixTemplate< TPoint3D >::insertRow(), mrpt::math::CMatrixTemplate< TPoint3D >::insertRowsAndCols(), mrpt::math::CMatrixTemplate< TPoint3D >::operator()(), mrpt::math::CMatrixTemplate< TPoint3D >::operator=(), mrpt::math::CMatrixTemplate< TPoint3D >::realloc(), mrpt::math::CMatrixTemplate< TPoint3D >::removeColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::removeRowsAndCols(), mrpt::math::CMatrixTemplate< TPoint3D >::set_unsafe(), mrpt::math::CMatrixTemplate< TPoint3D >::size(), mrpt::math::CMatrixTemplate< TPoint3D >::swap(), mrpt::math::CMatrixTemplate< TPoint3D >::swapCols(), and mrpt::math::CMatrixTemplate< TPoint3D >::swapRows().

template<class T>
T** mrpt::math::CMatrixTemplate< T >::m_Val [protected]

Definition at line 73 of file CMatrixTemplate.h.

Referenced by mrpt::math::CMatrixTemplate< TPoint3D >::appendCol(), mrpt::math::CMatrixTemplate< TPoint3D >::appendRow(), mrpt::math::CMatrixTemplate< TPoint3D >::CMatrixTemplate(), mrpt::math::CMatrixTemplate< TPoint3D >::deleteColumn(), mrpt::math::CMatrixTemplate< TPoint3D >::deleteRow(), mrpt::math::CMatrixTemplate< TPoint3D >::exchangeColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::extractCol(), mrpt::math::CMatrixTemplate< TPoint3D >::extractRow(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrix(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrixSymmetrical(), mrpt::math::CMatrixTemplate< TPoint3D >::extractSubmatrixSymmetricalBlocks(), mrpt::math::CMatrixTemplate< TPoint3D >::fillAll(), mrpt::math::CMatrixTemplate< TPoint3D >::fromMatlabStringFormat(), mrpt::math::CMatrixTemplate< TPoint3D >::get_unsafe(), mrpt::math::CMatrixTemplate< TPoint3D >::get_unsafe_row(), mrpt::math::CMatrixTemplate< TPoint3D >::getAsVector(), mrpt::math::CMatrixTemplate< TPoint3D >::inMatlabFormat(), mrpt::math::CMatrixTemplate< TPoint3D >::insertCol(), mrpt::math::CMatrixTemplate< TPoint3D >::insertRow(), mrpt::math::CMatrixTemplate< TPoint3D >::insertRowsAndCols(), mrpt::math::CMatrixTemplate< TPoint3D >::operator()(), mrpt::math::CMatrixTemplateObjects< T >::operator=(), mrpt::math::CMatrixTemplate< TPoint3D >::operator=(), mrpt::math::CMatrixTemplate< TPoint3D >::realloc(), mrpt::math::CMatrixTemplate< TPoint3D >::removeColumns(), mrpt::math::CMatrixTemplate< TPoint3D >::removeRowsAndCols(), mrpt::math::CMatrixTemplate< TPoint3D >::set_unsafe(), mrpt::math::CMatrixTemplate< TPoint3D >::swap(), and mrpt::math::CMatrixTemplate< TPoint3D >::swapCols().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010