All Classes Namespaces Functions Typedefs Enumerations Pages
fixed_vector.h
1 /* Copyright (C) 2003-2005 Martin Förg
2 
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact:
18  * martin.o.foerg@googlemail.com
19  *
20  */
21 
22 #ifndef fixed_vector_h
23 #define fixed_vector_h
24 
25 #include "fixed_general_matrix.h"
26 #include <vector>
27 #include <cstring>
28 
29 namespace fmatvec {
30 
39  template <int M, class AT>
40  class Vector<Fixed<M>,AT> : public Matrix<General,Fixed<M>,Fixed<1>,AT> {
41  using Matrix<General,Fixed<M>,Fixed<1>,AT>::ele;
42 
43  public:
44 
46 
47  protected:
48 
49  template<class Row> inline void deepCopy(const Vector<Row,AT> &x);
50 
52 
53  public:
54 
55 // template<class Ini=All<AT> >
56 // Vector(Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<1>,AT>(ini) { }
57 // template<class Ini=All<AT> >
58 // Vector(int m, Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<1>,AT>(ini) { }
59 
60  Vector(Noinit ini) : Matrix<General,Fixed<M>,Fixed<1>,AT>(ini) { }
61  Vector(Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<M>,Fixed<1>,AT>(ini,a) { }
62  Vector(int m, Noinit ini) : Matrix<General,Fixed<M>,Fixed<1>,AT>(ini) { }
63  Vector(int m, Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<M>,Fixed<1>,AT>(ini,a) { }
64 
77  Vector(const char *str) : Matrix<General,Fixed<M>,Fixed<1>,AT>(str) {
78  }
79 
87  template<class Row>
88  Vector(const Vector<Row,AT> &x) : Matrix<General,Fixed<M>,Fixed<1>,AT>(x) {
89  }
90 
95  template<class Type, class Row, class Col>
96  explicit Vector(const Matrix<Type,Row,Col,AT> &A) : Matrix<General,Fixed<M>,Fixed<1>,AT>(A) {
97  }
98 
99  template <class Row>
100  inline Vector<Fixed<M>,AT>& operator=(const Vector<Row,AT> &x);
101 
112  AT& operator()(int i) {
113 
114 #ifndef FMATVEC_NO_BOUNDS_CHECK
115  assert(i>=0);
116  assert(i<M);
117 #endif
118 
119  return e(i);
120  };
121 
126  const AT& operator()(int i) const {
127 
128 #ifndef FMATVEC_NO_BOUNDS_CHECK
129  assert(i>=0);
130  assert(i<M);
131 #endif
132 
133  return e(i);
134  };
135 
136  AT& e(int i) {
137  return ele[i][0];
138  };
139 
144  const AT& e(int i) const {
145  return ele[i][0];
146  };
147 
155  inline Vector<Fixed<M>,AT>& init(const AT& a=0);
156  inline Vector<Fixed<M>,AT>& init(Init, const AT& a=0) { return init(a); }
157  inline Vector<Fixed<M>,AT>& init(Noinit, const AT& a=0) { return *this; }
158 
163  int size() const {return M;};
164 
171  int inc() const {return 1;};
172 
173  template <int M1, int M2>
174  inline const Vector<Fixed<M2-M1+1>,AT> operator()(const Range<Fixed<M1>,Fixed<M2> > &I) const;
175 
176  using Matrix<General,Fixed<M>,Fixed<1>,AT>::operator();
177 
182  inline operator std::vector<AT>();
183 
188  inline Vector(std::vector<AT> v);
189 
193  inline const RowVector<Fixed<M>,AT> T() const;
194 
198  template<class Type, class Row, class Col>
199  inline void set(const Range<Var,Var> &I, const Matrix<Type,Row,Col,AT> &A);
200 
201  };
202 
203  template <int M, class AT>
204  inline Vector<Fixed<M>,AT>& Vector<Fixed<M>,AT>::init(const AT &val) {
205  for(int i=0; i<M; i++)
206  e(i) = val;
207  return *this;
208  }
209 
210  template <int M, class AT> template <int M1, int M2>
211  inline const Vector<Fixed<M2-M1+1>,AT> Vector<Fixed<M>,AT>::operator()(const Range<Fixed<M1>,Fixed<M2> > &I) const {
212 #ifndef FMATVEC_NO_BOUNDS_CHECK
213  assert(M2<M);
214 #endif
215  Vector<Fixed<M2-M1+1>,AT> x(NONINIT);
216 
217  for(int i=0; i<x.size(); i++)
218  x.e(i) = e(M1+i);
219 
220  return x;
221  }
222 
223  template <int M, class AT> template <class Row>
224  inline Vector<Fixed<M>,AT>& Vector<Fixed<M>,AT>::operator=(const Vector<Row,AT> &x) {
225 
226 #ifndef FMATVEC_NO_SIZE_CHECK
227  assert(x.size() == M);
228 #endif
229 
230  deepCopy(x);
231 
232  return *this;
233  }
234 
235  template <int M, class AT>
236  inline const RowVector<Fixed<M>,AT> Vector<Fixed<M>,AT>::T() const {
237  RowVector<Fixed<M>,AT> x(NONINIT);
238  for(int i=0; i<M; i++)
239  x.e(i) = e(i);
240  return x;
241  }
242 
243  template <int M, class AT>
244  inline Vector<Fixed<M>,AT>::operator std::vector<AT>() {
245  std::vector<AT> ret(size());
246  if(size()>0) memcpy(&ret[0], &operator()(0), sizeof(AT)*size());
247  return ret;
248  }
249 
250  template <int M, class AT>
251  inline Vector<Fixed<M>,AT>::Vector(std::vector<AT> v) : Matrix<General,Fixed<M>,Fixed<1>,AT>() {
252  if(size()>0) memcpy(&operator()(0), &v[0], sizeof(AT)*size());
253  }
254 
256 
257  template <int M, class AT> template<class Row>
258  inline void Vector<Fixed<M>,AT>::deepCopy(const Vector<Row,AT> &x) {
259  for(int i=0; i<M; i++)
260  e(i) = x.e(i);
261  }
262 
264 
265  template<int M, class AT> template<class Type, class Row, class Col>
266  inline void Vector<Fixed<M>,AT>::set(const Range<Var,Var> &I, const Matrix<Type,Row,Col,AT> &A) {
267  Matrix<General,Fixed<M>,Fixed<1>,AT>::set(I, Index(0,0), A);
268  }
269 
270 }
271 
272 #endif
Definition: types.h:68
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
Definition: matrix.h:39
Definition: matrix.h:218
Vector(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_vector.h:96
Vector(const Vector< Row, AT > &x)
Copy Constructor.
Definition: fixed_vector.h:88
Definition: matrix.h:215
This is an index class for creating submatrices.
Definition: range.h:35
const AT & e(int i) const
Element operator.
Definition: fixed_vector.h:144
int size() const
Size.
Definition: fixed_vector.h:163
This is an index class for creating submatrices.
Definition: index.h:34
int inc() const
Increment.
Definition: fixed_vector.h:171
Definition: matrix.h:38
Basic shape class for matrices.
Definition: types.h:100
AT & operator()(int i)
Element operator.
Definition: fixed_vector.h:112
const AT & operator()(int i) const
Element operator.
Definition: fixed_vector.h:126
Vector(const char *str)
String Constructor.
Definition: fixed_vector.h:77
This is an index class for creating submatrices.
Definition: range.h:44

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML