codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_VectorBase.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
 Matrix (int n)
 Constructs a vector or row matrix with size n.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
 Matrix (const std::vector< double > &v)
 Constructs a vector or row matrix from a vector of doubles.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
Scalar & operator() (Index i)
 Access element at index i (mutable).
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
const Scalar & operator() (Index i) const
 Access element at index i (const).
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
Scalar & operator[] (Index i)
 Access element at index i (mutable) via operator[].
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
const Scalar & operator[] (Index i) const
 Access element at index i (const) via operator[].
 
template<typename OtherDerived, int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C> && IsVectorOrRow<MatrixBase<OtherDerived>::RowsAtCompileTime,MatrixBase<OtherDerived>::ColsAtCompileTime>
void put (Index start_id, const MatrixBase< OtherDerived > &x)
 Inserts values from matrix x starting at index start_id.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
void resize_save_values (Index n)
 Resizes the vector or row matrix to size n, preserving existing values.
 

Detailed Description

This file is included in the declaration of Eigen::MatrixBase, thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html and the file codac2_matrices.h


Date
2024
Author
Simon Rohou
License: GNU Lesser General Public License (LGPL)

Function Documentation

◆ Matrix() [1/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
Matrix ( int n)
explicit

Constructs a vector or row matrix with size n.

Precondition
The matrix is a vector or row vector (IsVectorOrRow<R,C>).
Parameters
nNumber of elements.

Initializes the matrix to zero if Scalar is not an interval domain.

29{
30 Base::template _init2<int,int>(R == 1 ? 1 : n, C == 1 ? 1 : n);
31 if constexpr(!IsIntervalDomain<Scalar>)
32 init(0.);
33}
auto & init()
Initializes all elements of the matrix with default intervals.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:113

◆ Matrix() [2/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
Matrix ( const std::vector< double > & v)
explicit

Constructs a vector or row matrix from a vector of doubles.

Precondition
The matrix is a vector or row vector (IsVectorOrRow<R,C>).
Parameters
vVector of doubles to initialize the matrix.
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}
Matrix()=delete
Deleted default constructor to prevent default instantiation when either the number of rows or column...

◆ operator()() [1/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
Scalar & operator() ( Index i)
inline

Access element at index i (mutable).

Precondition
The matrix is a vector or row vector (IsVectorOrRow<R,C>).
Parameters
iIndex of the element.
Returns
Reference to the element at index i.
62{
63 return const_cast<Scalar&>(const_cast<const Matrix<Scalar,R,C>*>(this)->operator()(i));
64}
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

◆ operator()() [2/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
const Scalar & operator() ( Index i) const
inline

Access element at index i (const).

Precondition
The matrix is a vector or row vector (IsVectorOrRow<R,C>).
Parameters
iIndex of the element.
Returns
Const reference to the element at index i.
77{
78 assert_release(i >= 0 && i < this->size());
79 return this->PlainObjectBase<Matrix<Scalar,R,C>>::operator()(i);
80}

◆ operator[]() [1/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
Scalar & operator[] ( Index i)
inline

Access element at index i (mutable) via operator[].

Precondition
The matrix is a vector or row vector (IsVectorOrRow<R,C>).
Parameters
iIndex of the element.
Returns
Reference to the element at index i.
93{
94 return const_cast<Scalar&>(const_cast<const Matrix<Scalar,R,C>*>(this)->operator[](i));
95}

◆ operator[]() [2/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
const Scalar & operator[] ( Index i) const
inline

Access element at index i (const) via operator[].

Precondition
The matrix is a vector or row vector (IsVectorOrRow<R,C>).
Parameters
iIndex of the element.
Returns
Const reference to the element at index i.
108{
109 assert_release(i >= 0 && i < this->size());
110 return this->PlainObjectBase<Matrix<Scalar,R,C>>::operator[](i);
111}

◆ put()

template<typename OtherDerived, int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C> && IsVectorOrRow<MatrixBase<OtherDerived>::RowsAtCompileTime,MatrixBase<OtherDerived>::ColsAtCompileTime>
void put ( Index start_id,
const MatrixBase< OtherDerived > & x )
inline

Inserts values from matrix x starting at index start_id.

Precondition
The matrix and x are both vectors or row vectors.
Parameters
start_idStart index for insertion.
xThe matrix whose values will be inserted.
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}

◆ resize_save_values()

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsVectorOrRow<R,C>
void resize_save_values ( Index n)
inline

Resizes the vector or row matrix to size n, preserving existing values.

Precondition
The matrix is a vector or row vector.
Parameters
nThe new size.

Eigen's resize() discards existing data, so this function copies existing values before resizing and restores them afterward.

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}