codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_Base.h
Go to the documentation of this file.
1
15
26template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
27inline Scalar& operator()(Index i, Index j)
28{
29 return const_cast<Scalar&>(static_cast<const Matrix<Scalar,R,C>&>(*this).operator()(i,j));
30}
31
42template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
43inline const Scalar& operator()(Index i, Index j) const
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}
57
64inline auto& init(const Scalar& x)
65{
66 for(Index i = 0 ; i < this->size() ; i++)
67 *(this->data()+i) = x;
68 return *this;
69}
70
77template<typename U_,int R_,int C_>
78inline bool operator==(const Matrix<U_,R_,C_>& x) const
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 operator==(const Matrix< U_, R_, C_ > &x) const
Compares this matrix with another matrix for equality.
Definition codac2_Matrix_addons_Base.h:78
Scalar & operator()(Index i, Index j)
Accesses a matrix element (modifiable) by its row and column indices.
Definition codac2_Matrix_addons_Base.h:27
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
bool is_empty() const
Checks whether the interval matrix is empty.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:56