21 template <
class T,
class Alloc = Eigen::aligned_allocator<T>>
25 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 typedef std::vector<T, Alloc>
Base;
29 typedef typename std::vector<T, Alloc>::iterator
iterator;
62 DiscreteArray(const_iterator first, const_iterator last) : Base(first, last){};
67 using Base::operator[];
75 using Base::push_back;
92 Base::operator=(static_cast<const Base&>(rhs));
100 if (this->size() != rhs.size())
101 throw std::runtime_error(
"DiscreteArray.h (operator +): lhs.size() != rhs.size()");
105 std::transform(this->begin(), this->end(), rhs.begin(), result.begin(), std::plus<T>());
112 if (this->size() != rhs.size())
113 throw std::runtime_error(
"DiscreteArray.h (operator -): lhs.size() != rhs.size()");
117 std::transform(this->begin(), this->end(), rhs.begin(), result.begin(), std::minus<T>());
124 if (this->size() != rhs.size())
125 throw std::runtime_error(
"DiscreteArray.h (operator +=): lhs.size() != rhs.size()");
127 std::transform(this->begin(), this->end(), rhs.begin(), this->begin(), std::plus<T>());
134 if (this->size() != rhs.size())
135 throw std::runtime_error(
"DiscreteArray.h (operator -=): lhs.size() != rhs.size()");
137 std::transform(this->begin(), this->end(), rhs.begin(), this->begin(), std::minus<T>());
142 template <
typename SCALAR>
146 std::transform(this->begin(), this->end(), result.begin(), [scalar](T arg) {
return arg * scalar; });
151 template <
typename SCALAR>
155 std::transform(this->begin(), this->end(), result.begin(), [scalar](T arg) {
return arg / scalar; });
164 void eraseFront(
const size_t N) { this->erase(this->begin(), this->begin() + N); }
166 void setConstant(
const T& data) { std::fill(this->begin(), this->end(), data); }
170 std::for_each(this->begin(), this->end(), [&](T& val) { val += offset; });
virtual ~DiscreteArray()
destructor
Definition: DiscreteArray.h:65
An discrete array (vector) of a particular data type.
Definition: DiscreteArray.h:22
DiscreteArray(const DiscreteArray &&other)
move constructor
Definition: DiscreteArray.h:36
DiscreteArray(iterator first, iterator last)
copy constructor
Definition: DiscreteArray.h:54
void setConstant(const T &data)
sets all elements to a constant.
Definition: DiscreteArray.h:166
DiscreteArray< T, Alloc > & operator-=(const DiscreteArray< T, Alloc > &rhs)
overload -= operator
Definition: DiscreteArray.h:132
void eraseFront(const size_t N)
erase an element from the front
Definition: DiscreteArray.h:164
std::vector< T, Alloc >::iterator iterator
iterator
Definition: DiscreteArray.h:29
DiscreteArray(const DiscreteArray &other)
copy constructor
Definition: DiscreteArray.h:38
const Base & toImplementation() const
returns the underlying std::vector
Definition: DiscreteArray.h:162
DiscreteArray(int n, const T &value=T())
resize constructor
Definition: DiscreteArray.h:46
DiscreteArray< T, Alloc > operator*(const SCALAR &scalar) const
overload * operator
Definition: DiscreteArray.h:143
CppAD::AD< CppAD::cg::CG< double > > SCALAR
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
std::vector< T, Alloc >::const_iterator const_iterator
const iterator
Definition: DiscreteArray.h:30
DiscreteArray< T, Alloc > operator/(const SCALAR &scalar) const
overload / operator
Definition: DiscreteArray.h:152
DiscreteArray()
default constructor
Definition: DiscreteArray.h:33
std::vector< T, Alloc > Base
base class (std::vector)
Definition: DiscreteArray.h:28
DiscreteArray< T, Alloc > operator+(const DiscreteArray< T, Alloc > &rhs) const
overload + operator in order to be able to directly sum up two arrays
Definition: DiscreteArray.h:98
DiscreteArray(const_iterator first, const_iterator last)
copy constructor
Definition: DiscreteArray.h:62
DiscreteArray< T, Alloc > & operator=(const DiscreteArray< T, Alloc > &rhs)
Definition: DiscreteArray.h:86
Base & toImplementation()
returns the underlying std::vector
Definition: DiscreteArray.h:160
void addOffset(const T &offset)
add an offset to each element
Definition: DiscreteArray.h:168
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef T value_type
data type
Definition: DiscreteArray.h:27
DiscreteArray< T, Alloc > & operator+=(const DiscreteArray< T, Alloc > &rhs)
overload += operator
Definition: DiscreteArray.h:122
void swap(DiscreteArray &other)
swaps the content of two arrays
Definition: DiscreteArray.h:84
DiscreteArray< T, Alloc > operator-(const DiscreteArray< T, Alloc > &rhs) const
overload - operator in order to be able to directly take the difference between two arrays ...
Definition: DiscreteArray.h:110