codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_VectorBase.h
Go to the documentation of this file.
1
15
26template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
27 requires IsVectorOrRow<R,C>
28explicit Matrix(int n)
29{
30 Base::template _init2<int,int>(R == 1 ? 1 : n, C == 1 ? 1 : n);
31 if constexpr(!IsIntervalDomain<Scalar>)
32 init(0.);
33}
34
42template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
43 requires IsVectorOrRow<R,C>
44explicit Matrix(const std::vector<double>& v)
45 : Matrix<Scalar,R,C>(R == 1 ? 1 : v.size(), C == 1 ? 1 : v.size())
46{
47 for(size_t i = 0 ; i < v.size() ; i++)
48 (*this)[i] = v[i];
49}
50
59template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
60 requires IsVectorOrRow<R,C>
61inline Scalar& operator()(Index i)
62{
63 return const_cast<Scalar&>(const_cast<const Matrix<Scalar,R,C>*>(this)->operator()(i));
64}
65
74template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
75 requires IsVectorOrRow<R,C>
76inline const Scalar& operator()(Index i) const
77{
78 assert_release(i >= 0 && i < this->size());
79 return this->PlainObjectBase<Matrix<Scalar,R,C>>::operator()(i);
80}
81
90template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
91 requires IsVectorOrRow<R,C>
92inline Scalar& operator[](Index i)
93{
94 return const_cast<Scalar&>(const_cast<const Matrix<Scalar,R,C>*>(this)->operator[](i));
95}
96
105template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
106 requires IsVectorOrRow<R,C>
107inline const Scalar& operator[](Index i) const
108{
109 assert_release(i >= 0 && i < this->size());
110 return this->PlainObjectBase<Matrix<Scalar,R,C>>::operator[](i);
111}
112
121template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
122 requires IsVectorOrRow<R,C>
123inline static Matrix<Scalar,R,C> zero(Index n)
124{
125 assert_release(n >= 0);
126 return DenseBase<Matrix<Scalar,R,C>>::Zero(n);
127}
128
137template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
138 requires IsVectorOrRow<R,C>
139inline static Matrix<Scalar,R,C> ones(Index n)
140{
141 assert_release(n >= 0);
142 return DenseBase<Matrix<Scalar,R,C>>::Ones(n);
143}
144
154template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
155 requires IsVectorOrRow<R,C>
156inline static Matrix<Scalar,R,C> constant(Index n, const Scalar& x)
157{
158 assert_release(n >= 0);
159 return DenseBase<Matrix<Scalar,R,C>>::Constant(n,x);
160}
161
172template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
173 requires IsVectorOrRow<R,C>
174inline static Matrix<Scalar,R,C> random(Index n)
175{
176 assert_release(n >= 0);
177 return DenseBase<Matrix<Scalar,R,C>>::Random(n);
178}
179
188template<typename OtherDerived,int R=RowsAtCompileTime,int C=ColsAtCompileTime>
189 requires IsVectorOrRow<R,C> && IsVectorOrRow<MatrixBase<OtherDerived>::RowsAtCompileTime,MatrixBase<OtherDerived>::ColsAtCompileTime>
190inline void put(Index start_id, const MatrixBase<OtherDerived>& x)
191{
192 assert_release(start_id >= 0 && start_id < this->size());
193 assert_release(start_id+x.size() <= this->size());
194
195 this->segment(start_id,x.size()) << x;
196}
197
209template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
210 requires IsVectorOrRow<R,C>
211inline void resize_save_values(Index n)
212{
213 // With resize() of Eigen, the data is reallocated and all previous values are lost.
214 auto copy = *this;
215 this->resize(n);
216 for(Index i = 0 ; i < std::min((Index)copy.size(),n) ; i++)
217 (*this)[i] = copy[i];
218}
Matrix(const Matrix< double, R, C > &lb, const Matrix< double, R, C > &ub)
Constructs an interval matrix from lower and upper bound matrices.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:50
auto & init()
Initializes all elements of the matrix with default intervals.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:113
Matrix()=delete
Deleted default constructor to prevent default instantiation when either the number of rows or column...
Scalar & operator()(Index i)
Access element at index i (mutable).
Definition codac2_Matrix_addons_VectorBase.h:61
Scalar & operator[](Index i)
Access element at index i (mutable) via operator[].
Definition codac2_Matrix_addons_VectorBase.h:92
void put(Index start_id, const MatrixBase< OtherDerived > &x)
Inserts values from matrix x starting at index start_id.
Definition codac2_Matrix_addons_VectorBase.h:190
void resize_save_values(Index n)
Resizes the vector or row matrix to size n, preserving existing values.
Definition codac2_Matrix_addons_VectorBase.h:211