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();
39 if(shape1.first == 1 && shape1.second == 1)
42 else if(shape2.first == 1 && shape2.second == 1)
47 assert(shape1.second == shape2.first);
48 return { shape1.first, shape2.second };
52 static Interval fwd(
const Interval& x1,
const Interval& x2);
53 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
54 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
55 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
57 static IntervalVector fwd(
const Interval& x1,
const IntervalVector& x2);
58 static VectorType fwd_natural(
const ScalarType& x1,
const VectorType& x2);
59 static VectorType fwd_centered(
const ScalarType& x1,
const VectorType& x2);
60 static void bwd(
const IntervalVector& y, Interval& x1, IntervalVector& x2);
62 static IntervalVector fwd(
const IntervalVector& x1,
const Interval& x2);
63 static VectorType fwd_natural(
const VectorType& x1,
const ScalarType& x2);
64 static VectorType fwd_centered(
const VectorType& x1,
const ScalarType& x2);
65 static void bwd(
const IntervalVector& y, IntervalVector& x1, Interval& x2);
67 static Interval fwd(
const IntervalRow& x1,
const IntervalVector& x2);
69 static void bwd(
const Interval& y, IntervalRow& x1, IntervalVector& x2);
71 static IntervalMatrix fwd(
const Interval& x1,
const IntervalMatrix& x2);
72 static MatrixType fwd_natural(
const ScalarType& x1,
const MatrixType& x2);
73 static MatrixType fwd_centered(
const ScalarType& x1,
const MatrixType& x2);
74 static void bwd(
const IntervalMatrix& y, Interval& x1, IntervalMatrix& x2);
76 static IntervalVector fwd(
const IntervalMatrix& x1,
const IntervalVector& x2);
77 static VectorType fwd_natural(
const MatrixType& x1,
const VectorType& x2);
78 static VectorType fwd_centered(
const MatrixType& x1,
const VectorType& x2);
79 static void bwd(
const IntervalVector& y, IntervalMatrix& x1, IntervalVector& x2);
81 static IntervalMatrix fwd(
const IntervalMatrix& x1,
const IntervalMatrix& x2);
82 static MatrixType fwd_natural(
const MatrixType& x1,
const MatrixType& x2);
83 static MatrixType fwd_centered(
const MatrixType& x1,
const MatrixType& x2);
84 static void bwd(
const IntervalMatrix& y, IntervalMatrix& x1, IntervalMatrix& x2);
91 operator*(
const ScalarExpr& x1,
const ScalarExpr& x2)
93 return { std::make_shared<AnalyticOperationExpr<MulOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
97 operator*(
const ScalarExpr& x1,
const VectorExpr& x2)
99 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,ScalarType,VectorType>>(x1,x2) };
103 operator*(
const VectorExpr& x1,
const ScalarExpr& x2)
105 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,VectorType,ScalarType>>(x1,x2) };
109 operator*(
const ScalarExpr& x1,
const MatrixExpr& x2)
111 return { std::make_shared<AnalyticOperationExpr<MulOp,MatrixType,ScalarType,MatrixType>>(x1,x2) };
115 operator*(
const MatrixExpr& x1,
const VectorExpr& x2)
117 return { std::make_shared<AnalyticOperationExpr<MulOp,VectorType,MatrixType,VectorType>>(x1,x2) };
121 operator*(
const MatrixExpr& x1,
const MatrixExpr& x2)
123 return { std::make_shared<AnalyticOperationExpr<MulOp,MatrixType,MatrixType,MatrixType>>(x1,x2) };
133 inline ScalarType MulOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
137 x1.def_domain && x2.def_domain
141 inline ScalarType MulOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
143 if(centered_form_not_available_for_args(x1,x2))
144 return fwd_natural(x1,x2);
146 assert(x1.da.rows() == 1);
147 assert(x1.da.rows() == x2.da.rows() && x1.da.cols() == x2.da.cols());
149 IntervalMatrix d(1,x1.da.cols());
150 for(Index i = 0 ; i < d.size() ; i++)
151 d(0,i) = x1.da(0,i)*x2.a + x1.a*x2.da(0,i);
157 x1.def_domain && x2.def_domain
163 x1 = gaol::div_rel(y, x2, x1);
164 x2 = gaol::div_rel(y, x1, x2);
167 inline IntervalVector MulOp::fwd(
const Interval& x1,
const IntervalVector& x2)
172 inline VectorType MulOp::fwd_natural(
const ScalarType& x1,
const VectorType& x2)
176 x1.def_domain && x2.def_domain
180 inline VectorType MulOp::fwd_centered(
const ScalarType& x1,
const VectorType& x2)
182 if(centered_form_not_available_for_args(x1,x2))
183 return fwd_natural(x1,x2);
185 assert(x1.da.rows() == 1);
186 assert(x1.da.cols() == x2.da.cols());
187 assert(x2.a.size() == x2.da.rows());
189 IntervalMatrix d(x2.da.rows(),x2.da.cols());
190 for(Index i = 0 ; i < d.rows() ; i++)
191 for(Index j = 0 ; j < d.cols() ; j++)
192 d(i,j) = x1.da(0,j)*x2.a[i]+x1.a*x2.da(i,j);
198 x1.def_domain && x2.def_domain
202 inline void MulOp::bwd(
const IntervalVector& y,
Interval& x1, IntervalVector& x2)
204 assert(y.size() == x2.size());
205 for(Index i = 0 ; i < x2.size() ; i++)
206 MulOp::bwd(y[i], x1, x2[i]);
209 inline IntervalVector MulOp::fwd(
const IntervalVector& x1,
const Interval& x2)
211 return MulOp::fwd(x2,x1);
214 inline VectorType MulOp::fwd_natural(
const VectorType& x1,
const ScalarType& x2)
216 return MulOp::fwd_natural(x2,x1);
219 inline VectorType MulOp::fwd_centered(
const VectorType& x1,
const ScalarType& x2)
221 return MulOp::fwd_centered(x2,x1);
224 inline void MulOp::bwd(
const IntervalVector& y, IntervalVector& x1,
Interval& x2)
226 MulOp::bwd(y, x2, x1);
229 inline Interval MulOp::fwd(
const IntervalRow& x1,
const IntervalVector& x2)
231 assert(x1.size() == x2.size());
233 for(Index i = 0 ; i < x1.size() ; i++)
243 inline IntervalMatrix MulOp::fwd(
const Interval& x1,
const IntervalMatrix& x2)
248 inline MatrixType MulOp::fwd_natural(
const ScalarType& x1,
const MatrixType& x2)
252 x1.def_domain && x2.def_domain
256 inline MatrixType MulOp::fwd_centered(
const ScalarType& x1,
const MatrixType& x2)
258 if(centered_form_not_available_for_args(x1,x2))
259 return fwd_natural(x1,x2);
261 assert(x2.da.cols() == x1.da.cols());
262 IntervalMatrix d(x2.da.rows(),x2.da.cols());
263 for (Index j=0; j<d.cols(); j++)
264 for (Index i=0; i<d.rows(); i++) {
265 d(i,j) = x1.da(0,j)*x2.a.reshaped<Eigen::ColMajor>()[i]+x1.a*x2.da(i,j);
272 x1.def_domain && x2.def_domain
276 inline void MulOp::bwd([[maybe_unused]]
const IntervalMatrix& y, [[maybe_unused]]
Interval& x1, [[maybe_unused]] IntervalMatrix& x2)
281 inline IntervalVector MulOp::fwd(
const IntervalMatrix& x1,
const IntervalVector& x2)
283 assert(x1.cols() == x2.size());
287 inline VectorType MulOp::fwd_natural(
const MatrixType& x1,
const VectorType& x2)
291 x1.def_domain && x2.def_domain
295 inline VectorType MulOp::fwd_centered(
const MatrixType& x1,
const VectorType& x2)
297 if(centered_form_not_available_for_args(x1,x2))
298 return fwd_natural(x1,x2);
300 assert(x2.da.cols() == x1.da.cols());
301 IntervalMatrix d = IntervalMatrix::zero(x1.a.rows(),x1.da.cols());
302 for (Index j=0; j<d.cols(); j++)
303 for (Index i=0; i<d.rows(); i++) {
304 for (Index k=0; k<x2.a.size(); k++) {
305 d(i,j) += x1.da(i+k*x1.a.rows(),j)*x2.a[k]+x1.a(i,k)*x2.da(k,j);
313 x1.def_domain && x2.def_domain
317 inline IntervalMatrix MulOp::fwd(
const IntervalMatrix& x1,
const IntervalMatrix& x2)
319 assert(x1.cols() == x2.rows());
323 inline MatrixType MulOp::fwd_natural(
const MatrixType& x1,
const MatrixType& x2)
327 x1.def_domain && x2.def_domain
331 inline MatrixType MulOp::fwd_centered(
const MatrixType& x1,
const MatrixType& x2)
333 if(centered_form_not_available_for_args(x1,x2))
334 return fwd_natural(x1,x2);
336 assert(x2.da.cols() == x1.da.cols());
337 IntervalMatrix d = IntervalMatrix::zero(x1.a.rows()*x2.a.cols(),x1.da.cols());
338 for (Index j=0; j<d.cols(); j++)
339 for (Index i=0; i<d.rows(); i++)
341 Index row_i = i%x1.a.rows();
342 Index col_i = i/x1.a.rows();
343 for (Index k=0; k<x2.a.rows(); k++) {
344 d(i,j) += x1.da(row_i+k*x1.a.rows(),j)*x2.a(k,col_i)
345 +x1.a(row_i,k)*x2.da(k+col_i*x2.a.rows(),j);
353 x1.def_domain && x2.def_domain
357 inline void MulOp::bwd([[maybe_unused]]
const IntervalMatrix& y, [[maybe_unused]] IntervalMatrix& x1, [[maybe_unused]] IntervalMatrix& x2)
359 assert(x1.rows() == x2.cols());
360 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:428