12#ifndef __CODAC2_MATRIX_H__
13#define __CODAC2_MATRIX_H__
16#include <codac2_eigen.h>
22 template<
int R=Dynamic,
int C=Dynamic>
23 class Matrix_ :
public Eigen::Matrix<double,R,C>
28 : Eigen::Matrix<double,R,C>()
31 Matrix_(
int nb_rows,
int nb_cols)
32 : Eigen::Matrix<double,R,C>(nb_rows, nb_cols)
34 assert(R == Dynamic || R == (
int)nb_rows);
35 assert(C == Dynamic || C == (
int)nb_cols);
38 Matrix_(
int nb_rows,
int nb_cols,
double x)
39 : Eigen::Matrix<double,R,C>(nb_rows, nb_cols)
41 assert(R == Dynamic || R == (
int)nb_rows);
42 assert(C == Dynamic || C == (
int)nb_cols);
46 explicit Matrix_(
int nb_rows,
int nb_cols,
const double values[])
47 : Matrix_<R,C>(nb_rows, nb_cols)
50 for(
int i = 0 ; i < nb_rows ; i++)
51 for(
int j = 0 ; j < nb_cols ; j++)
56 (*
this)(i,j) = values[k];
61 explicit Matrix_(
const double values[])
62 : Matrix_<R,C>(R, C, values)
65 Matrix_(std::initializer_list<std::initializer_list<double>> l)
68 assert((R == Dynamic || (
int)l.size() == R) &&
"ill-formed matrix");
70 for(
const auto& ri : l) {
71 assert(cols == -1 || cols == (
int)ri.size() &&
"ill-formed matrix");
72 cols = (int)ri.size();
74 this->resize(l.size(),cols);
76 for(
const auto& ri : l)
79 for(
const auto& ci : ri)
86 template<
typename OtherDerived>
87 Matrix_(
const Eigen::MatrixBase<OtherDerived>& other)
88 : Eigen::Matrix<double,R,C>(other)
92 template<
typename OtherDerived>
93 Matrix_& operator=(
const Eigen::MatrixBase<OtherDerived>& other)
95 this->Eigen::Matrix<double,R,C>::operator=(other);
101 for(
size_t i = 0 ; i < this->size() ; i++)
102 *(this->data()+i) = x;
107 return Eigen::Matrix<double,R,C>::Identity();
112 return Eigen::Matrix<double,R,C>::minCoeff();
117 return Eigen::Matrix<double,R,C>::maxCoeff();
120 auto operator+(
const Matrix_<R,C>& x)
const
126 auto operator-(
const Matrix_<R,C>& x)
const
132 auto operator-()
const
134 return Eigen::Matrix<double,R,C>::operator-();
137 auto operator&(
const Matrix_<R,C>& x)
const
143 auto operator|(
const Matrix_<R,C>& x)
const
149 auto& operator+=(
const Matrix_<R,C>& x)
151 (*this).noalias() += x;
155 auto& operator-=(
const Matrix_<R,C>& x)
157 (*this).noalias() -= x;
161 static Matrix_<R,C> zeros()
163 return Eigen::Matrix<double,R,C>::Zero();
166 static Matrix_<R,C> ones()
168 return Eigen::Matrix<double,R,C>::Ones();
172 template<
int R,
int C>
173 std::ostream& operator<<(std::ostream& os,
const Matrix_<R,C>& x)
176 for(
size_t i = 0 ; i < x.rows() ; i++)
179 for(
size_t j = 0 ; j < x.cols() ; j++)
180 os << x(i,j) << (j<x.cols()-1 ?
" ; " :
"");
182 if(i < x.rows()-1) os << std::endl;
188 #include "ibex_Matrix.h"
189 template<
int R=Dynamic,
int C=Dynamic>
190 ibex::Matrix to_codac1(
const Matrix_<R,C>& x)
192 ibex::Matrix x_(x.rows(), x.cols());
193 for(
size_t i = 0 ; i < x.rows() ; i++)
194 for(
size_t j = 0 ; j < x.cols() ; j++)
199 template<
int R,
int C>
200 Matrix_<R,C> floor(
const Matrix_<R,C>& x)
202 Matrix_<R,C> f(x.rows(), x.cols());
203 for(
size_t i = 0 ; i < x.size() ; i++)
204 *(f.data()+i) = std::floor(*(x.data()+i));
208 template<
int R,
int C>
209 Matrix_<R,C> round(
const Matrix_<R,C>& x)
211 Matrix_<R,C> f(x.rows(), x.cols());
212 for(
size_t i = 0 ; i < x.size() ; i++)
213 *(f.data()+i) = std::round(*(x.data()+i));
217 template<
int R,
int C>
218 Matrix_<R,C> ceil(
const Matrix_<R,C>& x)
220 Matrix_<R,C> f(x.rows(), x.cols());
221 for(
size_t i = 0 ; i < x.size() ; i++)
222 *(f.data()+i) = std::ceil(*(x.data()+i));
226 template<
int R,
int C>
227 Matrix_<R,C> abs(
const Matrix_<R,C>& x)
229 Matrix_<R,C> f(x.rows(), x.cols());
230 for(
size_t i = 0 ; i < x.size() ; i++)
231 *(f.data()+i) = std::fabs(*(x.data()+i));
235 class Matrix :
public Matrix_<>
239 explicit Matrix(
size_t nb_rows,
size_t nb_cols)
240 : Matrix_<>(nb_rows, nb_cols)
244 explicit Matrix(
size_t nb_rows,
size_t nb_cols,
double x)
245 : Matrix_<>(nb_rows, nb_cols, x)
248 explicit Matrix(
size_t nb_rows,
size_t nb_cols,
const double values[])
249 : Matrix_<>(nb_rows, nb_cols, values)
252 Matrix(
const Matrix_<>& x)
256 Matrix(std::initializer_list<std::initializer_list<double>> l)
260 template<
int R,
int C>
261 explicit Matrix(
const Matrix_<R,C>& v)