vector_LTI.cpp
Go to the documentation of this file.
1 // $Id$
2 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
3 
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 
20 #include "../config.h"
21 #ifdef __MATRIXWRAPPER_LTI__
22 
23 #include "vector_LTI.h"
24 
25 
26 using std::cout;
27 using std::endl;
28 
29 
30 // Constructors
31 MyColumnVector::ColumnVector() : ltiColumnVector() {}
32 MyColumnVector::ColumnVector(int num_rows) : ltiColumnVector(num_rows){}
33 MyColumnVector::ColumnVector(const MyColumnVector& a,
34  const MyColumnVector& b)
35  : ltiColumnVector(a.rows() + b.rows())
36 {
37  ltiColumnVector& opl = (*this);
38 
39  unsigned int i;
40 
41  // copy elements of a to opl
42  for (i=0; i< a.rows(); i++)
43  opl.at(i) = a(i+1);
44 
45  // copy elements of b to opl
46  for (i=0; i< b.rows(); i++)
47  opl.at(a.rows() + i) = b(i+1);
48 }
49 
50 // Create from matrix
51 MyColumnVector::ColumnVector(const MyMatrix &a)
52 : ltiColumnVector(a.rows())
53 {
54  assert(a.columns() == 1);
55 
56  // copy elements of a to opl
57  ltiColumnVector& opl = (*this);
58  for (unsigned int i=0; i< a.rows(); i++)
59  {
60  opl.at(i) = a(i+1,1);
61  }
62 }
63 
64 // Destructor
65 MyColumnVector::~ColumnVector(){}
66 
67 // Copy constructor
68 MyColumnVector::ColumnVector(const MyColumnVector& a) :
69  ltiColumnVector(a){}
70 MyColumnVector::ColumnVector(const ltiColumnVector & a) :
71  ltiColumnVector(a){}
72 
73 // Resizing
74 void MyColumnVector::resize(int num_rows)
75 {
76  ltiColumnVector & op1 = (*this);
77  op1.resize(num_rows);
78 }
79 
80 // Assign
81 void MyColumnVector::assign(int num_rows, double value)
82 {
83  BoostColumnVector & op1 = (*this);
84  op1.resize(num_rows);
85  for (unsigned int i=0; i<num_rows; i++)
86  op1(i+1) = value;
87 }
88 
89 // Number of Rows / Cols
90 unsigned int MyColumnVector::rows() const { return this->size();}
91 unsigned int MyColumnVector::columns() const { return 1;}
92 unsigned int MyColumnVector::capacity() const { return this->size();}
93 
95 MyColumnVector::vectorAdd(const MyColumnVector& v2) const
96 {
97  const MyColumnVector& v1 = *this;
98  MyColumnVector res(v1.rows() + v2.rows());
99 
100  for (unsigned int i=0; i<v1.rows(); i++)
101  res(i) = v1(i);
102 
103  for (unsigned int i=0; i<v2.rows(); i++)
104  res(v1.rows()+i) = v2(i);
105 
106  return res;
107 }
108 
109 const bool MyColumnVector::operator==(const MyColumnVector& a) const
110 {
111  const ltiColumnVector& op1 = *this;
112  const ltiColumnVector& op2 = a;
113  return (op1 == op2);
114 }
115 
116 
117 // Operators
118 MyColumnVector & MyColumnVector::operator+= (const MyColumnVector& a)
119 {
120  ltiColumnVector & op1 = (*this);
121  const ltiColumnVector & op2 = a;
122  op1 += op2;
123  return (MyColumnVector &) op1 ;
124 }
125 
126 MyColumnVector & MyColumnVector::operator-= (const MyColumnVector& a)
127 {
128  ltiColumnVector & op1 = (*this);
129  const ltiColumnVector & op2 = a;
130  op1 -= op2;
131  return (MyColumnVector &) op1 ;
132 }
133 
134 MyColumnVector MyColumnVector::operator+ (const MyColumnVector &a) const
135 {
136  ltiColumnVector op1(*this);
137  const ltiColumnVector & op2 = a;
138  ltiColumnVector result = (ltiColumnVector) (op1.add(op2));
139  return (MyColumnVector) result;
140 }
141 
142 MyColumnVector MyColumnVector::operator- (const MyColumnVector &a) const
143 {
144  ltiColumnVector op1(*this);
145  const ltiColumnVector & op2 = a;
146  ltiColumnVector result = (ltiColumnVector) (op1.subtract(op2));
147  return (MyColumnVector) result;
148 }
149 
150 
151 
152 MyColumnVector& MyColumnVector::operator+= (double a)
153 {
154  ltiColumnVector& op1 = *this;
155  op1 += a;
156  return (MyColumnVector&) op1;
157 }
158 
159 MyColumnVector& MyColumnVector::operator-= (double a)
160 {
161  ltiColumnVector& op1 = *this;
162  op1 -= a;
163  return (MyColumnVector&) op1;
164 }
165 
166 
167 MyColumnVector& MyColumnVector::operator*= (double a)
168 {
169  ltiColumnVector& op1 = *this;
170  op1 *= a;
171  return (MyColumnVector&) op1;
172 }
173 
174 MyColumnVector& MyColumnVector::operator/= (double a)
175 {
176  ltiColumnVector& op1 = *this;
177  op1 /= a;
178  return (MyColumnVector&) op1;
179 }
180 
181 
182 MyColumnVector MyColumnVector::operator+ (double a) const
183 {
184  ltiColumnVector op1(*this);
185  op1 += a;
186  return (MyColumnVector&) op1;
187 }
188 
189 
190 MyColumnVector MyColumnVector::operator- (double a) const
191 {
192  ltiColumnVector op1(*this);
193  op1 -= a;
194  return (MyColumnVector&) op1;
195 }
196 
197 MyColumnVector MyColumnVector::operator* (double a) const
198 {
199  ltiColumnVector op1(*this);
200  return (MyColumnVector) (op1.multiply(a));
201 }
202 
203 
204 MyColumnVector MyColumnVector::operator/ (double a) const
205 {
206  ltiColumnVector op1(*this);
207  return (MyColumnVector) (op1.divide(a));
208 }
209 
210 
211 
212 
213 
214 
215 
216 MyRowVector MyColumnVector::transpose() const
217 {
218  ltiRowVector transposedbase((*this));
219  return (MyRowVector) transposedbase;
220 }
221 
222 MyMatrix MyColumnVector::operator* (const MyRowVector &a) const
223 {
224  const ltiColumnVector& op1 = *this;
225  const ltiRowVector & op2 = a;
226  ltiMatrix result(op1.size(),op2.size());
227  result.outerProduct(op1,op2);
228  return (MyMatrix) result;
229 }
230 
231 MyColumnVector& MyColumnVector::operator=(const MyColumnVector &a)
232 {
233  // Both these implementations result in the same
234  ltiColumnVector * op1; const ltiColumnVector * op2;
235  op1 = this; op2 = &a;
236  *op1 = *op2;
237 
238  return *this;
239 }
240 
241 MyColumnVector& MyColumnVector::operator=(const double a)
242 {
243  // Both these implementations result in the same
244  ltiColumnVector * op1;
245  op1 = this;
246  (*op1).fill(a,0,(*op1).size());
247 
248  return *this;
249 }
250 
251 double &MyColumnVector::operator()(unsigned int i)
252 {
253  assert (i != 0);
254  //ltiColumnVector * op1;
255  //op1 = this;
256  return this->at(i-1);
257 }
258 
259 const double MyColumnVector::operator()(unsigned int i) const
260 {
261  assert (i != 0);
262  //ltiColumnVector op1(*this);
263  return this->at(i-1);
264 }
265 
266 
267 MyColumnVector MyColumnVector::sub(int j_start , int j_end) const
268 {
269  ltiColumnVector result(*this,j_start-1,j_end-1);
270  return (MyColumnVector) result;
271 }
272 
276 
277 // Constructors
278 MyRowVector::RowVector() : ltiRowVector() {}
279 MyRowVector::RowVector(int num_rows) : ltiRowVector(num_rows){}
280 
281 // Destructor
282 MyRowVector::~RowVector(){}
283 
284 // Copy constructor
285 MyRowVector::RowVector(const MyRowVector& a) : ltiRowVector(a){}
286 MyRowVector::RowVector(const ltiRowVector & a) : ltiRowVector(a){}
287 
288 // Number of Rows / Cols
289 unsigned int MyRowVector::rows() const { return 1;}
290 unsigned int MyRowVector::columns() const { return this->size();}
291 unsigned int MyRowVector::capacity() const { return this->size();}
292 
293 const bool MyRowVector::operator==(const MyRowVector& a) const
294 {
295  const ltiRowVector& op1 = *this;
296  const ltiRowVector& op2 = a;
297  return (op1 == op2);
298 }
299 
300 
301 // Operators
302 MyRowVector & MyRowVector::operator+= (const MyRowVector& a)
303 {
304  ltiRowVector & op1 = (*this);
305  const ltiRowVector & op2 = a;
306  op1 += op2;
307  return (MyRowVector &) op1 ;
308 }
309 
310 MyRowVector & MyRowVector::operator-= (const MyRowVector& a)
311 {
312  ltiRowVector & op1 = (*this);
313  const ltiRowVector & op2 = a;
314  op1 -= op2;
315  return (MyRowVector &) op1 ;
316 }
317 
318 MyRowVector MyRowVector::operator+ (const MyRowVector &a) const
319 {
320  ltiRowVector op1(*this);
321  const ltiRowVector & op2 = a;
322  ltiRowVector result = (ltiRowVector) (op1.add(op2));
323  return (MyRowVector) result;
324 }
325 
326 MyRowVector MyRowVector::operator- (const MyRowVector &a) const
327 {
328  ltiRowVector op1(*this);
329  const ltiRowVector & op2 = a;
330  ltiRowVector result = (ltiRowVector) (op1.subtract(op2));
331  return (MyRowVector) result;
332 }
333 
334 
335 
336 
337 
338 
339 MyRowVector& MyRowVector::operator+= (double a)
340 {
341  ltiRowVector& op1 = *this;
342  op1 += a;
343  return (MyRowVector&) op1;
344 }
345 
346 MyRowVector& MyRowVector::operator-= (double a)
347 {
348  ltiRowVector& op1 = *this;
349  op1 -= a;
350  return (MyRowVector&) op1;
351 }
352 
353 
354 MyRowVector& MyRowVector::operator*= (double a)
355 {
356  ltiRowVector& op1 = *this;
357  op1 *= a;
358  return (MyRowVector&) op1;
359 }
360 
361 MyRowVector& MyRowVector::operator/= (double a)
362 {
363  ltiRowVector& op1 = *this;
364  op1 /= a;
365  return (MyRowVector&) op1;
366 }
367 
368 
369 MyRowVector MyRowVector::operator+ (double a) const
370 {
371  ltiRowVector op1(*this);
372  op1 += a;
373  return (MyRowVector&) op1;
374 }
375 
376 
377 MyRowVector MyRowVector::operator- (double a) const
378 {
379  ltiRowVector op1(*this);
380  op1 -= a;
381  return (MyRowVector&) op1;
382 }
383 
384 MyRowVector MyRowVector::operator* (double a) const
385 {
386  ltiRowVector op1(*this);
387  return (MyRowVector) (op1.multiply(a));
388 }
389 
390 
391 MyRowVector MyRowVector::operator/ (double a) const
392 {
393  ltiRowVector op1(*this);
394  return (MyRowVector) (op1.divide(a));
395 }
396 
397 MyRowVector MyRowVector::operator*(const MyMatrix& a)
398 {
399  assert(this->columns() == a.rows());
400 
401  ltiRowVector & op1 = (*this);
402  const ltiMatrix & op2 = a;
403  ltiRowVector result = op2.leftMultiply(op1);
404  return (MyRowVector) result;
405 }
406 
407 
408 double MyRowVector::operator*(const MyColumnVector& a) const
409 {
410  assert(this->columns() == a.rows());
411 
412  const ltiRowVector & op1 = (*this);
413  const ltiColumnVector & op2 = a;
414  double result=op1.dot(op2);
415  return result;
416 }
417 
418 MyRowVector& MyRowVector::operator=(const MyRowVector &a)
419 {
420  // Both these implementations result in the same
421  ltiRowVector * op1;
422  const ltiRowVector * op2;
423  op1 = this;
424  op2 = &a;
425  *op1 = *op2;
426 
427  return *this;
428 }
429 
430 
431 MyRowVector& MyRowVector::operator=(const double a)
432 {
433  // Both these implementations result in the same
434  ltiRowVector * op1;
435  op1 = this;
436  (*op1).fill(a,0,(*op1).size());
437 
438  return *this;
439 }
440 
441 
442 MyColumnVector MyRowVector::transpose() const
443 {
444  ltiColumnVector transposedbase((*this));
445  return (MyColumnVector) transposedbase;
446 }
447 
448 
449 double &MyRowVector::operator()(unsigned int i)
450 {
451  assert (i != 0);
452  ltiRowVector * op1;
453  op1 = this;
454  return op1->at(i-1);
455 }
456 
457 const double MyRowVector::operator()(unsigned int i) const
458 {
459  assert (i != 0);
460  ltiRowVector op1(*this);
461  return ((op1.at(i-1)));
462 }
463 
464 
465 
466 MyRowVector MyRowVector::sub(int j_start , int j_end) const
467 {
468  ltiRowVector result(*this,j_start-1,j_end-1);
469  return (MyRowVector) result;
470 }
471 
472 // Resizing
473 void MyRowVector::resize(int num_cols)
474 {
475  ltiRowVector & op1 = (*this);
476  op1.resize(num_cols);
477 }
478 
479 // Assign
480 void MyRowVector::assign(int num_columns, double value)
481 {
482  ltiRowVector & op1 = (*this);
483  op1.resize(num_columns);
484  for (unsigned int i=0; i<num_columns; i++)
485  op1(i+1) = value;
486 }
487 
488 
490 MyRowVector::vectorAdd(const MyRowVector& v2) const
491 {
492  const MyRowVector& v1 = *this;
493  MyRowVector res(v1.columns() + v2.columns());
494 
495  for (unsigned int i=0; i<v1.columns(); i++)
496  res(i) = v1(i);
497 
498  for (unsigned int i=0; i<v2.columns(); i++)
499  res(v1.columns()+i) = v2(i);
500 
501  return res;
502 }
503 
504 #endif
#define MyMatrix
#define MyRowVector
#define MyColumnVector


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Mon Jun 10 2019 12:48:00