codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_Base.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>
Scalar & operator() (Index i, Index j)
 Accesses a matrix element (modifiable) by its row and column indices.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
const Scalar & operator() (Index i, Index j) const
 Accesses a matrix element (non modifiable) by its row and column indices.
 
auto & init (const Scalar &x)
 Initializes all elements of the matrix with the scalar value x.
 
template<typename U_, int R_, int C_>
bool operator== (const Matrix< U_, R_, C_ > &x) const
 Compares this matrix with another matrix for equality.
 

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

◆ operator()() [1/2]

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

Accesses a matrix element (modifiable) by its row and column indices.

Provides mutable access to the element at the specified row i and column j. This operator allows both reading and writing of matrix elements.

Parameters
iRow index of the element.
jColumn index of the element.
Returns
Reference to the element at position (i,j).
28{
29 return const_cast<Scalar&>(static_cast<const Matrix<Scalar,R,C>&>(*this).operator()(i,j));
30}
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>
const Scalar & operator() ( Index i,
Index j ) const
inline

Accesses a matrix element (non modifiable) by its row and column indices.

Provides reading access to the element at the specified row i and column j. This operator allows only reading of matrix elements.

Parameters
iRow index of the element.
jColumn index of the element.
Returns
Const reference to the element at position (i,j).
44{
45 assert_release(i >= 0 && i < this->rows() && j >= 0 && j < this->cols());
46
47 if constexpr(!IsVectorOrRow<R,C>)
48 return this->PlainObjectBase<Matrix<Scalar,R,C>>::operator()(i,j);
49
50 else
51 {
52 if constexpr(R == 1)
53 return (*this)[j];
54 return (*this)[i];
55 }
56}

◆ init()

auto & init ( const Scalar & x)
inline

Initializes all elements of the matrix with the scalar value x.

Parameters
xThe scalar value to assign to each element.
Returns
Reference to the current matrix object (allows method chaining).
65{
66 for(Index i = 0 ; i < this->size() ; i++)
67 *(this->data()+i) = x;
68 return *this;
69}

◆ operator==()

template<typename U_, int R_, int C_>
bool operator== ( const Matrix< U_, R_, C_ > & x) const
inline

Compares this matrix with another matrix for equality.

Parameters
xThe other matrix to compare against.
Returns
true if matrices have the same size, shape, and identical elements; false otherwise.
79{
80 // This operator should be related to Eigen::MatrixBase,
81 // for allowing a comparison between two matrix expressions.
82 // However, it is not possible to overwrite Eigen::MatrixBase::operator==.
83 // Therefore, only comparisons between Eigen::Matrix types is possible.
84 // This must be corrected...
85
86 if(this->size() != x.size())
87 return false;
88
89 if constexpr(std::is_same_v<Scalar,codac2::Interval> && std::is_same_v<U_,codac2::Interval>)
90 {
91 if(this->is_empty() || x.is_empty())
92 return this->is_empty() && x.is_empty();
93 }
94
95 if(this->rows() != x.rows() || this->cols() != x.cols())
96 return false;
97
98 for(Index i = 0 ; i < this->size() ; i++)
99 if(*(this->data()+i) != *(x.data()+i))
100 return false;
101
102 return true;
103}
bool is_empty() const
Checks whether the interval matrix is empty.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:56