28 template<
typename X1,
typename X2>
29 static std::string str(
const X1& x1,
const X2& x2)
31 return x1->str(!x1->is_str_leaf()) +
"*" + x2->str(!x2->is_str_leaf());
34 template<
typename X1,
typename X2>
35 static std::pair<Index,Index> output_shape(
const X1& s1,
const X2& s2)
37 auto shape1 = s1->output_shape();
38 auto shape2 = s2->output_shape();
40 if(shape1.first == 1 && shape1.second == 1)
43 else if(shape2.first == 1 && shape2.second == 1)
48 assert(shape1.second == shape2.first);
49 return { shape1.first, shape2.second };
53 static Interval fwd(
const Interval& x1,
const Interval& x2);
54 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
55 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
56 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
59 static VectorType fwd_natural(
const ScalarType& x1,
const VectorType& x2);
60 static VectorType fwd_centered(
const ScalarType& x1,
const VectorType& x2);
64 static VectorType fwd_natural(
const VectorType& x1,
const ScalarType& x2);
65 static VectorType fwd_centered(
const VectorType& x1,
const ScalarType& x2);
73 static MatrixType fwd_natural(
const ScalarType& x1,
const MatrixType& x2);
74 static MatrixType fwd_centered(
const ScalarType& x1,
const MatrixType& x2);
78 static VectorType fwd_natural(
const MatrixType& x1,
const VectorType& x2);
79 static VectorType fwd_centered(
const MatrixType& x1,
const VectorType& x2);
83 static MatrixType fwd_natural(
const MatrixType& x1,
const MatrixType& x2);
84 static MatrixType fwd_centered(
const MatrixType& x1,
const MatrixType& x2);
92 operator*(
const ScalarExpr& x1,
const ScalarExpr& x2)
94 return { std::make_shared<AnalyticOperationExpr<MulOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
98 operator*(
const ScalarExpr& x1,
const VectorExpr& x2)
100 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,ScalarType,VectorType>>(x1,x2) };
104 operator*(
const VectorExpr& x1,
const ScalarExpr& x2)
106 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,VectorType,ScalarType>>(x1,x2) };
110 operator*(
const ScalarExpr& x1,
const MatrixExpr& x2)
112 return { std::make_shared<AnalyticOperationExpr<MulOp,MatrixType,ScalarType,MatrixType>>(x1,x2) };
116 operator*(
const MatrixExpr& x1,
const VectorExpr& x2)
118 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,MatrixType,VectorType>>(x1,x2) };
122 operator*(
const MatrixExpr& x1,
const MatrixExpr& x2)
124 return { std::make_shared<AnalyticOperationExpr<MulOp,MatrixType,MatrixType,MatrixType>>(x1,x2) };
134 inline ScalarType MulOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
138 x1.def_domain && x2.def_domain
142 inline ScalarType MulOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
144 if(centered_form_not_available_for_args(x1,x2))
145 return fwd_natural(x1,x2);
147 assert(x1.da.rows() == 1);
148 assert(x1.da.rows() == x2.da.rows() && x1.da.cols() == x2.da.cols());
151 for(Index i = 0 ; i < d.size() ; i++)
152 d(0,i) = x1.da(0,i)*x2.a + x1.a*x2.da(0,i);
158 x1.def_domain && x2.def_domain
164 x1 = gaol::div_rel(y, x2, x1);
165 x2 = gaol::div_rel(y, x1, x2);
173 inline VectorType MulOp::fwd_natural(
const ScalarType& x1,
const VectorType& x2)
177 x1.def_domain && x2.def_domain
181 inline VectorType MulOp::fwd_centered(
const ScalarType& x1,
const VectorType& x2)
183 if(centered_form_not_available_for_args(x1,x2))
184 return fwd_natural(x1,x2);
186 assert(x1.da.rows() == 1);
187 assert(x1.da.cols() == x2.da.cols());
188 assert(x2.a.size() == x2.da.rows());
191 for(Index i = 0 ; i < d.rows() ; i++)
192 for(Index j = 0 ; j < d.cols() ; j++)
193 d(i,j) = x1.da(0,j)*x2.a[i]+x1.a*x2.da(i,j);
199 x1.def_domain && x2.def_domain
205 assert(y.size() == x2.size());
206 for(Index i = 0 ; i < x2.size() ; i++)
207 MulOp::bwd(y[i], x1, x2[i]);
212 return MulOp::fwd(x2,x1);
215 inline VectorType MulOp::fwd_natural(
const VectorType& x1,
const ScalarType& x2)
217 return MulOp::fwd_natural(x2,x1);
220 inline VectorType MulOp::fwd_centered(
const VectorType& x1,
const ScalarType& x2)
222 return MulOp::fwd_centered(x2,x1);
227 MulOp::bwd(y, x2, x1);
232 assert(x1.size() == x2.size());
234 for(Index i = 0 ; i < x1.size() ; i++)
249 inline MatrixType MulOp::fwd_natural(
const ScalarType& x1,
const MatrixType& x2)
253 x1.def_domain && x2.def_domain
257 inline MatrixType MulOp::fwd_centered(
const ScalarType& x1,
const MatrixType& x2)
259 if(centered_form_not_available_for_args(x1,x2))
260 return fwd_natural(x1,x2);
262 assert(x2.da.cols() == x1.da.cols());
264 for (Index j=0; j<d.cols(); j++)
265 for (Index i=0; i<d.rows(); i++) {
266 d(i,j) = x1.da(0,j)*x2.a.reshaped<Eigen::ColMajor>()[i]+x1.a*x2.da(i,j);
273 x1.def_domain && x2.def_domain
284 assert(x1.cols() == x2.size());
288 inline VectorType MulOp::fwd_natural(
const MatrixType& x1,
const VectorType& x2)
292 x1.def_domain && x2.def_domain
296 inline VectorType MulOp::fwd_centered(
const MatrixType& x1,
const VectorType& x2)
298 if(centered_form_not_available_for_args(x1,x2))
299 return fwd_natural(x1,x2);
301 assert(x2.da.cols() == x1.da.cols());
302 IntervalMatrix d = IntervalMatrix::zero(x1.a.rows(),x1.da.cols());
303 for (Index j=0; j<d.cols(); j++)
304 for (Index i=0; i<d.rows(); i++) {
305 for (Index k=0; k<x2.a.size(); k++) {
306 d(i,j) += x1.da(i+k*x1.a.rows(),j)*x2.a[k]+x1.a(i,k)*x2.da(k,j);
314 x1.def_domain && x2.def_domain
320 assert(x1.cols() == x2.rows());
324 inline MatrixType MulOp::fwd_natural(
const MatrixType& x1,
const MatrixType& x2)
328 x1.def_domain && x2.def_domain
332 inline MatrixType MulOp::fwd_centered(
const MatrixType& x1,
const MatrixType& x2)
334 if(centered_form_not_available_for_args(x1,x2))
335 return fwd_natural(x1,x2);
337 assert(x2.da.cols() == x1.da.cols());
338 IntervalMatrix d = IntervalMatrix::zero(x1.a.rows()*x2.a.cols(),x1.da.cols());
339 for (Index j=0; j<d.cols(); j++)
340 for (Index i=0; i<d.rows(); i++)
342 Index row_i = i%x1.a.rows();
343 Index col_i = i/x1.a.rows();
344 for (Index k=0; k<x2.a.rows(); k++) {
345 d(i,j) += x1.da(row_i+k*x1.a.rows(),j)*x2.a(k,col_i)
346 +x1.a(row_i,k)*x2.da(k+col_i*x2.a.rows(),j);
354 x1.def_domain && x2.def_domain
360 assert(x1.rows() == x2.cols());
361 assert(y.rows() == x1.rows() && y.cols() == x2.cols());
363 IntvFullPivLU LUdec(x1);
365 if (x2.is_empty()) { x1.set_empty();
return; }
368 LUdec2.solve(y.transpose(),tX1);
369 x1 = tX1.transpose();
370 if (x1.is_empty()) { x2.set_empty();
return; }
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
Definition codac2_OctaSym.h:21
Interval operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:445
Eigen::Matrix< Interval, 1,-1 > IntervalRow
Alias for a dynamic-size row vector of intervals.
Definition codac2_IntervalRow.h:24
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25
Eigen::Matrix< Interval,-1,-1 > IntervalMatrix
Alias for a dynamic-size matrix of intervals.
Definition codac2_IntervalMatrix.h:25