23 template<
typename X1,
typename X2>
24 static std::string str(
const X1& x1,
const X2& x2)
26 return x1->str(!x1->is_str_leaf()) +
"/" + x2->str(!x2->is_str_leaf());
29 template<
typename X1,
typename X2>
30 static std::pair<Index,Index> output_shape(
const X1& s1, [[maybe_unused]]
const X2& s2)
32 [[maybe_unused]]
auto shape2 = s2->output_shape();
33 assert(shape2.first == 1 && shape2.second == 1);
34 return s1->output_shape();
37 static Interval fwd(
const Interval& x1,
const Interval& x2);
38 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
39 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
40 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
42 static IntervalVector fwd(
const IntervalVector& x1,
const Interval& x2);
43 static VectorType fwd_natural(
const VectorType& x1,
const ScalarType& x2);
44 static VectorType fwd_centered(
const VectorType& x1,
const ScalarType& x2);
45 static void bwd(
const IntervalVector& y, IntervalVector& x1, Interval& x2);
47 static IntervalMatrix fwd(
const IntervalMatrix& x1,
const Interval& x2);
48 static MatrixType fwd_natural(
const MatrixType& x1,
const ScalarType& x2);
49 static MatrixType fwd_centered(
const MatrixType& x1,
const ScalarType& x2);
50 static void bwd(
const IntervalMatrix& y, IntervalMatrix& x1, Interval& x2);
57 operator/(
const ScalarExpr& x1,
const ScalarExpr& x2)
59 return { std::make_shared<AnalyticOperationExpr<DivOp,ScalarType,ScalarType,ScalarType>>(x1,x2) };
63 operator/(
const VectorExpr& x1,
const ScalarExpr& x2)
65 return { std::make_shared<AnalyticOperationExpr<DivOp,VectorType,VectorType,ScalarType>>(x1,x2) };
69 operator/(
const MatrixExpr& x1,
const ScalarExpr& x2)
71 return { std::make_shared<AnalyticOperationExpr<DivOp,MatrixType,MatrixType,ScalarType>>(x1,x2) };
81 inline ScalarType DivOp::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
85 x1.def_domain && x2.def_domain && x2.a != 0.
89 inline ScalarType DivOp::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
91 if(centered_form_not_available_for_args(x1,x2))
92 return fwd_natural(x1,x2);
94 assert(x1.da.size() == x2.da.size());
96 IntervalMatrix d(1,x1.da.size());
97 for(Index i = 0 ; i < d.size() ; i++)
98 d(0,i) = (x1.da(0,i)*x2.a-x1.a*x2.da(0,i))/
sqr(x2.a);
104 x1.def_domain && x2.def_domain && x2.a != 0.
110 if((x1 &= y*x2).is_empty())
116 MulOp::bwd(x1, tmp, x2);
122 inline IntervalVector DivOp::fwd(
const IntervalVector& x1,
const Interval& x2)
127 inline VectorType DivOp::fwd_natural(
const VectorType& x1,
const ScalarType& x2)
131 x1.def_domain && x2.def_domain && x2.a != 0.
135 inline VectorType DivOp::fwd_centered(
const VectorType& x1,
const ScalarType& x2)
137 if(centered_form_not_available_for_args(x1,x2))
138 return fwd_natural(x1,x2);
140 assert(x2.da.rows() == 1);
141 assert(x1.da.cols() == x2.da.cols());
143 IntervalMatrix d(x1.da.rows(),x1.da.cols());
144 for(Index j = 0 ; j < d.cols() ; j++)
145 for(Index i = 0 ; i < d.rows() ; i++)
146 d(i,j) = x1.da(i,j)/x2.a - x1.a[i]*x2.da(0,j)/
sqr(x2.a);
152 x1.def_domain && x2.def_domain && x2.a != 0.
156 inline void DivOp::bwd(
const IntervalVector& y, IntervalVector& x1,
Interval& x2)
158 assert(x1.size() == y.size());
159 for(Index i = 0 ; i < x1.size() ; i++)
160 DivOp::bwd(y[i], x1[i], x2);
163 inline IntervalMatrix DivOp::fwd(
const IntervalMatrix& x1,
const Interval& x2)
168 inline MatrixType DivOp::fwd_natural(
const MatrixType& x1,
const ScalarType& x2)
172 x1.def_domain && x2.def_domain && x2.a != 0.
176 inline MatrixType DivOp::fwd_centered(
const MatrixType& x1,
const ScalarType& x2)
178 if(centered_form_not_available_for_args(x1,x2))
179 return fwd_natural(x1,x2);
181 assert(x2.da.rows() == 1);
182 assert(x1.da.cols() == x2.da.cols());
184 IntervalMatrix d(x1.da.rows(),x1.da.cols());
185 for(Index j = 0 ; j < d.cols() ; j++)
186 for(Index i = 0 ; i < d.rows() ; i++)
187 d(i,j) = x1.da(i,j)/x2.a -
188 x1.a.reshaped<Eigen::ColMajor>()[i]*x2.da(0,j)/
sqr(x2.a);
194 x1.def_domain && x2.def_domain && x2.a != 0.
198 inline void DivOp::bwd(
const IntervalMatrix& y, IntervalMatrix& x1,
Interval& x2)
200 assert(x1.cols() == y.cols() && x1.rows() == y.rows());
201 for(Index j = 0 ; j < x1.cols() ; j++)
202 for(Index i = 0 ; i < x1.rows() ; i++)
203 DivOp::bwd(y(i,j), x1(i,j), x2);
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:451
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21