NABLA  Nabla Ain't Basic Linear Algebra
Public Types | Public Member Functions | List of all members
matrix< value_t, shape > Class Template Reference

Square matrix template class. More...

Inheritance diagram for matrix< value_t, shape >:
Inheritance graph

Public Types

typedef util::sequence
< value_type >
::const_reference 
const_reference
 Type of reference to constant element.
typedef util::sequence
< value_type >::reference 
reference
 Type of reference to element.
typedef value_t value_type
 Type of elements.

Public Member Functions

 matrix ()
 Default constructor.
 matrix (const matrix &a)
 Copy constructor.
 matrix (temporary< matrix > &a)
 Move constructor from temporary object.
template<typename expr_t , typename tag >
 matrix (const shaped_expression< value_type, expr_t, tag, shape > &a)
 Copy constructor from matrix expression.
 matrix (size_t size)
 Constructor with size initialization.
 matrix (size_t size, const_reference value)
 Constructor with size and value initialization.
 ~matrix ()
 Destructor.
template<typename expr_t , typename tag >
void assign (const shaped_expression< value_type, expr_t, tag, shape > &rhs)
 Assigns symmetric matrix expression to this object.
size_t cols () const
 Returns number of columns.
reference operator() (size_t row, size_t column)
 Subscript operator.
const_reference operator() (size_t row, size_t column) const
 Subscript operator.
row_ref operator() (size_t row)
 Subscript operator.
const_row_ref operator() (size_t row) const
 Subscript operator.
matrixoperator= (const matrix &a)
 Assignment operator.
template<typename expr_t , typename tag >
matrixoperator= (const shaped_expression< value_type, expr_t, tag, shape > &a)
 Assignment operator.
matrixoperator= (temporary< matrix > &a)
 Move assignment operator.
row_ref operator[] (size_t row)
 Subscript operator.
const_row_ref operator[] (size_t row) const
 Subscript operator.
void resize (size_t size)
 Resizes matrix.
void resize (size_t size, const_reference value)
 Resizes matrix.
size_t rows () const
 Returns number of rows.
void swap (matrix &a)
 Swaps contents of two matrices.

Detailed Description

template<typename value_t, typename shape>
class nabla::matrix< value_t, shape >

Square matrix template class.

See matrix<value_t, rectangular> specialization for information about general matrix template class.

All square matrices share a restriction: matrices can not be resized to rectangular shape, i.e. can not have size other than n by n elements. This is ensured by the design and one will have to make an effort to brake this constraint. To stick to this policy all user-defined types related to square matrices in any way should also ensure this design constraint.

Depending on the specified shape there are different space optimizations, implementation details and guarantees. The remaining sections discuss that in detail. For more information about shapes consult Matrix Shape.

Symmetrically Shaped matrix

Such a matrix is invoked like

matrix<double, symmetric> m;
Additional guarantees:
Elements of a matrix<value_t, symmetric> are stored in memory continuously row by row. Only lower triangular part elements are stored. This implies
&m(i, j)==&m(0, 0) + (i1*(i1 + 1)/2 + j1))
is always satisfied for non-empty matrix and i1 = max(i, j); j1 = min(i, j); i<m.rows() && j<m.cols().

Lower Triangular Shaped matrix

Such a matrix is invoked like

matrix<double, lower_triangular> m;

or, using a typedef for lower_triangular,

matrix<double, lower_tr> m;
Additional guarantees:
Elements of a matrix<value_t, lower_triangular> are stored in memory continuously row by row. Only lower triangular part elements are stored. This implies
&m(i, j)==&m(0, 0) + ((i*(i + 1))/2 + j)
is always satisfied for non-empty matrix and i<m.rows() && j<m.cols() && j<=i.

Upper Triangular Shaped matrix

Such a matrix is invoked like

matrix<double, upper_triangular> m;

or, using a typedef for upper_triangular,

matrix<double, upper_tr> m;
Additional guarantees:
Elements of a matrix<value_t, upper_triangular> are stored in memory continuously row by row. Only upper triangular part elements are stored. This implies
&m(i, j)==&m(0, 0) + ((i*(2*m.rows() - i - 1))/2 + j)
is always satisfied for non-empty matrix and i<m.rows() && j<m.cols() && j>=i.
See Also
matrix<value_t, rectangular>, matrix_expression, vector

Definition at line 2624 of file matrix.h.

Member Function Documentation

void assign ( const shaped_expression< value_type, expr_t, tag, shape > &  rhs)
inline

Assigns symmetric matrix expression to this object.

Warning
This function may produce suprising results. Equivalent effect of this function is if this object were erased and then assigned the rhs.

This function assigns rhs in the most efficient way. It means that no temporary is introduced to store intermediate result. This circumstance can cause suprising results as stated above.Like in the STL this function doesn't care about object's previous state. The function discards all the contents (which may immediately invalidate all references to this object) and copies the result of rhs expression to this object's new contents.In other words this object should not be involved in the argument expression rhs. Otherwise this function may produce unexpected result or even crash the program.

Definition at line 2711 of file matrix.h.

reference operator() ( size_t  row,
size_t  column 
)
inline

Subscript operator.

Returns a reference to an element (row, column).

Since for lower and upper triangular matrices some elements are zero by definition (and hence not stored) an attempt to modify such elements will fail.

access_error is thrown under the following circumstances:

  • if an element (i, j) of a lower triangular matrix with i<j (i.e. super diagonal element) is to be modified;
  • if an element (i, j) of an upper triangular matrix with i>j (i.e. sub diagonal element) is to be modified.

Definition at line 2685 of file matrix.h.

void resize ( size_t  size)
inline

Resizes matrix.

Changes matrix size to size by size. Values of elements are undefined.

Definition at line 2722 of file matrix.h.

void resize ( size_t  size,
const_reference  value 
)
inline

Resizes matrix.

Changes matrix size to size by size. Values of elements are set to value.

Definition at line 2734 of file matrix.h.

void swap ( matrix< value_t, shape > &  a)
inline

Swaps contents of two matrices.

This function is not meant to throw any exceptions.

Definition at line 2742 of file matrix.h.


The documentation for this class was generated from the following file: