codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_MatrixBase.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 (R == -1 || C == -1)
 Matrix ()=delete
 Deleted default constructor to prevent default instantiation when either the number of rows or columns is dynamic.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires (!IsVectorOrRow<R,C>)
 Matrix (int r, int c)
 Constructs a matrix with given number of rows and columns.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires (!IsVectorOrRow<R,C>)
 Matrix (int r, int c, const Scalar values[])
 Constructs a non-vector matrix with given dimensions and initializes it from a raw array of values.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires (!IsVectorOrRow<R,C>)
void resize_save_values (Index r, Index c)
 Resizes the matrix to (r,c), preserving existing values where possible.
 

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 r,
int c )
explicit

Constructs a matrix with given number of rows and columns.

Initializes the matrix storage with dimensions (r,c). If Scalar is not an interval domain, the matrix is initialized with zeros.

Parameters
rNumber of rows (runtime).
cNumber of columns (runtime).
36{
37 Base::template _init2<int,int>(r,c);
38 if constexpr(!IsIntervalDomain<Scalar>)
39 init(0.);
40}
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 ( int r,
int c,
const Scalar values[] )
explicit

Constructs a non-vector matrix with given dimensions and initializes it from a raw array of values.

Copies the values from the values array into the matrix elements. If values is null, initializes all elements to zero.

Parameters
rNumber of rows (runtime).
cNumber of columns (runtime).
valuesPointer to array of values used to initialize matrix elements. Can be null, in which case the matrix is zero-initialized.
Precondition
The runtime dimensions r and c must match the compile-time dimensions R and C if these are fixed (not -1).
r and c must be non-negative.
62{
63 assert((R==(int)r || R==-1) && (C==(int)c || C==-1));
64 assert(r >= 0 && c >= 0);
65
66 if(values == 0)
67 init(Scalar(0.)); // in case the user called Matrix(r,c,0) and 0 is interpreted as NULL!
68
69 else
70 {
71 Index k = 0;
72 for(Index i = 0 ; i < this->rows() ; i++)
73 for(Index j = 0 ; j < this->cols() ; j++)
74 (*this)(i,j) = values[k++];
75 assert(k == this->size());
76 }
77}
Matrix()=delete
Deleted default constructor to prevent default instantiation when either the number of rows or column...

◆ resize_save_values()

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

Resizes the matrix to (r,c), preserving existing values where possible.

Parameters
rNew number of rows.
cNew number of columns.

This function resizes the matrix while preserving the data in the overlapping region of the old and new sizes. Unlike Eigen's resize(), which discards old data, this function copies existing values into the resized matrix.

171{
172 // With resize() of Eigen, the data is reallocated and all previous values are lost.
173 auto copy = *this;
174 this->resize(r,c);
175 for(Index i = 0 ; i < std::min((Index)copy.rows(),r) ; i++)
176 for(Index j = 0 ; j < std::min((Index)copy.cols(),c) ; j++)
177 (*this)(i,j) = copy(i,j);
178}