All Classes Namespaces Functions Typedefs Enumerations Pages
var_row_vector.h
1 /* Copyright (C) 2003-2012 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 var_row_vector_h
23 #define var_row_vector_h
24 
25 #include "var_general_matrix.h"
26 #include <vector>
27 #include <cstring>
28 
29 namespace fmatvec {
30 
39  template <class AT> class RowVector<Var,AT> : public Matrix<General,Fixed<1>,Var,AT> {
40  using Matrix<General,Fixed<1>,Var,AT>::N;
41  using Matrix<General,Fixed<1>,Var,AT>::ele;
42 
43  public:
44 
46 
47  protected:
48 
49  template<class Row> inline void deepCopy(const RowVector<Row,AT> &x);
50 
52 
53  public:
54 
59  RowVector() : Matrix<General,Fixed<1>,Var,AT>() {
60  }
61 
62 // template<class Ini=All<AT> >
63 // RowVector(int n, Ini ini=All<AT>()) : Matrix<General,Fixed<1>,Var,AT>(n,ini) { }
64 
65  RowVector(int n, Noinit ini) : Matrix<General,Fixed<1>,Var,AT>(n,ini) { }
66  RowVector(int n, Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<1>,Var,AT>(n,ini,a) { }
67 
80  RowVector(const char *str) : Matrix<General,Fixed<1>,Var,AT>(str) {
81  }
82 
91  }
92 
93  template<class Row>
94  RowVector(const RowVector<Row,AT> &x) : Matrix<General,Fixed<1>,Var,AT>(x) {
95  }
96 
97  template<class Type, class Row, class Col>
98  explicit RowVector(const Matrix<Type,Row,Col,AT> &A) : Matrix<General,Fixed<1>,Var,AT>(A) {
99  }
100 
101  RowVector<Var,AT>& resize() {
102  Matrix<General,Fixed<1>,Var,AT>::resize();
103  return *this;
104  }
105 
106  RowVector<Var,AT>& resize(int n, Noinit) {
107  Matrix<General,Fixed<1>,Var,AT>::resize(n,Noinit());
108  return *this;
109  }
110 
111  RowVector<Var,AT>& resize(int n, Init ini=INIT, const AT &a=0) {
112  Matrix<General,Fixed<1>,Var,AT>::resize(n,ini,a);
113  return *this;
114  }
115 
122  inline RowVector<Var,AT>& operator=(const RowVector<Var,AT> &x);
123 
124  template <class Row>
125  inline RowVector<Var,AT>& operator=(const RowVector<Row,AT> &x);
126 
133  template <class Row>
134  inline RowVector<Var,AT>& operator<<(const RowVector<Row,AT> &x);
135 
146  AT& operator()(int i) {
147 
148 #ifndef FMATVEC_NO_BOUNDS_CHECK
149  assert(i>=0);
150  assert(i<N);
151 #endif
152 
153  return e(i);
154  };
155 
160  const AT& operator()(int i) const {
161 
162 #ifndef FMATVEC_NO_BOUNDS_CHECK
163  assert(i>=0);
164  assert(i<N);
165 #endif
166 
167  return e(i);
168  };
169 
170  AT& e(int i) {
171  return ele[i];
172  };
173 
178  const AT& e(int i) const {
179  return ele[i];
180  };
181 
189  inline RowVector<Var,AT>& init(const AT& a=0);
190  inline RowVector<Var,AT>& init(Init, const AT &a=0) { return init(a); }
191  inline RowVector<Var,AT>& init(Noinit, const AT &a=0) { return *this; }
192 
197  int size() const {return N;};
198 
205  int inc() const {return 1;};
206 
207  using Matrix<General,Fixed<1>,Var,AT>::operator();
208 
213  inline operator std::vector<AT>();
214 
219  inline RowVector(std::vector<AT> v);
220 
221  inline const Vector<Var,AT> T() const;
222 
223  template <class Row>
224  inline void set(const Range<Var,Var> &I, const RowVector<Row,AT> &x);
225  };
226 
227  template <class AT>
229  for(int i=0; i<N; i++)
230  e(i) = val;
231  return *this;
232  }
233 
234  template <class AT>
236 
237  if(!ele) {
238  delete[] ele;
239  N = x.size();
240  ele = new AT[N];
241  } else {
242 #ifndef FMATVEC_NO_SIZE_CHECK
243  assert(N == x.size());
244 #endif
245  }
246 
247  deepCopy(x);
248 
249  return *this;
250  }
251 
252  template <class AT> template<class Row>
254 
255  if(!ele) {
256  delete[] ele;
257  N = x.size();
258  ele = new AT[N];
259  } else {
260 #ifndef FMATVEC_NO_SIZE_CHECK
261  assert(N == x.size());
262 #endif
263  }
264 
265  deepCopy(x);
266 
267  return *this;
268  }
269 
270  template <class AT> template<class Row>
272 
273  if(N!=x.size()) {
274  delete[] ele;
275  N = x.size();
276  ele = new AT[N];
277  }
278 
279  deepCopy(x);
280 
281  return *this;
282  }
283 
284  template <class AT>
285  inline const Vector<Var,AT> RowVector<Var,AT>::T() const {
286  Vector<Var,AT> x(N,NONINIT);
287  for(int i=0; i<N; i++)
288  x.e(i) = e(i);
289  return x;
290  }
291 
292  template <class AT>
293  inline RowVector<Var,AT>::operator std::vector<AT>() {
294  std::vector<AT> ret(size());
295  if(size()>0) memcpy(&ret[0], &operator()(0), sizeof(AT)*size());
296  return ret;
297  }
298 
299  template <class AT>
300  inline RowVector<Var,AT>::RowVector(std::vector<AT> v) : Matrix<General,Fixed<1>,Var,AT>(v.size(),1) {
301  if(size()>0) memcpy(&operator()(0), &v[0], sizeof(AT)*size());
302  }
303 
304  template <class AT> template <class Row>
305  inline void RowVector<Var,AT>::set(const Range<Var,Var> &I, const RowVector<Row,AT> &x) {
306 #ifndef FMATVEC_NO_BOUNDS_CHECK
307  assert(I.end()<size());
308  assert(I.size()==x.size());
309 #endif
310 
311  for(int i=I.start(), ii=0; i<=I.end(); i++, ii++)
312  e(i) = x.e(ii);
313  }
314 
316 
317  template <class AT> template <class Row>
318  inline void RowVector<Var,AT>::deepCopy(const RowVector<Row,AT> &x) {
319  for(int i=0; i<N; i++)
320  e(i) = x.e(i);
321  }
322 
324 
325 }
326 
327 #endif
const AT & operator()(int i) const
Element operator.
Definition: var_row_vector.h:160
Definition: types.h:68
RowVector(const char *str)
String Constructor.
Definition: var_row_vector.h:80
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
RowVector()
Standard constructor.
Definition: var_row_vector.h:59
This is a vector class of general shape in dense storage format.
Definition: var_vector.h:39
AT & operator()(int i)
Element operator.
Definition: var_row_vector.h:146
Definition: matrix.h:39
Definition: types.h:65
Definition: matrix.h:218
RowVector(const RowVector< Var, AT > &x)
Copy Constructor.
Definition: var_row_vector.h:90
int size() const
Size.
Definition: range.h:101
Definition: matrix.h:38
int size() const
Size.
Definition: var_row_vector.h:197
Basic shape class for matrices.
Definition: types.h:100
const AT & e(int i) const
Element operator.
Definition: var_row_vector.h:178
int end() const
Last element.
Definition: range.h:95
int inc() const
Increment.
Definition: var_row_vector.h:205
This is an index class for creating submatrices.
Definition: range.h:44
This is a vector class of general shape in dense storage format.
Definition: var_row_vector.h:39
int start() const
First element.
Definition: range.h:89

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML