27 template<
typename X1,
typename X2>
28 static std::string str(
const X1& x1,
const X2& x2)
30 return x1->str(!x1->is_str_leaf()) +
"*" + x2->str(!x2->is_str_leaf());
33 template<
typename X1,
typename X2>
34 static std::pair<Index,Index> output_shape(
const X1& s1,
const X2& s2)
36 auto shape1=s1->output_shape();
37 auto shape2=s2->output_shape();
38 if (shape1.first==1 && shape1.second==1) {
40 }
else if (shape2.first==1 && shape2.second==1) {
43 assert_release(shape1.second==shape2.first);
44 return std::pair(shape1.first, shape2.second);
48 static Interval fwd(
const Interval& x1,
const Interval& x2);
49 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
50 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
51 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
53 static IntervalVector fwd(
const Interval& x1,
const IntervalVector& x2);
54 static VectorType fwd_natural(
const ScalarType& x1,
const VectorType& x2);
55 static VectorType fwd_centered(
const ScalarType& x1,
const VectorType& x2);
56 static void bwd(
const IntervalVector& y, Interval& x1, IntervalVector& x2);
58 static IntervalVector fwd(
const IntervalVector& x1,
const Interval& x2);
59 static VectorType fwd_natural(
const VectorType& x1,
const ScalarType& x2);
60 static VectorType fwd_centered(
const VectorType& x1,
const ScalarType& x2);
61 static void bwd(
const IntervalVector& y, IntervalVector& x1, Interval& x2);
63 static Interval fwd(
const IntervalRow& x1,
const IntervalVector& x2);
65 static void bwd(
const Interval& y, IntervalRow& x1, IntervalVector& x2);
67 static IntervalMatrix fwd(
const Interval& x1,
const IntervalMatrix& x2);
68 static MatrixType fwd_natural(
const ScalarType& x1,
const MatrixType& x2);
69 static MatrixType fwd_centered(
const ScalarType& x1,
const MatrixType& x2);
70 static void bwd(
const IntervalMatrix& y, Interval& x1, IntervalMatrix& x2);
72 static IntervalVector fwd(
const IntervalMatrix& x1,
const IntervalVector& x2);
73 static VectorType fwd_natural(
const MatrixType& x1,
const VectorType& x2);
74 static VectorType fwd_centered(
const MatrixType& x1,
const VectorType& x2);
75 static void bwd(
const IntervalVector& y, IntervalMatrix& x1, IntervalVector& x2);
77 static IntervalMatrix fwd(
const IntervalMatrix& x1,
const IntervalMatrix& x2);
78 static MatrixType fwd_natural(
const MatrixType& x1,
const MatrixType& x2);
79 static MatrixType fwd_centered(
const MatrixType& x1,
const MatrixType& x2);
80 static void bwd(
const IntervalMatrix& y, IntervalMatrix& x1, IntervalMatrix& x2);
87 operator*(
const ScalarExpr& x1,
const ScalarExpr& x2)
89 return { std::make_shared<AnalyticOperationExpr<MulOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
93 operator*(
const ScalarExpr& x1,
const VectorExpr& x2)
95 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,ScalarType,VectorType>>(x1,x2) };
99 operator*(
const VectorExpr& x1,
const ScalarExpr& x2)
101 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,VectorType,ScalarType>>(x1,x2) };
105 operator*(
const ScalarExpr& x1,
const MatrixExpr& x2)
107 return { std::make_shared<AnalyticOperationExpr<MulOp,MatrixType,ScalarType,MatrixType>>(x1,x2) };
111 operator*(
const MatrixExpr& x1,
const VectorExpr& x2)
113 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,MatrixType,VectorType>>(x1,x2) };
117 operator*(
const MatrixExpr& x1,
const MatrixExpr& x2)
119 return { std::make_shared<AnalyticOperationExpr<MulOp,MatrixType,MatrixType,MatrixType>>(x1,x2) };
129 inline ScalarType MulOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
133 x1.def_domain && x2.def_domain
137 inline ScalarType MulOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
139 if(centered_form_not_available_for_args(x1,x2))
140 return fwd_natural(x1,x2);
142 assert(x1.da.rows() == 1);
143 assert(x1.da.rows() == x2.da.rows() && x1.da.cols() == x2.da.cols());
145 IntervalMatrix d(1,x1.da.cols());
146 for(Index i = 0 ; i < d.size() ; i++)
147 d(0,i) = x1.da(0,i)*x2.a + x1.a*x2.da(0,i);
153 x1.def_domain && x2.def_domain
159 x1 = gaol::div_rel(y, x2, x1);
160 x2 = gaol::div_rel(y, x1, x2);
163 inline IntervalVector MulOp::fwd(
const Interval& x1,
const IntervalVector& x2)
168 inline VectorType MulOp::fwd_natural(
const ScalarType& x1,
const VectorType& x2)
172 x1.def_domain && x2.def_domain
176 inline VectorType MulOp::fwd_centered(
const ScalarType& x1,
const VectorType& x2)
178 if(centered_form_not_available_for_args(x1,x2))
179 return fwd_natural(x1,x2);
181 assert(x1.da.rows() == 1);
182 assert(x1.da.cols() == x2.da.cols());
183 assert(x2.a.size() == x2.da.rows());
185 IntervalMatrix d(x2.da.rows(),x2.da.cols());
186 for(Index i = 0 ; i < d.rows() ; i++)
187 for(Index j = 0 ; j < d.cols() ; j++)
188 d(i,j) = x1.da(0,j)*x2.a[i]+x1.a*x2.da(i,j);
194 x1.def_domain && x2.def_domain
198 inline void MulOp::bwd(
const IntervalVector& y,
Interval& x1, IntervalVector& x2)
200 assert(y.size() == x2.size());
201 for(Index i = 0 ; i < x2.size() ; i++)
202 MulOp::bwd(y[i], x1, x2[i]);
205 inline IntervalVector MulOp::fwd(
const IntervalVector& x1,
const Interval& x2)
207 return MulOp::fwd(x2,x1);
210 inline VectorType MulOp::fwd_natural(
const VectorType& x1,
const ScalarType& x2)
212 return MulOp::fwd_natural(x2,x1);
215 inline VectorType MulOp::fwd_centered(
const VectorType& x1,
const ScalarType& x2)
217 return MulOp::fwd_centered(x2,x1);
220 inline void MulOp::bwd(
const IntervalVector& y, IntervalVector& x1,
Interval& x2)
222 MulOp::bwd(y, x2, x1);
225 inline Interval MulOp::fwd(
const IntervalRow& x1,
const IntervalVector& x2)
227 assert(x1.size() == x2.size());
229 for(Index i = 0 ; i < x1.size() ; i++)
239 inline IntervalMatrix MulOp::fwd(
const Interval& x1,
const IntervalMatrix& x2)
244 inline MatrixType MulOp::fwd_natural(
const ScalarType& x1,
const MatrixType& x2)
248 x1.def_domain && x2.def_domain
252 inline MatrixType MulOp::fwd_centered(
const ScalarType& x1,
const MatrixType& x2)
254 if(centered_form_not_available_for_args(x1,x2))
255 return fwd_natural(x1,x2);
257 assert(x2.da.cols() == x1.da.cols());
258 IntervalMatrix d(x2.da.rows(),x2.da.cols());
259 for (Index j=0; j<d.cols(); j++)
260 for (Index i=0; i<d.rows(); i++) {
261 d(i,j) = x1.da(0,j)*x2.a.reshaped<Eigen::ColMajor>()[i]+x1.a*x2.da(i,j);
268 x1.def_domain && x2.def_domain
272 inline void MulOp::bwd([[maybe_unused]]
const IntervalMatrix& y, [[maybe_unused]]
Interval& x1, [[maybe_unused]] IntervalMatrix& x2)
277 inline IntervalVector MulOp::fwd(
const IntervalMatrix& x1,
const IntervalVector& x2)
279 assert(x1.cols() == x2.size());
283 inline VectorType MulOp::fwd_natural(
const MatrixType& x1,
const VectorType& x2)
287 x1.def_domain && x2.def_domain
291 inline VectorType MulOp::fwd_centered(
const MatrixType& x1,
const VectorType& x2)
293 if(centered_form_not_available_for_args(x1,x2))
294 return fwd_natural(x1,x2);
296 assert(x2.da.cols() == x1.da.cols());
297 IntervalMatrix d = IntervalMatrix::zero(x1.a.rows(),x1.da.cols());
298 for (Index j=0; j<d.cols(); j++)
299 for (Index i=0; i<d.rows(); i++) {
300 for (Index k=0; k<x2.a.size(); k++) {
301 d(i,j) += x1.da(i+k*x1.a.rows(),j)*x2.a[k]+x1.a(i,k)*x2.da(k,j);
309 x1.def_domain && x2.def_domain
313 inline IntervalMatrix MulOp::fwd(
const IntervalMatrix& x1,
const IntervalMatrix& x2)
315 assert(x1.cols() == x2.rows());
319 inline MatrixType MulOp::fwd_natural(
const MatrixType& x1,
const MatrixType& x2)
323 x1.def_domain && x2.def_domain
327 inline MatrixType MulOp::fwd_centered(
const MatrixType& x1,
const MatrixType& x2)
329 if(centered_form_not_available_for_args(x1,x2))
330 return fwd_natural(x1,x2);
332 assert(x2.da.cols() == x1.da.cols());
333 IntervalMatrix d = IntervalMatrix::zero(x1.a.rows()*x2.a.cols(),x1.da.cols());
334 for (Index j=0; j<d.cols(); j++)
335 for (Index i=0; i<d.rows(); i++)
337 Index row_i = i%x1.a.rows();
338 Index col_i = i/x1.a.rows();
339 for (Index k=0; k<x2.a.rows(); k++) {
340 d(i,j) += x1.da(row_i+k*x1.a.rows(),j)*x2.a(k,col_i)
341 +x1.a(row_i,k)*x2.da(k+col_i*x2.a.rows(),j);
349 x1.def_domain && x2.def_domain
353 inline void MulOp::bwd([[maybe_unused]]
const IntervalMatrix& y, [[maybe_unused]] IntervalMatrix& x1, [[maybe_unused]] IntervalMatrix& x2)
355 assert(x1.rows() == x2.cols());
356 assert(y.rows() == x1.rows() && y.cols() == x2.cols());
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval operator*(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:412