Kalman::KMatrix< T, BEG, DBG > Class Template Reference

Minimalist matrix template class. More...

#include <kmatrix.hpp>

List of all members.

Public Types

enum  { beg = BEG }
typedef T type
 Type of objects contained in the matrix.

Public Member Functions

void assign (K_UINT_32 m, K_UINT_32 n, const T *v)
 Copies a C-style array of instances of T in an m by n matrix.
KMatrixoperator= (const KMatrix &M)
 Copy assignment operator. Performs a deep copy.
KMatrixoperator= (const T &a)
 Assigns a copy of a to all elements of the matrix.
void resize (K_UINT_32 m, K_UINT_32 n)
 Resizes the matrix. Resulting matrix contents are undefined.
void swap (KMatrix &M)
 Constant-time swap function between two matrices.
Streaming functions

void get (std::istream &is)
 Reads a matrix from a stream.
void put (std::ostream &os) const
 Writes a matrix to a stream.
Constructors and destructor.

 KMatrix (const KMatrix &M)
 Copy constructor. Performs a deep copy.
 KMatrix (K_UINT_32 m, K_UINT_32 n, const T *v)
 Creates an m by n matrix from an array of instances of T.
 KMatrix (K_UINT_32 m, K_UINT_32 n, const T &a)
 Creates an m by n matrix of copies of a.
 KMatrix (K_UINT_32 m, K_UINT_32 n)
 Creates an m by n matrix of default instances of T.
 KMatrix ()
 Default constructor. Creates an empty matrix.
 ~KMatrix ()
 Destructor.
Member access functions.

K_UINT_32 ncol () const
 Returns n_, the number of columns of the matrix.
K_UINT_32 nrow () const
 Returns m_, the number of rows of the matrix.
const T & operator() (K_UINT_32 i, K_UINT_32 j) const
 Returns the element (i,j), const version.
T & operator() (K_UINT_32 i, K_UINT_32 j)
 Returns the element (i,j).

Private Member Functions

void init (K_UINT_32 m, K_UINT_32 n)
 Helper function to initialize matrix.

Private Attributes

K_UINT_32 m_
 Number of rows of matrix.
T ** M_
 Pointer to the start of vimpl_.
std::vector< T > Mimpl_
 Underlying vector implementation.
K_UINT_32 n_
 Number of columns of matrix.
std::vector< T * > vimpl_
 Array of pointers to rows of Mimpl_.

Detailed Description

template<typename T, K_UINT_32 BEG, bool DBG>
class Kalman::KMatrix< T, BEG, DBG >

Minimalist matrix template class.

This matrix class does not define any fancy linear algebra functions, nor even any operator between matrices. Its sole purpose is to well encapsulate an extensible array representing a matrix, and also to allow starting index to be 0 or 1.

Template parameters
  • T : Type of elements contained in the matrix. Usually float or double.
  • BEG : Starting index of matrix. Can be either 0 or 1.
  • DGB : Debug flag. If true, then bound-checking will be performed, and OutOfBoundError exceptions can be thrown.
Type requirements for T
  • T must be default constructible.
  • T must be assignable.
  • T must be serializable.
This means that, if t1, t2 are instances of T, is is of type istream and os is of type ostream, the following expressions must be valid :
  •  T(); T t1; 
    
    Default constructor
  •  T t1 = t2; T t1(t2); T(t1); 
    
    Copy constructor
  •  t1 = t2; 
    
    Assignment operator
  •  is >> t1; 
    
    operator>>()
  •  os << t1; 
    
    operator<<()
Finally, note that operator>>() and operator<<() must be compatible. Also, operator&() must not have been overloaded.

Definition at line 72 of file kmatrix.hpp.


Member Typedef Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
typedef T Kalman::KMatrix< T, BEG, DBG >::type

Type of objects contained in the matrix.

Definition at line 75 of file kmatrix.hpp.


Member Enumeration Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
anonymous enum
Enumerator:
beg 

Starting index of matrix, either 0 or 1.

Definition at line 77 of file kmatrix.hpp.


Constructor & Destructor Documentation

template<typename T , K_UINT_32 BEG, bool DBG>
Kalman::KMatrix< T, BEG, DBG >::KMatrix (  )  [inline]

Default constructor. Creates an empty matrix.

Definition at line 135 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
Kalman::KMatrix< T, BEG, DBG >::KMatrix ( K_UINT_32  m,
K_UINT_32  n 
) [inline]

Creates an m by n matrix of default instances of T.

Parameters:
m Number of rows in matrix. Can be 0.
n Number of columns in matrix. Can be 0.
Note:
If either m or n is 0, then both the number of rows and the number of columns will be set to 0.

Definition at line 144 of file kmatrix_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
Kalman::KMatrix< T, BEG, DBG >::KMatrix ( K_UINT_32  m,
K_UINT_32  n,
const T &  a 
) [inline]

Creates an m by n matrix of copies of a.

Parameters:
m Number of rows in matrix. Can be 0.
n Number of columns in matrix. Can be 0.
a Value to copy multiple times in the matrix.
Note:
If either m or n is 0, then both the number of rows and the number of columns will be set to 0.

Definition at line 155 of file kmatrix_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
Kalman::KMatrix< T, BEG, DBG >::KMatrix ( K_UINT_32  m,
K_UINT_32  n,
const T *  v 
) [inline]

Creates an m by n matrix from an array of instances of T.

This function allows to transform a C-style array of T objects in a KMatrix<T, BEG, DBG> equivalent array. Note that objects from the C-style array are copied into the matrix, which may slow down application if used extensively. The elements are copied row-wise, that is to say, the elements of the C-style array first fill the first row of the matrix, then the second, etc.

Parameters:
m Number of rows in matrix. Can be 0.
n Number of columns in matrix. Can be 0.
v Pointer to an m*n array of T objects.
Note:
If either m or n is 0, then both the number of rows and the number of columns will be set to 0.

Definition at line 172 of file kmatrix_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
Kalman::KMatrix< T, BEG, DBG >::KMatrix ( const KMatrix< T, BEG, DBG > &  M  )  [inline]

Copy constructor. Performs a deep copy.

Parameters:
M Matrix to copy. Can be an empty matrix.

Definition at line 180 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
Kalman::KMatrix< T, BEG, DBG >::~KMatrix (  )  [inline]

Destructor.

Definition at line 186 of file kmatrix_impl.hpp.


Member Function Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
void Kalman::KMatrix< T, BEG, DBG >::assign ( K_UINT_32  m,
K_UINT_32  n,
const T *  v 
) [inline]

Copies a C-style array of instances of T in an m by n matrix.

The elements are copied row-wise, that is to say, the elements of the C-style array first fill the first row of the matrix, then the second, etc.

Parameters:
m Number of rows in matrix. Can be 0.
n Number of columns in matrix. Can be 0.
v Pointer to first element to copy from C-style array.
Warning:
This function invalidates pointers inside the vector.

Definition at line 320 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KMatrix< T, BEG, DBG >::get ( std::istream &  is  )  [inline]

Reads a matrix from a stream.

This function will extract nrow()*ncol() elements from a stream to fill the matrix, while considering the formatting constraints of the current matrix printing context.

Parameters:
is A reference to the input stream.
See also:
createKMatrixContext()
selectKMatrixContext()

Definition at line 347 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KMatrix< T, BEG, DBG >::init ( K_UINT_32  m,
K_UINT_32  n 
) [inline, private]

Helper function to initialize matrix.

This function is called by all the constructors and also by the resize() function. If either m or n is 0, then both m_ and n_ will be set to 0.

Precondition:
Mimpl_ has been resized to m*n elements.
Postcondition:
vimpl_ has been resized to <m elements.
All pointers of vimpl_ have been assigned to point in Mimpl_.
M_, m_ and n_ have been initialized correctly.
Parameters:
m Number of rows. Can be 0.
n Number of cols. Can be 0.

Definition at line 104 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
K_UINT_32 Kalman::KMatrix< T, BEG, DBG >::ncol (  )  const [inline]

Returns n_, the number of columns of the matrix.

Returns:
The number of columns in the matrix.

Definition at line 264 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
K_UINT_32 Kalman::KMatrix< T, BEG, DBG >::nrow (  )  const [inline]

Returns m_, the number of rows of the matrix.

Returns:
The number of rows in the matrix.

Definition at line 257 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
const T & Kalman::KMatrix< T, BEG, DBG >::operator() ( K_UINT_32  i,
K_UINT_32  j 
) const [inline]

Returns the element (i,j), const version.

Parameters:
i Row index of matrix element.
j Column index of matrix element.
Returns:
A const reference to the element (i,j).
Exceptions:
OutOfBoundError Thrown if i or j is out of matrix bounds and DBG == true.

Definition at line 228 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
T & Kalman::KMatrix< T, BEG, DBG >::operator() ( K_UINT_32  i,
K_UINT_32  j 
) [inline]

Returns the element (i,j).

Parameters:
i Row index of matrix element.
j Column index of matrix element.
Returns:
A reference to the element (i,j).
Exceptions:
OutOfBoundError Thrown if i or j is out of matrix bounds and DBG == true.

Definition at line 194 of file kmatrix_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
KMatrix< T, BEG, DBG > & Kalman::KMatrix< T, BEG, DBG >::operator= ( const KMatrix< T, BEG, DBG > &  M  )  [inline]

Copy assignment operator. Performs a deep copy.

Parameters:
M Matrix to copy.
Returns:
A reference to the assigned matrix.
Warning:
This function invalidates pointers inside the matrix.

Definition at line 306 of file kmatrix_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
KMatrix< T, BEG, DBG > & Kalman::KMatrix< T, BEG, DBG >::operator= ( const T &  a  )  [inline]

Assigns a copy of a to all elements of the matrix.

Parameters:
a Instance to copy to each element of matrix.
Returns:
A reference to the matrix.

Definition at line 290 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KMatrix< T, BEG, DBG >::put ( std::ostream &  os  )  const [inline]

Writes a matrix to a stream.

This function will send all the matrix elements to a stream, while considering the formatting constraints of the current matrix printing context.

Parameters:
os A reference to the output stream.
See also:
createKMatrixContext()
selectKMatrixContext()

Definition at line 423 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KMatrix< T, BEG, DBG >::resize ( K_UINT_32  m,
K_UINT_32  n 
) [inline]

Resizes the matrix. Resulting matrix contents are undefined.

Parameters:
m Number of rows in matrix. Can be 0.
n Number of columns in matrix. Can be 0.
Warning:
This function may invalidates pointers inside the matrix.
Note:
Resizing to a smaller size does not free any memory. To do so, one can swap the matrix to shrink with a temporary copy of itself : KMatrix<T, BEG, DBG>(M).swap(M).
If either m or n is 0, then both the number of rows and the number of columns will be set to 0.

Definition at line 277 of file kmatrix_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KMatrix< T, BEG, DBG >::swap ( KMatrix< T, BEG, DBG > &  M  )  [inline]

Constant-time swap function between two matrices.

This function is fast, since it exchanges pointers to underlying implementation without copying any element.

Parameters:
M Matrix to swap.
Note:
No pointer is invalidated by this function. They still point to the same element, but in the other matrix.

Definition at line 332 of file kmatrix_impl.hpp.


Member Data Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
K_UINT_32 Kalman::KMatrix< T, BEG, DBG >::m_ [private]

Number of rows of matrix.

Definition at line 161 of file kmatrix.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
T** Kalman::KMatrix< T, BEG, DBG >::M_ [private]

Pointer to the start of vimpl_.

In fact, M_ is such that &M_[beg] == &vimpl_[0]. This means also that &M_[beg][beg] == &Mimpl_[0][0].

Warning:
M_[0] is not defined for beg != 0.

Definition at line 160 of file kmatrix.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
std::vector<T> Kalman::KMatrix< T, BEG, DBG >::Mimpl_ [private]

Underlying vector implementation.

Definition at line 152 of file kmatrix.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
K_UINT_32 Kalman::KMatrix< T, BEG, DBG >::n_ [private]

Number of columns of matrix.

Definition at line 162 of file kmatrix.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
std::vector<T*> Kalman::KMatrix< T, BEG, DBG >::vimpl_ [private]

Array of pointers to rows of Mimpl_.

In fact, vimpl_ is such that &vimpl_[i][beg] == &Mimpl_[i*n_].

Definition at line 151 of file kmatrix.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines


kfilter
Author(s): Vincent Zalzal, Sylvain Marleau, Richard Gourdeau
autogenerated on Wed Jul 23 04:33:42 2014