iterative-solver 0.0
molpro::linalg::itsolv::subspace::Matrix< T > Class Template Reference

Matrix container that allows simple data access, slicing, copying and resizing without loosing data. More...

#include <Matrix.h>

Detailed Description

template<typename T>
class molpro::linalg::itsolv::subspace::Matrix< T >

Matrix container that allows simple data access, slicing, copying and resizing without loosing data.

This is not meant to be a general matrix, or to be very efficient. This is just a utility for internal implementation of IterativeSolver and it only supports operations that are necessary. Memory management is not done very efficiently, because for our use subspace matrices are relatively small.

Note
Row-major order.
Template Parameters
T

Classes

class  CSlice
 Constant slice that cannot be assigned to. More...
 
class  Slice
 Proxy mapping to a rectangular slice of the matrix data. Implements simple assignment. More...
 

Public Types

using value_type = T
 
using index_type = size_t
 
using coord_type = std::pair< size_t, size_t >
 

Public Member Functions

 Matrix (coord_type dims)
 
 Matrix (std::vector< T > &&data, coord_type dims)
 Construct a matrix by taking ownership of an existing data buffer which must be of correct size. More...
 
 Matrix (const std::vector< T > &data, coord_type dims)
 
 Matrix ()=default
 
 ~Matrix ()=default
 
 Matrix (const Matrix< T > &)=default
 
 Matrix (Matrix< T > &&) noexcept=default
 
Matrix< T > & operator= (const Matrix< T > &)=default
 
Matrix< T > & operator= (Matrix< T > &&) noexcept=default
 
T & operator() (index_type i, index_type j)
 Access element. More...
 
operator() (index_type i, index_type j) const
 Access element. More...
 
const std::vector< T > & data () const &
 Access the underlying data buffer. More...
 
std::vector< T > && data () &&
 Access the raw data buffer of an r-value matrix. The matrix is left empty. More...
 
bool empty () const
 Returns true if matrix is empty. More...
 
void clear ()
 Clears all elements and sets dimensions to 0. More...
 
coord_type to_coord (size_t ind) const
 Converts index of 1D data to matrix coordinate. More...
 
void fill (T value)
 Sets all elements of matrix to value. More...
 
Slice slice (coord_type upper_left, coord_type bottom_right)
 Access a rectangular slice of the matrix. More...
 
Slice slice ()
 Access the whole matrix as a slice. More...
 
CSlice slice (coord_type upper_left, coord_type bottom_right) const
 Access a constant rectangular slice of the matrix. More...
 
CSlice slice () const
 Access the whole matrix as a slice. More...
 
Slice row (size_t i)
 Access row slice. More...
 
CSlice row (size_t i) const
 
Slice col (size_t j)
 Access column slice. More...
 
CSlice col (size_t j) const
 
void resize (const coord_type &dims)
 Resize the matrix. The old data is preserved and any new rows/cols are zeroed. More...
 
void remove_row (index_type row)
 removes a row from the matrix More...
 
void remove_col (index_type col)
 removes a column from the matrix More...
 
void remove_row_col (index_type row, index_type col)
 removes row and column More...
 
index_type rows () const
 
index_type cols () const
 
coord_type dimensions () const
 
size_t size () const
 

Protected Attributes

index_type m_rows = 0
 number of rows More...
 
index_type m_cols = 0
 number of columns More...
 
std::vector< T > m_buffer
 data buffer More...
 

Member Typedef Documentation

◆ coord_type

template<typename T >
using molpro::linalg::itsolv::subspace::Matrix< T >::coord_type = std::pair<size_t, size_t>

◆ index_type

template<typename T >
using molpro::linalg::itsolv::subspace::Matrix< T >::index_type = size_t

◆ value_type

template<typename T >
using molpro::linalg::itsolv::subspace::Matrix< T >::value_type = T

Constructor & Destructor Documentation

◆ Matrix() [1/6]

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::Matrix ( coord_type  dims)
inlineexplicit

◆ Matrix() [2/6]

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::Matrix ( std::vector< T > &&  data,
coord_type  dims 
)
inlineexplicit

Construct a matrix by taking ownership of an existing data buffer which must be of correct size.

◆ Matrix() [3/6]

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::Matrix ( const std::vector< T > &  data,
coord_type  dims 
)
inlineexplicit

◆ Matrix() [4/6]

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::Matrix ( )
default

◆ ~Matrix()

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::~Matrix ( )
default

◆ Matrix() [5/6]

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::Matrix ( const Matrix< T > &  )
default

◆ Matrix() [6/6]

template<typename T >
molpro::linalg::itsolv::subspace::Matrix< T >::Matrix ( Matrix< T > &&  )
defaultnoexcept

Member Function Documentation

◆ clear()

template<typename T >
void molpro::linalg::itsolv::subspace::Matrix< T >::clear ( )
inline

Clears all elements and sets dimensions to 0.

◆ col() [1/2]

template<typename T >
Slice molpro::linalg::itsolv::subspace::Matrix< T >::col ( size_t  j)
inline

Access column slice.

◆ col() [2/2]

template<typename T >
CSlice molpro::linalg::itsolv::subspace::Matrix< T >::col ( size_t  j) const
inline

◆ cols()

template<typename T >
index_type molpro::linalg::itsolv::subspace::Matrix< T >::cols ( ) const
inline

◆ data() [1/2]

template<typename T >
std::vector< T > && molpro::linalg::itsolv::subspace::Matrix< T >::data ( ) &&
inline

Access the raw data buffer of an r-value matrix. The matrix is left empty.

◆ data() [2/2]

template<typename T >
const std::vector< T > & molpro::linalg::itsolv::subspace::Matrix< T >::data ( ) const &
inline

Access the underlying data buffer.

◆ dimensions()

template<typename T >
coord_type molpro::linalg::itsolv::subspace::Matrix< T >::dimensions ( ) const
inline

◆ empty()

template<typename T >
bool molpro::linalg::itsolv::subspace::Matrix< T >::empty ( ) const
inline

Returns true if matrix is empty.

◆ fill()

template<typename T >
void molpro::linalg::itsolv::subspace::Matrix< T >::fill ( value)
inline

Sets all elements of matrix to value.

◆ operator()() [1/2]

template<typename T >
T & molpro::linalg::itsolv::subspace::Matrix< T >::operator() ( index_type  i,
index_type  j 
)
inline

Access element.

Parameters
irow index
jcolumn index

◆ operator()() [2/2]

template<typename T >
T molpro::linalg::itsolv::subspace::Matrix< T >::operator() ( index_type  i,
index_type  j 
) const
inline

Access element.

Parameters
irow index
jcolumn index

◆ operator=() [1/2]

template<typename T >
Matrix< T > & molpro::linalg::itsolv::subspace::Matrix< T >::operator= ( const Matrix< T > &  )
default

◆ operator=() [2/2]

template<typename T >
Matrix< T > & molpro::linalg::itsolv::subspace::Matrix< T >::operator= ( Matrix< T > &&  )
defaultnoexcept

◆ remove_col()

template<typename T >
void molpro::linalg::itsolv::subspace::Matrix< T >::remove_col ( index_type  col)
inline

removes a column from the matrix

Parameters
colindex of the column to remove

◆ remove_row()

template<typename T >
void molpro::linalg::itsolv::subspace::Matrix< T >::remove_row ( index_type  row)
inline

removes a row from the matrix

Parameters
rowindex of the row to remove

◆ remove_row_col()

template<typename T >
void molpro::linalg::itsolv::subspace::Matrix< T >::remove_row_col ( index_type  row,
index_type  col 
)
inline

removes row and column

Parameters
rowrow incdex
colcolumn index

◆ resize()

template<typename T >
void molpro::linalg::itsolv::subspace::Matrix< T >::resize ( const coord_type dims)
inline

Resize the matrix. The old data is preserved and any new rows/cols are zeroed.

Parameters
dimsnew dimensions

◆ row() [1/2]

template<typename T >
Slice molpro::linalg::itsolv::subspace::Matrix< T >::row ( size_t  i)
inline

Access row slice.

◆ row() [2/2]

template<typename T >
CSlice molpro::linalg::itsolv::subspace::Matrix< T >::row ( size_t  i) const
inline

◆ rows()

template<typename T >
index_type molpro::linalg::itsolv::subspace::Matrix< T >::rows ( ) const
inline

◆ size()

template<typename T >
size_t molpro::linalg::itsolv::subspace::Matrix< T >::size ( ) const
inline

◆ slice() [1/4]

template<typename T >
Slice molpro::linalg::itsolv::subspace::Matrix< T >::slice ( )
inline

Access the whole matrix as a slice.

◆ slice() [2/4]

template<typename T >
CSlice molpro::linalg::itsolv::subspace::Matrix< T >::slice ( ) const
inline

Access the whole matrix as a slice.

◆ slice() [3/4]

template<typename T >
Slice molpro::linalg::itsolv::subspace::Matrix< T >::slice ( coord_type  upper_left,
coord_type  bottom_right 
)
inline

Access a rectangular slice of the matrix.

Parameters
upper_leftindices of upper left corner
bottom_rightpast the end indices of bottom right corner, so that dimensions of slice were (bottom_right-upper_left)

◆ slice() [4/4]

template<typename T >
CSlice molpro::linalg::itsolv::subspace::Matrix< T >::slice ( coord_type  upper_left,
coord_type  bottom_right 
) const
inline

Access a constant rectangular slice of the matrix.

Parameters
upper_leftindices of upper left corner
bottom_rightpast the end indices of bottom right corner, so that dimensions of slice were (bottom_right-upper_left)

◆ to_coord()

template<typename T >
coord_type molpro::linalg::itsolv::subspace::Matrix< T >::to_coord ( size_t  ind) const
inline

Converts index of 1D data to matrix coordinate.

Member Data Documentation

◆ m_buffer

template<typename T >
std::vector<T> molpro::linalg::itsolv::subspace::Matrix< T >::m_buffer
protected

data buffer

◆ m_cols

template<typename T >
index_type molpro::linalg::itsolv::subspace::Matrix< T >::m_cols = 0
protected

number of columns

◆ m_rows

template<typename T >
index_type molpro::linalg::itsolv::subspace::Matrix< T >::m_rows = 0
protected

number of rows