kmatrix.hpp
Go to the documentation of this file.
1 // This file is part of kfilter.
2 // kfilter is a C++ variable-dimension extended kalman filter library.
3 //
4 // Copyright (C) 2004 Vincent Zalzal, Sylvain Marleau
5 // Copyright (C) 2001, 2004 Richard Gourdeau
6 // Copyright (C) 2004 GRPR and DGE's Automation sector
7 // �cole Polytechnique de Montr�al
8 //
9 // Code adapted from algorithms presented in :
10 // Bierman, G. J. "Factorization Methods for Discrete Sequential
11 // Estimation", Academic Press, 1977.
12 //
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
17 //
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 
27 #ifndef KMATRIX_HPP
28 #define KMATRIX_HPP
29 
32 
33 #include <vector>
34 #include <string>
35 #include <iostream>
36 
37 #include <kfilter/ktypes.hpp>
38 
39 namespace Kalman {
40 
42 
71  template<typename T, K_UINT_32 BEG, bool DBG>
72  class KMatrix {
73  public:
74 
75  typedef T type;
76 
77  enum { beg = BEG
78  };
79 
81 
82 
84  inline KMatrix();
85 
87  inline KMatrix(K_UINT_32 m, K_UINT_32 n);
88 
90  inline KMatrix(K_UINT_32 m, K_UINT_32 n, const T& a);
91 
93  inline KMatrix(K_UINT_32 m, K_UINT_32 n, const T* v);
94 
96  inline KMatrix(const KMatrix& M);
97 
99  inline ~KMatrix();
100 
102 
104 
105 
107  inline T& operator()(K_UINT_32 i, K_UINT_32 j);
108 
110  inline const T& operator()(K_UINT_32 i, K_UINT_32 j) const;
111 
113  inline K_UINT_32 nrow() const;
114 
116  inline K_UINT_32 ncol() const;
117 
119 
121  inline void resize(K_UINT_32 m, K_UINT_32 n);
122 
124  inline KMatrix& operator=(const T& a);
125 
127  inline KMatrix& operator=(const KMatrix& M);
128 
130  inline void assign(K_UINT_32 m, K_UINT_32 n, const T* v);
131 
133  inline void swap(KMatrix& M);
134 
136 
137 
139  inline void get(std::istream& is);
140 
142  inline void put(std::ostream& os) const;
143 
145 
146  private:
148 
151  std::vector<T*> vimpl_;
152  std::vector<T> Mimpl_;
153 
155 
160  T** M_;
163 
165  inline void init(K_UINT_32 m, K_UINT_32 n);
166  };
167 
169  template<typename T, K_UINT_32 BEG, bool DBG>
170  inline std::istream& operator>>(std::istream& is,
172 
174  template<typename T, K_UINT_32 BEG, bool DBG>
175  inline std::ostream& operator<<(std::ostream& os,
176  const KMatrix<T, BEG, DBG>& M);
177 
179  typedef unsigned short KMatrixContext;
180 
183 
185  KMatrixContext createKMatrixContext(std::string elemDelim = " ",
186  std::string rowDelim = "\n",
187  std::string startDelim = "",
188  std::string endDelim = "",
189  unsigned prec = 4);
190 
193 
194 }
195 
196 #include <kfilter/kmatrix_impl.hpp>
197 
198 #endif
K_UINT_32 nrow() const
Returns m_, the number of rows of the matrix.
void swap(KMatrix &M)
Constant-time swap function between two matrices.
KMatrix()
Default constructor. Creates an empty matrix.
Contains the implementation of the KMatrix template class.
K_UINT_32 n_
Number of columns of matrix.
Definition: kmatrix.hpp:162
unsigned short KMatrixContext
Handle type to a matrix printing context.
Definition: kmatrix.hpp:179
KMatrix & operator=(const T &a)
Assigns a copy of a to all elements of the matrix.
T type
Type of objects contained in the matrix.
Definition: kmatrix.hpp:75
KMatrixContext createKMatrixContext(std::string elemDelim=" ", std::string rowDelim="\n", std::string startDelim="", std::string endDelim="", unsigned prec=4)
Creates a matrix printing context.
Definition: kstatics.cpp:144
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.
KMatrixContext DEFAULT_MATRIX_CONTEXT
Default matrix printing context object.
Definition: kstatics.cpp:119
void init(K_UINT_32 m, K_UINT_32 n)
Helper function to initialize matrix.
std::vector< T * > vimpl_
Array of pointers to rows of Mimpl_.
Definition: kmatrix.hpp:151
Starting index of matrix, either 0 or 1.
Definition: kmatrix.hpp:77
K_UINT_32 m_
Number of rows of matrix.
Definition: kmatrix.hpp:161
unsigned long int K_UINT_32
Unsigned 32-bits integral type.
Definition: ktypes.hpp:68
T & operator()(K_UINT_32 i, K_UINT_32 j)
Returns the element (i,j).
Contains type definitions specific to each platform.
void resize(K_UINT_32 m, K_UINT_32 n)
Resizes the matrix. Resulting matrix contents are undefined.
Minimalist matrix template class.
Definition: kmatrix.hpp:72
std::ostream & operator<<(std::ostream &os, const KMatrix< T, BEG, DBG > &M)
Writes a matrix to a stream.
void put(std::ostream &os) const
Writes a matrix to a stream.
K_UINT_32 ncol() const
Returns n_, the number of columns of the matrix.
std::vector< T > Mimpl_
Underlying vector implementation.
Definition: kmatrix.hpp:152
KMatrixContext selectKMatrixContext(KMatrixContext c)
Selects a matrix printing context as the current context.
Definition: kstatics.cpp:164
std::istream & operator>>(std::istream &is, KMatrix< T, BEG, DBG > &M)
Reads a matrix from a stream.
T ** M_
Pointer to the start of vimpl_.
Definition: kmatrix.hpp:160
~KMatrix()
Destructor.


kfilter
Author(s): Jorge Almeida, Vincent Zalzal, Sylvain Marleau, Richard Gourdeau
autogenerated on Mon Mar 2 2015 01:31:45