Matrix
Matrix offers two template classes of fixed N-dimensional matrices
of any given type: a "normal" Matrix class and a CompressedMatrix
class. The CompressedMatrix class offers compression by using ranges of
identical neighbouring values. Additionally Matrix offers a
DynamicMatrix class
which is N-dimensional, and the dimensionality is variable during
runtime.
Note: the CompressedMatrix class actually only compresses when many
neighbouring values are identical!
Matrices can be in
row-major (C-style) or column-major(FORTRAN/Matlab-style)
addressing modes.
Interface
Fixed Dimensionality
In the following table, one may read CompressedMatrix for Matrix.
The exact definition is:
template <typename T, std::size_t Dimensions>
class Matrix;
value_type |
The type of the values in the Matrix. |
iterator |
The iterator type of this Matrix. |
const_iterator |
The const_iterator type of this Matrix, for read-only access. |
Matrix(bool colMajor = false) |
Default Constructor |
template <typename Iterator>
Matrix(Iterator extentsIt) |
Constructor, dimensions as prescribed in the range indicated by
extentsIt. |
template <typename Iterator>
Matrix(Iterator extentsIt, const T value, bool colMajor = false) |
Constructor, dimensions as prescribed in the range indicated by
extentsIt, filled with "value". Parameter colMajor allows
one to use colums-major addressing in stead of row-major addressing.
|
template <typename Iterator1, typename Iterator2>
Matrix(const Iterator1 extentsIt,
const Iterator2 beginData, const Iterator2 endData,
bool colMajor = false) |
Constructor, dimensions as prescribed in the range indicated by
extentsIt. The Matrix is filled with values from the range
beginData to endData. Parameter colMajor
allows one to use colums-major addressing in stead of row-major
addressing.
|
template <typename U>
Matrix(const std::initializer_list<U> init_list) |
Constructor, dimensions as prescribed in the range indicated by
the initializer_list init_list. |
template <typename U>
Matrix(const std::initializer_list<U> init_list,
const T value, bool colMajor = false) |
Constructor, dimensions as prescribed in the range indicated by
the initializer_list init_list, filled with value. Parameter colMajor allows
one to use colums-major addressing in stead of row-major addressing.
|
template <typename U, typename Iterator>
Matrix(const std::initializer_list<U> init_list,
const Iterator beginData, const Iterator endData,
bool colMajor = false) |
Constructor, dimensions as prescribed in the range indicated by
the initializer_list init_list. The Matrix is filled with values from the range
beginData to endData. Parameter colMajor
allows one to use colums-major addressing in stead of row-major
addressing.
|
std::size_t size() const |
Number of elements in the Matrix. |
std::tr1::array<std::size_t, D>::const_iterator extents() const |
Extents, i.e. sizes in all dimensions. |
template <typename Iterator>
void resize(Iterator extentsIt) |
Change the size and shape of the Matrix according to the extents
given in the range indicated by "extentsIt". |
template <typename U>
void resize(const std::initializer_list<U> size_list) |
Change the size and shape of the Matrix according to the extents
given in the initializer_list size_list. |
Matrix<T, Dimensions-1>
&operator[] (const std::size_t index) |
Returns a reference to a Matrix with one less dimension. |
const Matrix<T, Dimensions-1>
&operator[] (const std::size_t index) const |
Returns a reference to a const Matrix with one less dimension. |
iterator begin() |
Iterator pointing to the first element. |
iterator end() |
Iterator pointing to the non-existing end element. |
const_iterator begin() const |
const_iterator pointing to the first element. |
const_iterator end() const |
const_iterator pointing to the non-existing end element. |
void changeMajor() |
Change between row-major and column-major addressing. |
bool colMajor() |
Return true if matrix is in column-major addressing mode,
false if the matrix is in row-major mode. |
void clear() |
Completely empty the matrix. |
Dynamic Dimensionality
The DynamicMatrix can have any dimension chosen during runtime, and the
dimensionality can be changed during runtime if desired.
value_type |
The type of the values in the Matrix. |
iterator |
The iterator type of this Matrix. |
const_iterator |
The const_iterator type of this Matrix, for read-only access. |
slice_type |
. |
template <typename It>
DynamicMatrix(It extentsBegin, It extentsEnd) |
. |
template <typename It>
DynamicMatrix(It extentsBegin, It extentsEnd, T value) |
. |
std::size_t size() const |
Returns the number of elements in the entire matrix. |
std::size_t dimensions() const |
Returns the current number of dimensions of the matrix. |
std::vector<std::size_t>::const_iterator extents() const |
. |
slice_type &operator[](std::size_t index) |
. |
const slice_type &operator[](std::size_t index) const |
. |
template <typename It>
void resize(It extentsBegin, It extentsEnd, bool preserve = false)
|
. |
iterator begin() |
Begin iterator over all elements. |
iterator end() |
End iterator over all elements. |
const_iterator begin() const |
Begin read-only iterator over all elements. |
const_iterator end() const |
End read-only iterator over all elements. |
void clear() |
Completely empty the matrix, set to zero all extents in all dimensions. |
SymmetricMatrix
A SymmetricMatrix is an n-by-n 2-dimensional matrix that
is equal to its transpose, i.e. an element at (x, y) is the same as
the element at (y, x).
In the context of a SymmetricMatrix, there is a distiction between
physical elements, i.e. memory locations, and logical elements,
which are positions in the matrix. In short, the two logical elements (x, y)
and (y, x) refer to one physical element.
value_type |
The type of the values in the Matrix. |
iterator |
This type of read/write iterator iterates over the rank()*rank() logical elements in the matrix. |
const_iterator |
The const_iterator type of this Matrix, for read-only access. This type of iterator iterates over
the rank()*rank() logical elements in the matrix. |
row_iterator |
A special iterator type of for rows in the Matrix. This type of iterator iterates over the physical elements in a row the matrix. |
const_row_iterator |
A special const_iterator type of for rows in the Matrix. This type of iterator iterates over the physical elements in a row of the matrix. |
SymmetricMatrix(const std::size_t rank = 0) |
Construct a SymmetricMatrix with rank rows and columns. |
SymmetricMatrix(const std::size_t rank, const T value) |
Construct a SymmetricMatrix with rank rows and columns, and
fills it entirely with the given value. |
std::size_t size() const |
Returns the number of physical elements in memory, i.e. rank()*(rank()+1)/2. |
std::size_t rank() const |
Returns the number of rows, which is equal to the number of
columns. |
void resize(const std::size_t rank) |
Resize to an rank-by-rank matrix. |
const SymmetricMatrix operator=(const T value) |
Fill the entire Matrix with the given value. |
T &operator()(const std::size_t row, const std::size_t column) |
Return reference to an element in the matrix. If row and column would be
swapped, the same physical element would be returned. |
const T &operator()(const std::size_t row, const std::size_t column) const |
Return read-only reference to an element in the matrix. If
row and column are swapped, the same physical element is returned. |
iterator begin() |
Begin iterator over all rank-by-rank logical elements in the matrix. |
iterator end() |
End iterator over all logical elements. |
const_iterator begin() const |
Begin read-only iterator over all rank-by-rank logical elements. |
const_iterator end() const |
End read-only iterator over all logical elements. |
row_iterator begin(const std::size_t row) |
Begin iterator over the physical elements in the indicated row.
The length of the range is rank-row. |
row_iterator end(const std::size_t row) |
End iterator over the physical elements in the indicated row. |
const_row_iterator begin(const std::size_t row) const |
Begin read-only iterator over the physical elements in the indicated row.
The length of the range is rank-row. |
const_row_iterator end(const std::size_t row) const |
End read-only iterator over the physical elements in the indicated row. |
void swap(SymmetricMatrix that) |
Swap this matix with that one. |
|