All Classes Namespaces Functions Variables Typedefs Enumerations Pages
fixed_row_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_row_vector_h
23 #define fixed_row_vector_h
24 
25 #include "fixed_general_matrix.h"
26 #include <stdexcept>
27 
28 namespace fmatvec {
29 
38  template <int N, class AT> class RowVector<Fixed<N>,AT> : public Matrix<General,Fixed<1>,Fixed<N>,AT> {
39 
40  using Matrix<General,Fixed<1>,Fixed<N>,AT>::ele;
41 
42  public:
43 
44  typedef AT AtomicType;
45 
47 
48  protected:
49 
50  template<class Col> inline void deepCopy(const RowVector<Col,AT> &x);
51 
53 
54  public:
55 
56 // template<class Ini=All<AT> >
57 // RowVector(Ini ini=All<AT>()) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini) { }
58 // template<class Ini=All<AT> >
59 // RowVector(int n, Ini ini=All<AT>()) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini) { }
60 
62  RowVector(Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini,a) { }
63  RowVector(int n, Noinit ini) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini) { }
64  RowVector(int n, Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini,a) { }
65 
78  RowVector(const char *str) : Matrix<General,Fixed<1>,Fixed<N>,AT>(str) {
79  }
80 
85  template<class Col>
86  RowVector(const RowVector<Col,AT> &A) : Matrix<General,Fixed<1>,Fixed<N>,AT>(A) {
87  }
88 
93  template<class Type, class Row, class Col>
94  explicit RowVector(const Matrix<Type,Row,Col,AT> &A) : Matrix<General,Fixed<1>,Fixed<N>,AT>(A) {
95  }
96 
107  AT& operator()(int i) {
108 #ifndef FMATVEC_NO_BOUNDS_CHECK
109  assert(i>=0);
110  assert(i<N);
111 #endif
112  return e(i);
113  };
114 
119  const AT& operator()(int i) const {
120 #ifndef FMATVEC_NO_BOUNDS_CHECK
121  assert(i>=0);
122  assert(i<N);
123 #endif
124  return e(i);
125  };
126 
127  AT& e(int i) {
128  return ele[0][i];
129  };
130 
135  const AT& e(int i) const {
136  return ele[0][i];
137  };
138 
146  inline RowVector<Fixed<N>,AT>& init(const AT &a=0);
147  inline RowVector<Fixed<N>,AT>& init(Init, const AT &a=0) { return init(a); }
148  inline RowVector<Fixed<N>,AT>& init(Noinit, const AT &a=0) { return *this; }
149 
154  int size() const {return N;};
155 
158  void resize(int n) {
159  if(n!=N)
160  throw std::runtime_error("A fixed row vector cannot be resized.");
161  }
162 
169  int inc() const {return 1;};
170 
171  using Matrix<General,Fixed<1>,Fixed<N>,AT>::operator();
172 
173  inline const Vector<Fixed<N>,AT> T() const;
174  };
175 
176  template <int N, class AT>
177  inline RowVector<Fixed<N>,AT>& RowVector<Fixed<N>,AT>::init(const AT &val) {
178  for(int i=0; i<N; i++)
179  e(i) = val;
180  return *this;
181  }
182 
183  template <int N, class AT>
184  inline const Vector<Fixed<N>,AT> RowVector<Fixed<N>,AT>::T() const {
185  Vector<Fixed<N>,AT> x(NONINIT);
186  for(int i=0; i<N; i++)
187  x.e(i) = e(i);
188  return x;
189  }
190 
192 
193  template <int N, class AT> template <class Col>
194  inline void RowVector<Fixed<N>,AT>::deepCopy(const RowVector<Col,AT> &x) {
195  for(int i=0; i<N; i++)
196  e(i) = x.e(i);
197  }
198 
200 
201 }
202 #endif
Definition: fmatvec.h:38
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Definition: matrix.h:39
Definition: fmatvec.h:50
RowVector(const RowVector< Col, AT > &A)
Copy Constructor.
Definition: fixed_row_vector.h:86
Definition: fmatvec.h:47
int size() const
Size.
Definition: fixed_row_vector.h:154
RowVector(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_row_vector.h:94
void resize(int n)
Definition: fixed_row_vector.h:158
Definition: matrix.h:38
int inc() const
Increment.
Definition: fixed_row_vector.h:169
Basic shape class for matrices.
Definition: types.h:100
AT & operator()(int i)
Element operator.
Definition: fixed_row_vector.h:107
const AT & operator()(int i) const
Element operator.
Definition: fixed_row_vector.h:119
const AT & e(int i) const
Element operator.
Definition: fixed_row_vector.h:135
RowVector(const char *str)
String Constructor.
Definition: fixed_row_vector.h:78

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML