- 3.0.2 core module.
ScalarArray.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include "DiscreteArray.h"
9 
10 namespace ct {
11 namespace core {
12 
14 
17 template <class SCALAR = double>
18 class ScalarArray : public DiscreteArray<SCALAR>
19 {
20 public:
21  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
22 
23  typedef std::vector<Eigen::Matrix<SCALAR, 1, 1>, Eigen::aligned_allocator<Eigen::Matrix<SCALAR, 1, 1>>> EigenTraj;
24 
27 
29 
34  ScalarArray(size_t n, const SCALAR& value = SCALAR()) : DiscreteArray<SCALAR>(n, value){};
35 
37  ScalarArray(const ScalarArray& other) : DiscreteArray<SCALAR>(other){};
38 
40  ScalarArray(const std::vector<SCALAR>& arg) : DiscreteArray<SCALAR>()
41  {
42  for (size_t i = 0; i < arg.size(); i++)
43  this->push_back(arg[i]);
44  }
45 
47  virtual ~ScalarArray() {}
48  void fromEigenTrajectory(const EigenTraj in)
49  {
50  for (auto el : in)
51  this->push_back(el(0, 0));
52  }
53 
55  EigenTraj toEigenTrajectory()
56  {
57  EigenTraj eigenTraj;
58  for (size_t i = 0; i < this->size(); i++)
59  {
60  Eigen::Matrix<SCALAR, 1, 1> newElement;
61  newElement(0, 0) = (*this)[i];
62  eigenTraj.push_back(newElement);
63  }
64  return eigenTraj;
65  }
66 
67 private:
68 };
69 }
70 }
An discrete array (vector) of a particular data type.
Definition: DiscreteArray.h:22
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::vector< Eigen::Matrix< SCALAR, 1, 1 >, Eigen::aligned_allocator< Eigen::Matrix< SCALAR, 1, 1 > > > EigenTraj
Definition: ScalarArray.h:23
void fromEigenTrajectory(const EigenTraj in)
Definition: ScalarArray.h:48
ScalarArray(const std::vector< SCALAR > &arg)
constructor from std::vector
Definition: ScalarArray.h:40
ScalarArray(const ScalarArray &other)
copy constructor
Definition: ScalarArray.h:37
CppAD::AD< CppAD::cg::CG< double > > SCALAR
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
for i
An array of scalar data types.
Definition: ScalarArray.h:18
ScalarArray()
default constructor
Definition: ScalarArray.h:26
virtual ~ScalarArray()
destructor
Definition: ScalarArray.h:47
ScalarArray(size_t n, const SCALAR &value=SCALAR())
resize constructor
Definition: ScalarArray.h:34
EigenTraj toEigenTrajectory()
convert to an Eigen trajectory
Definition: ScalarArray.h:55