vector.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 #ifndef ACADO_TOOLKIT_VECTOR_HPP
36 #define ACADO_TOOLKIT_VECTOR_HPP
37 
38 #include <complex>
41 
43 
46 {
50 };
51 
53 template<typename T>
54 class GenericVector : public Eigen::Matrix<T, Eigen::Dynamic, 1>
55 {
56 public:
57 
65 
67  template<typename OtherDerived>
68  inline GenericVector(const Eigen::MatrixBase<OtherDerived>& other) : Base( other ) {}
69 
71  template<typename OtherDerived>
72  inline GenericVector(const Eigen::ReturnByValue<OtherDerived>& other) : Base( other ) {}
73 
75  template<typename OtherDerived>
76  inline GenericVector(const Eigen::EigenBase<OtherDerived>& other) : Base( other ) {}
77 
86  GenericVector() : Base() {}
87 
89  GenericVector( unsigned _dim ) : Base( _dim ) { Base::setZero(); }
90 
92  GenericVector( unsigned _dim,
93  const T* const _values
94  )
95  : Base( _dim )
96  { std::copy(_values, _values + _dim, Base::data()); }
97 
99  GenericVector( std::vector< T > _values
100  )
101  : Base( _values.size() )
102  { std::copy(_values.begin(), _values.end(), Base::data()); }
103 
107  virtual ~GenericVector()
108  {}
109 
111  bool operator==(const GenericVector& _arg) const
112  {
113  if (Base::rows() != _arg.rows())
114  return false;
115  return Base::isApprox(_arg, EQUALITY_EPS);
116  }
117 
119  bool operator!=(const GenericVector& _arg) const
120  {
121  return (operator==( _arg ) == false);
122  }
123 
124  bool operator<=(const GenericVector& _arg) const
125  {
126  if (Base::rows() != _arg.rows())
127  return false;
128  for (unsigned el = 0; el < Base::rows(); ++el)
129  if (Base::data()[ el ] > _arg.data()[ el ])
130  return false;
131  return true;
132  }
133 
134  bool operator>=(const GenericVector& _arg) const
135  {
136  if (Base::rows() != _arg.rows())
137  return false;
138  for (unsigned el = 0; el < Base::rows(); ++el)
139  if (Base::data()[ el ] < _arg.data()[ el ])
140  return false;
141  return true;
142  }
143 
144  bool operator>(const GenericVector& _arg) const
145  {
146  return operator<=( _arg ) == false;
147  }
148 
149  bool operator<(const GenericVector& _arg) const
150  {
151  return operator>=( _arg ) == false;
152  }
153 
155  void init( unsigned _dim = 0
156  )
157  { Base::_set(GenericVector< T >( _dim )); }
158 
160  void setAll( const T& _value)
161  { Base::setConstant( _value ); }
162 
164  GenericVector& append( const GenericVector& _arg
165  );
166 
168  GenericVector& setUnitVector( unsigned _idx
169  );
170 
172  unsigned getDim( ) const
173  { return Base::rows(); }
174 
176  bool isEmpty( ) const
177  { return Base::rows() == 0; }
178 
180  T getMax( ) const
181  { return Base::maxCoeff(); }
182 
184  T getMin( ) const
185  { return Base::minCoeff(); }
186 
188  T getMean( ) const
189  { return Base::mean(); }
190 
193  { return Base::cwiseAbs(); }
194 
199  T getNorm( VectorNorm _norm
200  ) const;
201 
207  T getNorm( VectorNorm _norm,
208  const GenericVector& _scale
209  ) const;
210 
227  virtual returnValue print( std::ostream& stream = std::cout,
228  const std::string& name = DEFAULT_LABEL,
229  const std::string& startString = DEFAULT_START_STRING,
230  const std::string& endString = DEFAULT_END_STRING,
231  uint width = DEFAULT_WIDTH,
233  const std::string& colSeparator = DEFAULT_COL_SEPARATOR,
234  const std::string& rowSeparator = DEFAULT_ROW_SEPARATOR
235  ) const;
236 
253  virtual returnValue print( const std::string& filename,
254  const std::string& name = DEFAULT_LABEL,
255  const std::string& startString = DEFAULT_START_STRING,
256  const std::string& endString = DEFAULT_END_STRING,
257  uint width = DEFAULT_WIDTH,
259  const std::string& colSeparator = DEFAULT_COL_SEPARATOR,
260  const std::string& rowSeparator = DEFAULT_ROW_SEPARATOR
261  ) const;
262 
274  virtual returnValue print( std::ostream& stream,
275  const std::string& name,
276  PrintScheme printScheme
277  ) const;
278 
290  virtual returnValue print( const std::string& filename,
291  const std::string& name,
292  PrintScheme printScheme
293  ) const;
294 
296  virtual returnValue read( std::istream& stream
297  );
298 
300  virtual returnValue read( const std::string& filename
301  );
302 };
303 
305 template<typename T>
306 std::ostream& operator<<( std::ostream& _stream,
307  const GenericVector< T >& _arg
308  )
309 {
310  if (_arg.print( _stream ) != SUCCESSFUL_RETURN)
311  ACADOERRORTEXT(RET_INVALID_ARGUMENTS, "Cannot write to output stream.");
312 
313  return _stream;
314 }
315 
317 template<typename T>
318 std::istream& operator>>( std::istream& _stream,
319  GenericVector< T >& _arg
320 )
321 {
322  if (_arg.read( _stream ) != SUCCESSFUL_RETURN )
323  ACADOERRORTEXT(RET_INVALID_ARGUMENTS, "Cannot read from input stream.");
324 
325  return _stream;
326 }
327 
334 
337 
339 
340 #endif // ACADO_TOOLKIT_VECTOR_HPP
const char DEFAULT_END_STRING[4]
T getMax() const
Definition: vector.hpp:180
T getMin() const
Definition: vector.hpp:184
GenericVector< bool > BVector
Definition: vector.hpp:333
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
bool operator>(const GenericVector &_arg) const
Definition: vector.hpp:144
const uint DEFAULT_PRECISION
void init(unsigned _dim=0)
Definition: vector.hpp:155
Allows to pass back messages to the calling function.
const char DEFAULT_COL_SEPARATOR[2]
GenericVector(const Eigen::MatrixBase< OtherDerived > &other)
Definition: vector.hpp:68
GenericVector & setUnitVector(unsigned _idx)
Definition: vector.cpp:55
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > cwiseAbs() const
#define CLOSE_NAMESPACE_ACADO
const char DEFAULT_START_STRING[3]
bool isEmpty() const
Definition: vector.hpp:176
EIGEN_STRONG_INLINE Index rows() const
GenericVector(unsigned _dim)
Definition: vector.hpp:89
static const DVector emptyConstVector
Definition: vector.hpp:336
T getMean() const
Definition: vector.hpp:188
bool isApprox(const Scalar &x, const Scalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
VectorNorm
Definition: vector.hpp:45
GenericVector(unsigned _dim, const T *const _values)
Definition: vector.hpp:92
unsigned getDim() const
Definition: vector.hpp:172
bool operator==(const GenericVector &_arg) const
Definition: vector.hpp:111
std::istream & operator>>(std::istream &_stream, GenericVector< T > &_arg)
Definition: vector.hpp:318
PrintScheme
virtual returnValue print(std::ostream &stream=std::cout, const std::string &name=DEFAULT_LABEL, const std::string &startString=DEFAULT_START_STRING, const std::string &endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const std::string &colSeparator=DEFAULT_COL_SEPARATOR, const std::string &rowSeparator=DEFAULT_ROW_SEPARATOR) const
Definition: vector.cpp:97
std::ostream & operator<<(std::ostream &_stream, const GenericVector< T > &_arg)
Definition: vector.hpp:306
bool operator<(const GenericVector &_arg) const
Definition: vector.hpp:149
bool operator>=(const GenericVector &_arg) const
Definition: vector.hpp:134
GenericVector< int > IVector
Definition: vector.hpp:331
Definition: vector.hpp:48
Derived & setZero(Index size)
Derived & setConstant(Index size, const Scalar &value)
GenericVector(std::vector< T > _values)
Definition: vector.hpp:99
EIGEN_STRONG_INLINE const Scalar * data() const
Eigen::Matrix< T, Eigen::Dynamic, 1 > Base
Definition: vector.hpp:64
bool operator<=(const GenericVector &_arg) const
Definition: vector.hpp:124
GenericVector & append(const GenericVector &_arg)
Definition: vector.cpp:42
bool operator!=(const GenericVector &_arg) const
Definition: vector.hpp:119
EIGEN_STRONG_INLINE Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
GenericVector< double > DVector
Definition: vector.hpp:329
const uint DEFAULT_WIDTH
GenericVector(const Eigen::EigenBase< OtherDerived > &other)
Definition: vector.hpp:76
void setAll(const T &_value)
Definition: vector.hpp:160
const double EQUALITY_EPS
const char DEFAULT_ROW_SEPARATOR[6]
static DVector emptyVector
Definition: vector.hpp:335
#define BEGIN_NAMESPACE_ACADO
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
GenericVector(const Eigen::ReturnByValue< OtherDerived > &other)
Definition: vector.hpp:72
const char DEFAULT_LABEL[1]
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
GenericVector getAbsolute() const
Definition: vector.hpp:192
virtual ~GenericVector()
Definition: vector.hpp:107
T getNorm(VectorNorm _norm) const
Definition: vector.cpp:67
#define ACADOERRORTEXT(retval, text)
virtual returnValue read(std::istream &stream)
Definition: vector.cpp:251
Definition: vector.hpp:47


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:16