KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
kjb::Matrix_d< M, N, Transposed > Class Template Reference

#include <gr_opengl.h>

Inheritance diagram for kjb::Matrix_d< M, N, Transposed >:

Classes

struct  if_then_
 
struct  if_then_< false, value1, value2 >
 

Public Member Functions

 Matrix_d ()
 
 Matrix_d (const Matrix_d &m)
 
 Matrix_d (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &m)
 
template<class Iterator >
 Matrix_d (Iterator begin)
 Fill constructor. More...
 
 Matrix_d (const Matrix &m)
 Construct from "dynamic" vector. More...
 
 Matrix_d (double value)
 
void resize (size_t rows, size_t cols)
 
Matrix_dswap (Matrix_d &other)
 
Matrix_d< NROWS, NCOLS,!TRANSPOSED > & transpose ()
 
const Matrix_d< NROWS, NCOLS,!TRANSPOSED > & transpose () const
 
Matrix_doperator= (const Matrix_d &other)
 assignment More...
 
Matrix_doperator= (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &other)
 assignment More...
 
Matrix_doperator= (const Matrix &other)
 assignment from dynamic matrix More...
 
Matrix_doperator-= (const Matrix_d &second)
 
Matrix_d operator- (const Matrix_d &second) const
 
Matrix_doperator-= (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &second)
 
Matrix_d operator- (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &second) const
 
Matrix_doperator-= (const Matrix &second)
 
Matrix_d operator- (const Matrix &second) const
 
Matrix_d operator- () const
 negation More...
 
Matrix_doperator+= (const Matrix_d &second)
 
Matrix_d operator+ (const Matrix_d &second) const
 
Matrix_doperator+= (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &second)
 
Matrix_d operator+ (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &second) const
 
Matrix_doperator+= (const Matrix &second)
 
Matrix_d operator+ (const Matrix &second) const
 
template<std::size_t IN_COLS>
Matrix_d< num_rows, IN_COLS > operator* (const Matrix_d< num_cols, IN_COLS, false > &second) const
 
template<std::size_t IN_COLS>
Matrix_d< num_rows, IN_COLS > operator* (const Matrix_d< IN_COLS, num_cols, true > &second) const
 
Matrix_doperator*= (double s)
 multiplication by a scalar More...
 
template<std::size_t IN_ROWS, bool IN_TRANSPOSED>
Matrix_doperator*= (const Matrix_d< IN_ROWS, IN_ROWS, IN_TRANSPOSED > &other)
 
Matrix_d operator* (double s) const
 
Vector_d< num_rowsoperator* (const Vector_d< num_cols > &v) const
 
Matrix_doperator/= (double s)
 
Matrix_d operator/ (double s) const
 
double & operator() (size_t row, size_t col)
 
const double & operator() (size_t row, size_t col) const
 
Vector_d< num_colsget_row (size_t r) const
 
template<size_t D>
void set_row (size_t r, const Vector_d< D > &row)
 
Vector_d< num_rowsget_col (size_t c) const
 
template<size_t D>
void set_col (size_t c, const Vector_d< D > &col)
 
bool operator== (const Matrix_d &op2) const
 
bool operator== (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &op2) const
 
bool operator== (const Matrix &op2) const
 
bool operator!= (const Matrix_d &op2) const
 
bool operator!= (const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &op2) const
 
bool operator!= (const Matrix &op2) const
 
template<class Matrix_type >
Matrix_d< NROWS, NCOLS,
TRANSPOSED > & 
assignment_dispatch_ (Matrix_type &other)
 
template<class Matrix_op >
Matrix_d< NROWS, NCOLS,
TRANSPOSED > & 
plus_equals_dispatch_ (const Matrix_op &second)
 
template<class Matrix_op >
Matrix_d< NROWS, NCOLS,
TRANSPOSED > & 
minus_equals_dispatch_ (const Matrix_op &second)
 

Static Public Member Functions

static size_t get_num_rows ()
 
static size_t get_num_cols ()
 

Static Public Attributes

static const std::size_t num_cols = if_then_<TRANSPOSED, NROWS, NCOLS>::value
 
static const std::size_t num_rows = if_then_<TRANSPOSED, NCOLS, NROWS>::value
 

Detailed Description

template<size_t M, size_t N, bool Transposed>
class kjb::Matrix_d< M, N, Transposed >

Statically-allocated matrix. More limited in functionality than kjb::Matrix, but can offer significantly better performance, because no operations require heap allocation. Transposes are also handle statically, so a matrix can be transposed and used in operators without a copy and zero runtime overhead–the compiler simply calls a different version of the operation.

An added benefit is that all dimension mis-matches are caught at compile time.

Note
This is implemented as an array of Vector_d objects, which offers convenient semantics in some situations, especially with STL algorithms.
Warning
The transposed state of a matrix should be transparent to the user. For that reasons, square-bracket operator is generally discouraged, as it doesn't respect the transposed state. In other words, for transposed matrices, m(i,j) != m[i][j].
Template Parameters
NROWSnumber of rows in matrix
NCOLSnumber of columns in matrix
TRANSPOSEDswap meaning of rows and columns. You'll rarely set this manually; rather the "transpose()" method will set this. It's actually a bit confusing to work in this mode deliberately, because the meaning of NROWS and NCOLS is swapped. Just use m.transpose() and trust the implementation ;-)

Constructor & Destructor Documentation

template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::Matrix_d ( )
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::Matrix_d ( const Matrix_d< M, N, Transposed > &  m)
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::Matrix_d ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  m)
template<size_t M, size_t N, bool Transposed>
template<class Iterator >
kjb::Matrix_d< M, N, Transposed >::Matrix_d ( Iterator  begin)
inlineexplicit

Fill constructor.

template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::Matrix_d ( const Matrix m)
explicit

Construct from "dynamic" vector.

template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::Matrix_d ( double  value)
explicit

Member Function Documentation

template<size_t M, size_t N, bool Transposed>
template<class Matrix_type >
Matrix_d<NROWS,NCOLS,TRANSPOSED>& kjb::Matrix_d< M, N, Transposed >::assignment_dispatch_ ( Matrix_type &  other)
template<size_t M, size_t N, bool Transposed>
Vector_d<num_rows> kjb::Matrix_d< M, N, Transposed >::get_col ( size_t  c) const
inline
template<size_t M, size_t N, bool Transposed>
static size_t kjb::Matrix_d< M, N, Transposed >::get_num_cols ( )
inlinestatic
template<size_t M, size_t N, bool Transposed>
static size_t kjb::Matrix_d< M, N, Transposed >::get_num_rows ( )
inlinestatic
template<size_t M, size_t N, bool Transposed>
Vector_d<num_cols> kjb::Matrix_d< M, N, Transposed >::get_row ( size_t  r) const
inline
template<size_t M, size_t N, bool Transposed>
template<class Matrix_op >
Matrix_d<NROWS,NCOLS,TRANSPOSED>& kjb::Matrix_d< M, N, Transposed >::minus_equals_dispatch_ ( const Matrix_op &  second)
template<size_t M, size_t N, bool Transposed>
bool kjb::Matrix_d< M, N, Transposed >::operator!= ( const Matrix_d< M, N, Transposed > &  op2) const
inline
template<size_t M, size_t N, bool Transposed>
bool kjb::Matrix_d< M, N, Transposed >::operator!= ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  op2) const
inline
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
bool kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator!= ( const Matrix op2) const
inline
template<size_t M, size_t N, bool Transposed>
double& kjb::Matrix_d< M, N, Transposed >::operator() ( size_t  row,
size_t  col 
)
inline
template<size_t M, size_t N, bool Transposed>
const double& kjb::Matrix_d< M, N, Transposed >::operator() ( size_t  row,
size_t  col 
) const
inline
template<size_t M, size_t N, bool Transposed>
template<std::size_t IN_COLS>
Matrix_d<num_rows, IN_COLS> kjb::Matrix_d< M, N, Transposed >::operator* ( const Matrix_d< num_cols, IN_COLS, false > &  second) const
inline

Multiplying by a normal (non-transposed) matrix

template<size_t M, size_t N, bool Transposed>
template<std::size_t IN_COLS>
Matrix_d<num_rows, IN_COLS> kjb::Matrix_d< M, N, Transposed >::operator* ( const Matrix_d< IN_COLS, num_cols, true > &  second) const
inline

Multiplying by a transposed matrix

template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator* ( double  s) const
inline
template<size_t M, size_t N, bool Transposed>
Vector_d<num_rows> kjb::Matrix_d< M, N, Transposed >::operator* ( const Vector_d< num_cols > &  v) const
inline

multiplication by a vector.

Note
Dimensions must match for this method to exist.
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > & kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator*= ( double  s)

multiplication by a scalar

template<size_t M, size_t N, bool Transposed>
template<std::size_t IN_ROWS, bool IN_TRANSPOSED>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator*= ( const Matrix_d< IN_ROWS, IN_ROWS, IN_TRANSPOSED > &  other)
inline

Multiply and store in self.

Note
This is for convenience only, and has no performance benefit over a = a * b, since a temporary is still necessary to hold the result during the computation.
This method will only be available if matrix is square, i.e. NROWS == NCOLS.
template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator+ ( const Matrix_d< M, N, Transposed > &  second) const
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator+ ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  second) const
inline
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator+ ( const Matrix second) const
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator+= ( const Matrix_d< M, N, Transposed > &  second)
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator+= ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  second)
inline
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > & kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator+= ( const Matrix second)
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator- ( const Matrix_d< M, N, Transposed > &  second) const
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator- ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  second) const
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator- ( const Matrix second) const
inline
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator- ( ) const

negation

template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator-= ( const Matrix_d< M, N, Transposed > &  second)
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator-= ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  second)
inline
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > & kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator-= ( const Matrix second)
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d kjb::Matrix_d< M, N, Transposed >::operator/ ( double  s) const
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator/= ( double  s)
inline
template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::operator= ( const Matrix_d< M, N, Transposed > &  other)
inline

assignment

template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > & kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator= ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  other)

assignment

template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
Matrix_d< NROWS, NCOLS, TRANSPOSED > & kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator= ( const Matrix other)

assignment from dynamic matrix

template<size_t M, size_t N, bool Transposed>
bool kjb::Matrix_d< M, N, Transposed >::operator== ( const Matrix_d< M, N, Transposed > &  op2) const
inline
template<size_t M, size_t N, bool Transposed>
bool kjb::Matrix_d< M, N, Transposed >::operator== ( const Matrix_d< NCOLS, NROWS,!TRANSPOSED > &  op2) const
inline
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
bool kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::operator== ( const Matrix op2) const
template<size_t M, size_t N, bool Transposed>
template<class Matrix_op >
Matrix_d<NROWS,NCOLS,TRANSPOSED>& kjb::Matrix_d< M, N, Transposed >::plus_equals_dispatch_ ( const Matrix_op &  second)
template<size_t M, size_t N, bool Transposed>
void kjb::Matrix_d< M, N, Transposed >::resize ( size_t  rows,
size_t  cols 
)
inline

Construct a Matrix from two rows. This constructor only exists if NROWS == 2. Both rows must have size == NCOLS

Note
in transpose mode, r1 and r2 represent columns
Precondition
r1.size() == r2.size == NCOLS Construct a Matrix from three rows. This constructor only exists if NROWS == 3. All rows must have size == NCOLS
Note
in transpose mode, r1 and r2 represent columns
Precondition
r*.size() == NCOLS Construct a Matrix from four rows. This constructor only exists if NROWS == 4. All rows must have size == NCOLS
Note
in transpose mode, r1 and r2 represent columns
Precondition
r*.size() == NCOLS Implemented for compatibility with template functions that also operate on dynamic matrices. If rows != get_num_rows() or cols != get_num_cols(), this will be considered a bug and will trigger an abort.
rows == get_num_rows();
cols == get_num_cols();
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
template<size_t D>
void kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::set_col ( size_t  c,
const Vector_d< D > &  col 
)
template<size_t NROWS, size_t NCOLS, bool TRANSPOSED>
template<size_t D>
void kjb::Matrix_d< NROWS, NCOLS, TRANSPOSED >::set_row ( size_t  r,
const Vector_d< D > &  row 
)
template<size_t M, size_t N, bool Transposed>
Matrix_d& kjb::Matrix_d< M, N, Transposed >::swap ( Matrix_d< M, N, Transposed > &  other)
inline

NOT a constant-time operation! This will most likely perform one stack allocation and two assignments, like the default swap operation. This is because data is stored on the stack, so pointers can't be moved around.

template<size_t M, size_t N, bool Transposed>
Matrix_d<NROWS, NCOLS, !TRANSPOSED>& kjb::Matrix_d< M, N, Transposed >::transpose ( )
inline
template<size_t M, size_t N, bool Transposed>
const Matrix_d<NROWS, NCOLS, !TRANSPOSED>& kjb::Matrix_d< M, N, Transposed >::transpose ( ) const
inline

Member Data Documentation

template<size_t M, size_t N, bool Transposed>
const std::size_t kjb::Matrix_d< M, N, Transposed >::num_cols = if_then_<TRANSPOSED, NROWS, NCOLS>::value
static
template<size_t M, size_t N, bool Transposed>
const std::size_t kjb::Matrix_d< M, N, Transposed >::num_rows = if_then_<TRANSPOSED, NCOLS, NROWS>::value
static

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