codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_MatrixBase.h
Go to the documentation of this file.
1
15
20template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
21 requires (R == -1 || C == -1)
22Matrix() = delete;
23
33template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
34 requires (!IsVectorOrRow<R,C>)
35explicit Matrix(int r, int c)
36{
37 Base::template _init2<int,int>(r,c);
38 if constexpr(!IsIntervalDomain<Scalar>)
39 init(0.);
40}
41
58template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
59 requires (!IsVectorOrRow<R,C>)
60explicit Matrix(int r, int c, const Scalar values[])
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}
78
86template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
87 requires (!IsVectorOrRow<R,C>)
88inline static Matrix<Scalar,R,C> zero(Index r, Index c)
89{
90 assert_release(r >= 0 && c >= 0);
91 return DenseBase<Matrix<Scalar,R,C>>::Zero(r,c);
92}
93
101template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
102 requires (!IsVectorOrRow<R,C>)
103inline static Matrix<Scalar,R,C> ones(Index r, Index c)
104{
105 assert_release(r >= 0 && c >= 0);
106 return DenseBase<Matrix<Scalar,R,C>>::Ones(r,c);
107}
108
116template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
117 requires (!IsVectorOrRow<R,C>)
118inline static Matrix<Scalar,R,C> eye(Index r, Index c)
119{
120 assert_release(r >= 0 && c >= 0);
121 return MatrixBase<Matrix<Scalar,R,C>>::Identity(r,c);
122}
123
132template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
133 requires (!IsVectorOrRow<R,C>)
134inline static Matrix<Scalar,R,C> constant(Index r, Index c, const Scalar& x)
135{
136 assert_release(r >= 0 && c >= 0);
137 return DenseBase<Matrix<Scalar,R,C>>::Constant(r,c,x);
138}
139
149template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
150 requires (!IsVectorOrRow<R,C>)
151inline static Matrix<Scalar,R,C> random(Index r, Index c)
152{
153 assert_release(r >= 0 && c >= 0);
154 return DenseBase<Matrix<Scalar,R,C>>::Random(r,c);
155}
156
168template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
169 requires (!IsVectorOrRow<R,C>)
170inline void resize_save_values(Index r, Index c)
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}
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...
void resize_save_values(Index r, Index c)
Resizes the matrix to (r,c), preserving existing values where possible.
Definition codac2_Matrix_addons_MatrixBase.h:170