KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kjb::Generic_matrix_view< Matrix_type > Class Template Reference

#include <m_mat_view.h>

Public Types

typedef Generic_matrix_view Self
 
typedef Matrix_type::Value_type Value_type
 
typedef Matrix_type::Vec_type Vec_type
 
typedef int Size_type
 

Public Member Functions

 Generic_matrix_view (Matrix_type &mat, const Index_range &row_indices, const Index_range &col_indices)
 
 Generic_matrix_view (Matrix_type &mat)
 
 Generic_matrix_view (const Generic_matrix_view &src)
 
bool operator== (const Self &other)
 
bool operator== (const Matrix_type &other)
 
bool operator!= (const Self &other)
 
bool operator!= (const Matrix_type &other)
 
Value_typeoperator() (int r, int c)
 
Value_type operator() (int r, int c) const
 
Value_typeoperator() (int i)
 
Value_type operator() (int i) const
 
Value_typeoperator[] (int i)
 
Value_type operator[] (int i) const
 
Size_type get_num_rows () const
 
Size_type get_num_cols () const
 
Selfoperator= (const Matrix_type &mat)
 
Selfoperator= (const Self &mat)
 
Selfoperator= (const Value_type &s)
 
Selfoperator= (const Vec_type &v)
 
Selfoperator= (const std::vector< double > &v)
 
Selfoperator= (const std::vector< float > &v)
 
Selfoperator*= (Value_type s)
 
Selfoperator/= (Value_type s)
 
Selfoperator+= (const Self &s)
 
Selfoperator+= (const Matrix_type &s)
 
Selfoperator-= (const Self &s)
 
Selfoperator-= (const Matrix_type &s)
 

Protected Member Functions

void compute_row_col (int index, int *row, int *col) const
 This quickly computes row and column indices, assuming the Matrix has at least one column. More...
 
template<class Generic_matrix >
bool equality (const Generic_matrix &mat)
 
template<class Generic_matrix >
Selfassign (const Generic_matrix &mat)
 
template<class T >
Selfassign_from_vector (const T &v)
 
template<class Generic_matrix >
Selfplus_equals (const Generic_matrix &mat)
 
template<class Generic_matrix >
Selfminus_equals (const Generic_matrix &mat)
 

Protected Attributes

Index_range row_indices_
 
Index_range col_indices_
 
Matrix_type & mat_
 

Detailed Description

template<class Matrix_type>
class kjb::Generic_matrix_view< Matrix_type >

Represents a filtered "view" of another matrix. This object has the same semantics as a real Matrix, but altering it will alter the "visible" elements of the underlying matrix. Here's an example

Matrix mat = create_identity_matrix(); Matrix_view mat_view = mat(_,3); mat_view *= -1; assert(mat(2,2) == -1);

This may seem like a roundabout way of doing it, but when we put it all on one line, the power of this approach becomes obvous:

mat(_,3) *= -1;

Eventually, we would like to support matlab-like syntax using strings:

mat("2:8", 3) *= -1;

Member Typedef Documentation

template<class Matrix_type >
typedef Generic_matrix_view kjb::Generic_matrix_view< Matrix_type >::Self
template<class Matrix_type >
typedef int kjb::Generic_matrix_view< Matrix_type >::Size_type
template<class Matrix_type >
typedef Matrix_type::Value_type kjb::Generic_matrix_view< Matrix_type >::Value_type
template<class Matrix_type >
typedef Matrix_type::Vec_type kjb::Generic_matrix_view< Matrix_type >::Vec_type

Constructor & Destructor Documentation

template<class Matrix_type >
kjb::Generic_matrix_view< Matrix_type >::Generic_matrix_view ( Matrix_type &  mat,
const Index_range row_indices,
const Index_range col_indices 
)
inline
template<class Matrix_type >
kjb::Generic_matrix_view< Matrix_type >::Generic_matrix_view ( Matrix_type &  mat)
inline
template<class Matrix_type >
kjb::Generic_matrix_view< Matrix_type >::Generic_matrix_view ( const Generic_matrix_view< Matrix_type > &  src)
inline

Member Function Documentation

template<class Matrix_type >
template<class Generic_matrix >
Self& kjb::Generic_matrix_view< Matrix_type >::assign ( const Generic_matrix &  mat)
inlineprotected

generic version of operator=(). Made private to avoid unwanted template instantiation.

template<class Matrix_type >
template<class T >
Self& kjb::Generic_matrix_view< Matrix_type >::assign_from_vector ( const T &  v)
inlineprotected

generic version of operator=(). Made private to avoid unwanted template instantiation.

template<class Matrix_type >
void kjb::Generic_matrix_view< Matrix_type >::compute_row_col ( int  index,
int *  row,
int *  col 
) const
inlineprotected

This quickly computes row and column indices, assuming the Matrix has at least one column.

Precondition
We assume row and col are non-nil and the number of columns is bigger than zero.

This routine is used for the one-dimensional (row-major) addressing of the matrix WITHOUT bounds checking – for which speed is a priority.

Parameters
[in]indexRow-major index of some matrix element
[out]rowPtr to where to store its computed row index
[out]colPtr to where to store its computed column index
template<class Matrix_type >
template<class Generic_matrix >
bool kjb::Generic_matrix_view< Matrix_type >::equality ( const Generic_matrix &  mat)
inlineprotected

generic version of operator=(). Made private to avoid unwanted template instantiation.

template<class Matrix_type >
Size_type kjb::Generic_matrix_view< Matrix_type >::get_num_cols ( ) const
inline
template<class Matrix_type >
Size_type kjb::Generic_matrix_view< Matrix_type >::get_num_rows ( ) const
inline
template<class Matrix_type >
template<class Generic_matrix >
Self& kjb::Generic_matrix_view< Matrix_type >::minus_equals ( const Generic_matrix &  mat)
inlineprotected

generic version of operator-=(). Made private to avoid unwanted template instantiation

template<class Matrix_type >
bool kjb::Generic_matrix_view< Matrix_type >::operator!= ( const Self other)
inline
template<class Matrix_type >
bool kjb::Generic_matrix_view< Matrix_type >::operator!= ( const Matrix_type &  other)
inline
template<class Matrix_type >
Value_type& kjb::Generic_matrix_view< Matrix_type >::operator() ( int  r,
int  c 
)
inline
Warning
Bounds-checking is enabled, so expect a performance hit
template<class Matrix_type >
Value_type kjb::Generic_matrix_view< Matrix_type >::operator() ( int  r,
int  c 
) const
inline
Warning
Bounds-checking is enabled, so expect a performance hit
template<class Matrix_type >
Value_type& kjb::Generic_matrix_view< Matrix_type >::operator() ( int  i)
inline
template<class Matrix_type >
Value_type kjb::Generic_matrix_view< Matrix_type >::operator() ( int  i) const
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator*= ( Value_type  s)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator+= ( const Self s)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator+= ( const Matrix_type &  s)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator-= ( const Self s)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator-= ( const Matrix_type &  s)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator/= ( Value_type  s)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator= ( const Matrix_type &  mat)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator= ( const Self mat)
inline
template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator= ( const Value_type s)
inline

Set all elements to s

template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator= ( const Vec_type v)
inline

If this object has only 1 column or 1 row, set it equal to v or v', respectively.

template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator= ( const std::vector< double > &  v)
inline

If this object has only 1 column or 1 row, set it equal to v or v', respectively.

template<class Matrix_type >
Self& kjb::Generic_matrix_view< Matrix_type >::operator= ( const std::vector< float > &  v)
inline

If this object has only 1 column or 1 row, set it equal to v or v', respectively.

template<class Matrix_type >
bool kjb::Generic_matrix_view< Matrix_type >::operator== ( const Self other)
inline
template<class Matrix_type >
bool kjb::Generic_matrix_view< Matrix_type >::operator== ( const Matrix_type &  other)
inline
template<class Matrix_type >
Value_type& kjb::Generic_matrix_view< Matrix_type >::operator[] ( int  i)
inline
template<class Matrix_type >
Value_type kjb::Generic_matrix_view< Matrix_type >::operator[] ( int  i) const
inline
template<class Matrix_type >
template<class Generic_matrix >
Self& kjb::Generic_matrix_view< Matrix_type >::plus_equals ( const Generic_matrix &  mat)
inlineprotected

generic version of operator+=. Made private to avoid unwanted template instantiation

Member Data Documentation

template<class Matrix_type >
Index_range kjb::Generic_matrix_view< Matrix_type >::col_indices_
protected
template<class Matrix_type >
Matrix_type& kjb::Generic_matrix_view< Matrix_type >::mat_
protected
template<class Matrix_type >
Index_range kjb::Generic_matrix_view< Matrix_type >::row_indices_
protected

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