- 3.0.2 core module.
ArrayHelpers.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 
27 template <typename EIGEN_VECTOR_ARRAY_TYPE_IN, typename SCALAR = double>
28 DiscreteArray<Eigen::Matrix<SCALAR, -1, -1>> transposeArray(const EIGEN_VECTOR_ARRAY_TYPE_IN& array)
29 {
30  // some runtime tests
31  if (array.front().cols() != 1)
32  {
33  throw std::runtime_error(
34  "ct::core::transposeArray() called with invalid type. Eigen types in array must be vectors (no matrices "
35  "allowed).");
36  }
37 
38  size_t rows_in = array.front().rows();
39  size_t cols_in = array.size();
40 
41  DiscreteArray<Eigen::Matrix<SCALAR, -1, -1>> result;
42 
43  for (size_t j = 0; j < rows_in; j++)
44  {
45  Eigen::Matrix<SCALAR, -1, -1> newVec(cols_in, 1);
46 
47  for (size_t i = 0; i < cols_in; i++)
48  {
49  newVec(i, 0) = array[i](j);
50  }
51  result.push_back(newVec);
52  }
53  return result;
54 }
55 
56 } /* namespace core */
57 } /* namespace ct */
An discrete array (vector) of a particular data type.
Definition: DiscreteArray.h:22
CppAD::AD< CppAD::cg::CG< double > > SCALAR
for i
DiscreteArray< Eigen::Matrix< SCALAR, -1, -1 > > transposeArray(const EIGEN_VECTOR_ARRAY_TYPE_IN &array)
this method transposes/flips an array of vectors into another array containing the scalar trajectorie...
Definition: ArrayHelpers.h:28