25 class CtcInverse :
public Ctc<CtcInverse<Y_,X0,X...>,X0,X...>
29 using Y =
typename Wrapper<Y_>::Domain;
30 using OutputType =
typename ExprType<Y>::Type;
33 requires IsCtcBaseOrPtr<C,Y>
34 CtcInverse(
const AnalyticFunction<OutputType>& f,
const C& ctc_y,
bool with_centered_form =
true,
bool is_not_in =
false)
35 : Ctc<CtcInverse<Y,X0,X...>,X0,X...>(f.input_size()), _f(f), _ctc_y(ctc_y), _with_centered_form(with_centered_form), _is_not_in(is_not_in)
37 assert_release([&]() {
return f.output_size() == size_of(ctc_y); }()
38 &&
"CtcInverse: invalid dimension of image argument ('y' or 'ctc_y')");
41 CtcInverse(
const AnalyticFunction<OutputType>& f,
const Y& y,
bool with_centered_form =
true,
bool is_not_in =
false)
42 : CtcInverse(f, CtcWrapper<Y,Y>(y), with_centered_form, is_not_in)
44 if constexpr(std::is_same_v<Y,IntervalMatrix>)
46 const auto [rows,cols] = f.output_shape();
47 assert_release(y.rows() == rows && y.cols() == cols
48 &&
"CtcInverse: invalid output matrix dimensions");
52 void contract(X0& x0, X&... x)
const
54 return contract_(*_ctc_y.front(), x0, x...);
57 void contract_(
const Y& y, X0& x0, X&... x)
const
59 return contract_(CtcWrapper<Y,Y>(y), x0, x...);
62 void contract_(
const CtcBase<Y>& ctc_y, X0& x0, X&... x)
const
64 assert_release(_f.nb_args() == 1 +
sizeof...(X)
65 &&
"CtcInverse: invalid number of input arguments");
69 _f.fill_from_args(v, x0, x...);
74 _f.expr()->fwd_eval(v, _f.input_size(), !_with_centered_form);
75 auto& val_expr = _f.expr()->value(v);
77 if(_is_not_in && !val_expr.def_domain)
85 ctc_y.contract(val_expr.a);
92 if(_with_centered_form && val_expr.def_domain && !val_expr.da.is_unbounded() && val_expr.da.size() != 0)
100 Y diffval = val_expr.a - val_expr.m;
102 MulOp::bwd(fm, val_expr.da, p);
103 intersect_from_flat_vector((p + x_mid).eval(), x0, x...);
107 _f.expr()->bwd_eval(v);
108 _f.intersect_from_args(v, x0, x...);
111 const AnalyticFunction<OutputType>& fnc()
const
118 static void intersect_from_flat_vector(Interval& x,
const IntervalVector& v, Index& i)
126 x &= v.segment(i,x.size());
132 x &= v.segment(i,x.size()).reshaped<Eigen::ColMajor>(x.rows(),x.cols());
136 template<
typename... T>
137 static void intersect_from_flat_vector(
const IntervalVector& v, T&... x)
140 ((intersect_from_flat_vector(x,v,i)), ...);
145 const AnalyticFunction<OutputType> _f;
146 const Collection<CtcBase<Y>> _ctc_y;
147 bool _with_centered_form;
148 bool _is_not_in =
false;
156 CtcInverse(
const AnalyticFunction<ScalarType>&, std::initializer_list<double>,
bool =
true,
bool =
false) ->
157 CtcInverse<Interval,IntervalVector>;
160 CtcInverse(
const AnalyticFunction<ScalarType>&, std::initializer_list<Y>,
bool =
true,
bool =
false) ->
161 CtcInverse<Interval,IntervalVector>;
163 CtcInverse(
const AnalyticFunction<ScalarType>&,
const Interval&,
bool =
true,
bool =
false) ->
164 CtcInverse<Interval,IntervalVector>;
166 CtcInverse(
const AnalyticFunction<ScalarType>&,
double,
bool =
true,
bool =
false) ->
167 CtcInverse<Interval,IntervalVector>;
170 requires IsCtcBaseOrPtr<C,Interval>
171 CtcInverse(
const AnalyticFunction<ScalarType>&,
const C&,
bool =
true,
bool =
false) ->
172 CtcInverse<Interval,IntervalVector>;
176 CtcInverse(
const AnalyticFunction<VectorType>&, std::initializer_list<double>,
bool =
true,
bool =
false) ->
177 CtcInverse<IntervalVector,IntervalVector>;
179 CtcInverse(
const AnalyticFunction<VectorType>&, std::initializer_list<std::initializer_list<double>>,
bool =
true,
bool =
false) ->
180 CtcInverse<IntervalVector,IntervalVector>;
182 CtcInverse(
const AnalyticFunction<VectorType>&,
const Vector&,
bool =
true,
bool =
false) ->
183 CtcInverse<IntervalVector,IntervalVector>;
185 CtcInverse(
const AnalyticFunction<VectorType>&,
const IntervalVector&,
bool =
true,
bool =
false) ->
186 CtcInverse<IntervalVector,IntervalVector>;
188 template<
typename OtherDerived>
189 requires (OtherDerived::RowsAtCompileTime == -1 && OtherDerived::ColsAtCompileTime == 1)
190 CtcInverse(
const AnalyticFunction<VectorType>&,
const Eigen::MatrixBase<OtherDerived>&,
bool =
true,
bool =
false) ->
191 CtcInverse<IntervalVector,IntervalVector>;
194 requires IsCtcBaseOrPtr<C,IntervalVector>
195 CtcInverse(
const AnalyticFunction<VectorType>&,
const C&,
bool =
true,
bool =
false) ->
196 CtcInverse<IntervalVector,IntervalVector>;
200 CtcInverse(
const AnalyticFunction<MatrixType>&, std::initializer_list<std::initializer_list<double>>,
bool =
true,
bool =
false) ->
201 CtcInverse<IntervalMatrix,IntervalVector>;
203 CtcInverse(
const AnalyticFunction<MatrixType>&, std::initializer_list<std::initializer_list<std::initializer_list<double>>>,
bool =
true,
bool =
false) ->
204 CtcInverse<IntervalMatrix,IntervalVector>;
206 template<
typename OtherDerived>
207 requires (OtherDerived::RowsAtCompileTime == -1 && OtherDerived::ColsAtCompileTime == -1)
208 CtcInverse(
const AnalyticFunction<MatrixType>&,
const Eigen::MatrixBase<OtherDerived>&,
bool =
true,
bool =
false) ->
209 CtcInverse<IntervalMatrix,IntervalVector>;
212 requires IsCtcBaseOrPtr<C,IntervalMatrix>
213 CtcInverse(
const AnalyticFunction<MatrixType>&,
const C&,
bool =
true,
bool =
false) ->
214 CtcInverse<IntervalMatrix,IntervalVector>;
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:50
Definition codac2_OctaSym.h:21
Eigen::Matrix< double,-1, 1 > Vector
Alias for a dynamically-sized column vector of doubles.
Definition codac2_Vector.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