Cypress  1.0
C++ Spiking Neural Network Simulation Framework
Public Member Functions | Friends | List of all members
cypress::Matrix< T > Class Template Reference

#include <matrix.hpp>

Inheritance diagram for cypress::Matrix< T >:
Inheritance graph
[legend]

Public Member Functions

 Matrix ()
 
 Matrix (std::initializer_list< T > init)
 
template<size_t Rows, size_t Cols>
 Matrix (const std::array< std::array< T, Cols >, Rows > &init)
 
 Matrix (const std::vector< std::vector< T >> &init)
 
 Matrix (const std::vector< T > &init)
 
 Matrix (size_t rows, size_t cols, MatrixFlags flags=MatrixFlags::NONE)
 
 Matrix (size_t rows, size_t cols, const T *data)
 
 Matrix (size_t rows, size_t cols, T *data, bool destroy)
 
 Matrix (const Matrix &o)
 
 Matrix (Matrix &&o) noexcept
 
Matrixoperator= (const Matrix &o)
 
Matrixoperator= (Matrix &&o) noexcept
 
 ~Matrix ()
 
 operator std::vector< T > () const
 
bool operator== (const Matrix< T > &o) const
 
Matrix< T > & fill (const T &val)
 
T * begin (size_t row=0)
 
T * end ()
 
const T * begin (size_t row=0) const
 
const T * end () const
 
const T * cbegin (size_t row=0) const
 
const T * cend () const
 
T & operator() (size_t row, size_t col)
 
const T & operator() (size_t row, size_t col) const
 
T & operator() (size_t i)
 
const T & operator() (size_t i) const
 
T & operator[] (size_t i)
 
const T & operator[] (size_t i) const
 
size_t rows () const
 
size_t cols () const
 
size_t size () const
 
void resize (size_t rows, size_t cols)
 
void reshape (size_t rows, size_t cols)
 
T * data ()
 
const T * data () const
 
bool empty () const
 
Matrix submatrix (size_t row, size_t col) const
 Returns the submatrix not containing specified row and column. More...
 
determinant () const
 Calculate the determinant of this matrix. Note that the type of the returned value is of the same type as the matrix, which might be a problem for unsigned types! Only valid for squared matrices! More...
 
Matrix adjugate () const
 Calculates the adjugate/adjunct matrix. As for the determinant, this runs into issues with unsigned types and works only for squared matrices! More...
 
Matrix< double > inverse () const
 Calculates the inverse of the matrix. As for the determinant, this runs into issues with unsigned types and works only for squared matrices! Note that the type of the returned matrix is always double! Throws if matrix is not invertible! More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Matrix< T > &m)
 

Detailed Description

template<typename T>
class cypress::Matrix< T >

Base class providing storage for a 2D memory region of an arbitrary type T.

Template Parameters
Tis the type stored in the matrix.

Constructor & Destructor Documentation

template<typename T>
cypress::Matrix< T >::Matrix ( )
inline

Default constructor. Creates an empty matrix.

template<typename T>
cypress::Matrix< T >::Matrix ( std::initializer_list< T >  init)
inline

Initialiser list constructor.

template<typename T>
template<size_t Rows, size_t Cols>
cypress::Matrix< T >::Matrix ( const std::array< std::array< T, Cols >, Rows > &  init)
inline

2D array constructor.

template<typename T>
cypress::Matrix< T >::Matrix ( const std::vector< std::vector< T >> &  init)
inline
template<typename T>
cypress::Matrix< T >::Matrix ( const std::vector< T > &  init)
inline
template<typename T>
cypress::Matrix< T >::Matrix ( size_t  rows,
size_t  cols,
MatrixFlags  flags = MatrixFlags::NONE 
)
inline

Constructor of the Matrix type, creates a new matrix with the given extent.

Parameters
rowsis the number of rows in the matrix.
colsis the number of columns in the matrix.
flagsset to MatrixFlags::ZEROS to force an initialisation of the memory. If not given, the memory is not initialised.
template<typename T>
cypress::Matrix< T >::Matrix ( size_t  rows,
size_t  cols,
const T *  data 
)
inline

Constructor of the Matrix type, creates a new matrix with the given extent, copying the data from the given address.

Parameters
rowsis the number of rows in the matrix.
colsis the number of columns in the matrix.
datais a pointer at a pre-existing data region from which the data will be copied.
template<typename T>
cypress::Matrix< T >::Matrix ( size_t  rows,
size_t  cols,
T *  data,
bool  destroy 
)
inline

Constructor of the Matrix type from an existing data structure without a copy

Parameters
rowsis the number of rows in the matrix.
colsis the number of columns in the matrix.
datais a pointer at a pre-existing data region
destroyTrue: destructor will free memory, False: Destructor will do nothing
template<typename T>
cypress::Matrix< T >::Matrix ( const Matrix< T > &  o)
inline
template<typename T>
cypress::Matrix< T >::Matrix ( Matrix< T > &&  o)
inlinenoexcept
template<typename T>
cypress::Matrix< T >::~Matrix ( )
inline

Member Function Documentation

template<typename T>
Matrix cypress::Matrix< T >::adjugate ( ) const
inline

Calculates the adjugate/adjunct matrix. As for the determinant, this runs into issues with unsigned types and works only for squared matrices!

Returns
Matrix< T > Adjugate matrix.
template<typename T>
T* cypress::Matrix< T >::begin ( size_t  row = 0)
inline
template<typename T>
const T* cypress::Matrix< T >::begin ( size_t  row = 0) const
inline
template<typename T>
const T* cypress::Matrix< T >::cbegin ( size_t  row = 0) const
inline
template<typename T>
const T* cypress::Matrix< T >::cend ( ) const
inline
template<typename T>
size_t cypress::Matrix< T >::cols ( ) const
inline

Returns the height of the matrix.

template<typename T>
T* cypress::Matrix< T >::data ( )
inline

Returns a pointer at the raw data buffer.

template<typename T>
const T* cypress::Matrix< T >::data ( ) const
inline

Returns a const pointer at the raw data.

template<typename T>
T cypress::Matrix< T >::determinant ( ) const
inline

Calculate the determinant of this matrix. Note that the type of the returned value is of the same type as the matrix, which might be a problem for unsigned types! Only valid for squared matrices!

Returns
Value of the determinant.
template<typename T>
bool cypress::Matrix< T >::empty ( ) const
inline

Returns true if the matrix contains no data.

template<typename T>
T* cypress::Matrix< T >::end ( )
inline
template<typename T>
const T* cypress::Matrix< T >::end ( ) const
inline
template<typename T>
Matrix<T>& cypress::Matrix< T >::fill ( const T &  val)
inline

Fills the matrix with the given value.

template<typename T>
Matrix<double> cypress::Matrix< T >::inverse ( ) const
inline

Calculates the inverse of the matrix. As for the determinant, this runs into issues with unsigned types and works only for squared matrices! Note that the type of the returned matrix is always double! Throws if matrix is not invertible!

Returns
cypress::Matrix< double > The inverse.
template<typename T>
cypress::Matrix< T >::operator std::vector< T > ( ) const
inline

Conversion to a std::vector

template<typename T>
T& cypress::Matrix< T >::operator() ( size_t  row,
size_t  col 
)
inline

Returns a reference at the element at position row and col.

template<typename T>
const T& cypress::Matrix< T >::operator() ( size_t  row,
size_t  col 
) const
inline

Returns a const reference at the element at position row and col.

template<typename T>
T& cypress::Matrix< T >::operator() ( size_t  i)
inline

Returns a reference at the i-th element.

template<typename T>
const T& cypress::Matrix< T >::operator() ( size_t  i) const
inline

Returns a const reference at the i-th element.

template<typename T>
Matrix& cypress::Matrix< T >::operator= ( const Matrix< T > &  o)
inline
template<typename T>
Matrix& cypress::Matrix< T >::operator= ( Matrix< T > &&  o)
inlinenoexcept
template<typename T>
bool cypress::Matrix< T >::operator== ( const Matrix< T > &  o) const
inline

Tests equality between two matrices.

Parameters
ois the matrix to which this matrix should be compared.
template<typename T>
T& cypress::Matrix< T >::operator[] ( size_t  i)
inline

Returns a copy of the i-th element.

template<typename T>
const T& cypress::Matrix< T >::operator[] ( size_t  i) const
inline

Returns a copy of the i-th element.

template<typename T>
void cypress::Matrix< T >::reshape ( size_t  rows,
size_t  cols 
)
inline

Reshapes the matrix if rows * cols does not change. Otherwise flushes all previously stored data, does nothing if the dimensions do not change.

template<typename T>
void cypress::Matrix< T >::resize ( size_t  rows,
size_t  cols 
)
inline

Resizes the matrix, flushes all previously stored data, does nothing if the dimensions do not change.

template<typename T>
size_t cypress::Matrix< T >::rows ( ) const
inline

Returns the width of the matrix.

template<typename T>
size_t cypress::Matrix< T >::size ( ) const
inline

Returns the size of the matrix.

template<typename T>
Matrix cypress::Matrix< T >::submatrix ( size_t  row,
size_t  col 
) const
inline

Returns the submatrix not containing specified row and column.

Parameters
rowrow to delete
colcolumn to delete
Returns
Matrix< T > submatrix with deleted row and column

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const Matrix< T > &  m 
)
friend

Dumps the matrix as CSV.


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