#include <cmat.h>
Public Types | |
typedef Subscript | size_type |
Subscript type. | |
typedef T | value_type |
Type of elements stored in matrix. | |
typedef T | element_type |
Type of elements stored in matrix. | |
typedef T * | pointer |
Pointer to type stored in matrix. | |
typedef T & | reference |
Reference to type stored in matrix. | |
typedef const T & | const_reference |
Reference to type stored in constant matrix. | |
typedef T * | iterator |
Iterator over elements in matrix. | |
typedef const T * | const_iterator |
Iterator over elements in constant matrix. | |
typedef T * | row_iterator |
Iterator over elements of a row. | |
typedef const T * | const_row_iterator |
Iterator over constant elements of a row. | |
typedef slice_pointer_base< T, T *, T & > | column_iterator |
Iterator over elements of a column. | |
typedef slice_pointer_base< T, const T *, const T & > | const_column_iterator |
Iterator over constant elements of a column. | |
typedef row_iterator * | rows_iterator |
Iterator over row iterators (points to row_iterator object for a row). | |
typedef const_row_iterator * | const_rows_iterator |
Iterator over row iterators (points to const_row_iterator object for a row). | |
typedef column_iterator * | columns_iterator |
Iterator over column iterators (points to column_iterator object for a column). | |
typedef const_column_iterator * | const_columns_iterator |
Iterator over column iterators (points to const_column_iterator object for a column). | |
typedef slice_pointer_base< T, T *, T & > | diag_iterator |
Iterator over elements of a matrix diagonal. | |
typedef slice_pointer_base< T, const T *, const T & > | const_diag_iterator |
Iterator over constant elements of a matrix diagonal. | |
Public Member Functions | |
Subscript | lbound () const |
Returns lower bound of subscript. | |
Subscript | size () const |
Return total number of elements in matrix. | |
Subscript | dim (Subscript d) const |
Return number of rows if argument is 1, number of columns if argument is 2. | |
Subscript | num_rows () const |
Return number of rows in matrix. | |
Subscript | num_columns () const |
Return number of columns in matrix. | |
Matrix () | |
Default constructor. | |
Matrix (const Matrix< T > &A) | |
Copy constructor. | |
Matrix (Subscript M, Subscript N) | |
Construct matrix of a particular size, but do not initialize elements to any value. | |
Matrix (Subscript M, Subscript N, const T value) | |
Construct and assign all elements to a particular value. | |
Matrix (Subscript M, Subscript N, const std::string &s) | |
Constructor that reads elements from a string. | |
template<class IT> | |
Matrix (IT begin, Subscript number_rows, Subscript number_columns) | |
Construct from an iterator giving initial elements in row-major order. | |
~Matrix () | |
Destructor. | |
Matrix< T > & | newsize (Subscript M, Subscript N) |
Resize matrix (old elements are distroyed). | |
Matrix< T > & | operator= (const Matrix< T > &A) |
Matrix assignment. | |
Matrix< T > & | operator= (const T &scalar) |
Scalar assignment. | |
row_iterator | operator[] (Subscript i) |
Return iterator to elements in row i+1 (0-offset). | |
const_row_iterator | operator[] (Subscript i) const |
Return iterator to constant elements in row i+1 (0-offset). | |
reference | operator() (Subscript i) |
Return i-th (1-offset) element of matrix when treated as a vector (row major ordering). | |
const_reference | operator() (Subscript i) const |
Return i-th (1-offset) constant element of matrix when treated as a vector (row major ordering). | |
reference | operator() (Subscript i, Subscript j) |
Return element in row i and column j, where i and j are 1-offset indices. | |
const_reference | operator() (Subscript i, Subscript j) const |
Return constant element in row i and column j, where i and j are 1-offset indices. | |
rows_iterator | begin_rows () |
Return iterator pointing to row iterator for first row (iterator over row iterators). | |
const_rows_iterator | begin_rows () const |
Return iterator pointing to row iterator for first row (constant version). | |
columns_iterator | begin_columns () |
Return iterator pointing to column iterator for first column (iterator over column iterators). | |
const_columns_iterator | begin_columns () const |
Return iterator pointing to column iterator for first column (constant version). | |
rows_iterator | end_rows () |
Return iterator pointing to row iterator for one past last row (iterator over row iterators). | |
const_rows_iterator | end_rows () const |
Return iterator pointing to row iterator for one past last row (constant version). | |
columns_iterator | end_columns () |
Return iterator pointing to column iterator for one past last column (iterator over column iterators). | |
const_columns_iterator | end_columns () const |
Return iterator pointing to column iterator for one past last column (constant version). | |
row_iterator | begin_row (Subscript index) |
Return iterator pointing to first element in row 'index' (1-offset). | |
const_row_iterator | begin_row (Subscript index) const |
Return iterator pointing to first element in row 'index' (1-offset). | |
column_iterator | begin_column (Subscript index) |
Return iterator pointing to first element in column 'index' (1-offset). | |
const_column_iterator | begin_column (Subscript index) const |
Return iterator pointing to first element in column 'index' (1-offset). | |
row_iterator | end_row (Subscript index) |
Return iterator pointing to one past last element in row 'index' (1-offset). | |
const_row_iterator | end_row (Subscript index) const |
Return iterator pointing to one past last element in row 'index' (1-offset). | |
column_iterator | end_column (Subscript index) |
Return iterator pointing to one past last element in column 'index' (1-offset). | |
const_column_iterator | end_column (Subscript index) const |
Return iterator pointing to one past last element in column 'index' (1-offset). | |
iterator | begin () |
Returns iterator pointing to first element of matrix (consecutive element accessed by row). | |
const_iterator | begin () const |
Returns iterator pointing to first element of matrix (consecutive element accessed by row). | |
iterator | end () |
Iterator pointing to one past last element of matrix. | |
const_iterator | end () const |
Iterator pointing to one past last element of matrix. | |
diag_iterator | begin_diagonal (Subscript row, Subscript column) |
Returns iterator pointing to first element of matrix diagonal. | |
const_diag_iterator | begin_diagonal (Subscript row, Subscript column) const |
Returns iterator pointing to first element of matrix diagonal. | |
diag_iterator | end_diagonal (Subscript row, Subscript column) |
Returns iterator pointing to one past last element of matrix diagonal. | |
const_diag_iterator | end_diagonal (Subscript row, Subscript column) const |
Returns iterator pointing to one past last element of matrix diagonal. | |
operator T ** () | |
convert to T** | |
operator const T ** () const | |
convert to const T** | |
template<class MAT> | |
Matrix< T > & | operator+= (const MAT &rhs) |
Add matrix rhs to matrix. | |
template<class MAT> | |
Matrix< T > & | operator-= (const MAT &rhs) |
Subtract matrix rhs from matrix. | |
template<class MAT> | |
Matrix< T > & | operator *= (const MAT &rhs) |
Matrix multiply of matrix times rhs (rhs must be square). | |
Matrix< T > & | operator+= (const T &value) |
Add scalar to all elements of the matrix. | |
Matrix< T > & | operator-= (const T &value) |
Subtract scalar from all elements of the matrix. | |
Matrix< T > & | operator *= (const T &value) |
Multiply each element of matrix by scalar value. | |
Matrix< T > & | operator/= (const T &value) |
Divide each element of matrix by scalar value. |
Templated numerical matrix class based on Template Numerical Toolkit Matrix class. Row-oriented matrix with element access through 0-based [i][j] and 1-based (i,j) indexing, and row, column, and diagonal iterators. The matrix is stored in one contiguous piece of memory. Besides memory being allocated for the contents of the matrix, memory is also allocated for row iterators (one iterator for each row), column iterators (one iterator for each column), and column iterators over constant elements (one iterator for each column). If SCPPNT_BOUNDS_CHECK is defined then memory is allocated for row iterators over constant elements (one for each row).
This class adds the following to the TNT Matrix class:
Definition at line 110 of file cmat.h.
SCPPNT::Matrix< T >::Matrix | ( | Subscript | M, | |
Subscript | N, | |||
const std::string & | s | |||
) | [inline] |
Constructor that reads elements from a string.
Constructor that reads elements from a string
M | Number of rows. | |
N | Number of columns. | |
s | String containing initial elements of matrix in row-major order separated by white space. |
Definition at line 736 of file cmat.h.
00736 : v_(0) 00737 { 00738 initialize(M,N); 00739 std::istrstream ins(s.c_str()); 00740 00741 Subscript i, j; 00742 00743 for (i=0; i<M; i++) 00744 for (j=0; j<N; j++) 00745 ins >> row_[i][j]; 00746 }
SCPPNT::Matrix< T >::Matrix | ( | IT | begin, | |
Subscript | number_rows, | |||
Subscript | number_columns | |||
) | [inline] |
Construct from an iterator giving initial elements in row-major order.
begin | Iterator pointing to the first element of a sequence of values assigned to elements of the matrix created in row-major order (elements in first row followed by elements in second row, etc.) | |
number_rows | Number of rows in matrix created. | |
number_columns | Number of columns in matrix created. |
Definition at line 246 of file cmat.h.
References SCPPNT::Matrix< T >::begin().
00246 : 00247 v_(0) 00248 { 00249 00250 initialize(number_rows, number_columns); 00251 00252 iterator i = this->begin(); 00253 Subscript n = number_rows * number_columns; 00254 while (n--) 00255 { 00256 *i = *begin; 00257 ++begin; 00258 ++i; 00259 } 00260 }
Matrix< T >::diag_iterator SCPPNT::Matrix< T >::begin_diagonal | ( | Subscript | row, | |
Subscript | column | |||
) | [inline] |
Returns iterator pointing to first element of matrix diagonal.
Returns iterator pointing to the first element of the matrix diagonal given by (row, column), (row+1, column+1), (row+2, column+2), ... For example, if row=1 and column=1 then an iterator pointing to the first element of the main diagnonal is returned.
row | 1-based row number for initial element of diagonal. | |
column | 1-based column number for initial element of diagonal. |
Definition at line 1047 of file cmat.h.
Referenced by SCPPNT::Matrix< T >::end_diagonal().
01048 { 01049 Subscript num_elem = 0; 01050 01051 #ifdef SCPPNT_BOUNDS_CHECK 01052 01053 if (row < 1 || row > m_ || column < 1 || column > n_) BoundsError("SCPPNT::Matrix::begin_diagonal(row, column)"); 01054 num_elem = diagonal_size(row, column); 01055 01056 #endif 01057 01058 /* Pass zero for number of elements if SCPPNT_BOUNDS_CHECK 01059 is not defined, since in that case the number of elements is not used. */ 01060 return diag_iterator(v_ + column-1 + n_*(row-1), n_ + 1, num_elem); 01061 }
Matrix< T >::const_diag_iterator SCPPNT::Matrix< T >::begin_diagonal | ( | Subscript | row, | |
Subscript | column | |||
) | const [inline] |
Returns iterator pointing to first element of matrix diagonal.
Returns iterator pointing to the first element of the matrix diagonal given by (row, column), (row+1, column+1), (row+2, column+2), ... For example, if row=1 and column=1 then an iterator pointing to the first element of the main diagnonal is returned.
row | 1-based row number for initial element of diagonal. | |
column | 1-based column number for initial element of diagonal. |
Definition at line 1074 of file cmat.h.
01075 { 01076 Subscript num_elem = 0; 01077 01078 #ifdef SCPPNT_BOUNDS_CHECK 01079 01080 if (row < 1 || row > m_ || column < 1 || column > n_) BoundsError("SCPPNT::Matrix::begin_diagonal(row, column)"); 01081 num_elem = diagonal_size(row, column); 01082 01083 #endif 01084 01085 /* Pass zero for number of elements if SCPPNT_BOUNDS_CHECK 01086 is not defined, since in that case the number of elements is not used. */ 01087 return const_diag_iterator(v_ + column-1 + n_*(row-1), n_ + 1, num_elem); 01088 }
Matrix< T >::diag_iterator SCPPNT::Matrix< T >::end_diagonal | ( | Subscript | row, | |
Subscript | column | |||
) | [inline] |
Returns iterator pointing to one past last element of matrix diagonal.
Returns iterator pointing to the one past last element of the matrix diagonal given by (row, column), (row+1, column+1), (row+2, column+2), ... For example, for a square matrix with n rows and columns end_diagonal(1, 1) returns an iterator pointing to the element (row+n, column+n), which is one past the last element of the main diagonal.
row | 1-based row number for initial element of diagonal. | |
column | 1-based column number for initial element of diagonal. |
Definition at line 1102 of file cmat.h.
References SCPPNT::Matrix< T >::begin_diagonal().
01103 { 01104 diag_iterator it = begin_diagonal(row, column); 01105 return it + diagonal_size(row, column); 01106 }
Matrix< T >::const_diag_iterator SCPPNT::Matrix< T >::end_diagonal | ( | Subscript | row, | |
Subscript | column | |||
) | const [inline] |
Returns iterator pointing to one past last element of matrix diagonal.
Returns iterator pointing to the one past last element of the matrix diagonal given by (row, column), (row+1, column+1), (row+2, column+2), ... For example, for a square matrix with n rows and columns end_diagonal(1, 1) returns an iterator pointing to the element (row+n, column+n), which is one past the last element of the main diagonal.
row | 1-based row number for initial element of diagonal. | |
column | 1-based column number for initial element of diagonal. |
Definition at line 1119 of file cmat.h.
References SCPPNT::Matrix< T >::begin_diagonal().
01120 { 01121 const_diag_iterator it = begin_diagonal(row, column); 01122 return it + diagonal_size(row, column); 01123 }