Skip to content

Commit 466428f

Browse files
committed
[ctc] improved genericity of contractors (Ctc, CtcInverse, CtcInverseNotIn), again
1 parent 61a0a97 commit 466428f

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

src/core/contractors/codac2_Ctc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace codac2
4646
virtual void contract(SlicedTube<X>&... x) const;
4747
// -> is defined in codac2_SlicedTube.h
4848

49-
//virtual void contract_tube(SlicedTube<X>&... x) const;
49+
virtual void contract_tube(SlicedTube<X>&... x) const;
5050
// -> is defined in codac2_SlicedTube.h
5151

5252
virtual std::shared_ptr<CtcBase<X...>> copy() const = 0;

src/core/contractors/codac2_CtcInverse.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,43 @@ namespace codac2
2121
{
2222
class CtcNot;
2323

24-
template<typename Y, typename... X>
25-
requires (sizeof...(X) > 0)
26-
class CtcInverse : public Ctc<CtcInverse<Y,X...>,X...>
24+
template<typename Y_, typename X0=IntervalVector, typename... X>
25+
class CtcInverse : public Ctc<CtcInverse<Y_,X0,X...>,X0,X...>
2726
{
2827
public:
2928

30-
using Ctc<CtcInverse<Y,X...>,X...>::contract;
29+
//using Ctc<CtcInverse<Y,X0,X...>,X0,X...>::contract;
30+
using Y = typename Wrapper<Y_>::Domain; // Y_ is a possible Eigen expr. type
31+
using OutputType = typename ExprType<Y>::Type;
3132

3233
template<typename C>
3334
requires IsCtcBaseOrPtr<C,Y>
34-
CtcInverse(const AnalyticFunction<typename ExprType<Y>::Type>& f, const C& ctc_y, bool with_centered_form = true, bool is_not_in = false)
35-
: Ctc<CtcInverse<Y,X...>,X...>(f.input_size()), _f(f), _ctc_y(ctc_y), _with_centered_form(with_centered_form), _is_not_in(is_not_in)
35+
CtcInverse(const AnalyticFunction<OutputType>& f, const C& ctc_y, bool with_centered_form = true, bool is_not_in = false)
36+
: 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)
3637
{
3738
assert_release([&]() { return f.output_size() == size_of(ctc_y); }()
3839
&& "CtcInverse: invalid dimension of image argument ('y' or 'ctc_y')");
3940
}
4041

41-
CtcInverse(const AnalyticFunction<typename ExprType<Y>::Type>& f, const Y& y, bool with_centered_form = true, bool is_not_in = false)
42+
CtcInverse(const AnalyticFunction<OutputType>& f, const Y& y, bool with_centered_form = true, bool is_not_in = false)
4243
: CtcInverse(f, CtcWrapper<Y,Y>(y), with_centered_form, is_not_in)
4344
{ }
4445

45-
void contract(X&... x) const
46+
void contract(X0& x0, X&... x) const
4647
{
47-
return contract_(*_ctc_y.front(), x...);
48+
return contract_(*_ctc_y.front(), x0, x...);
4849
}
4950

50-
void contract_(const Y& y, X&... x) const
51+
void contract_(const Y& y, X0& x0, X&... x) const
5152
{
52-
return contract_(CtcWrapper<Y,Y>(y), x...);
53+
return contract_(CtcWrapper<Y,Y>(y), x0, x...);
5354
}
5455

55-
void contract_(const CtcBase<Y>& ctc_y, X&... x) const
56+
void contract_(const CtcBase<Y>& ctc_y, X0& x0, X&... x) const
5657
{
5758
ValuesMap v;
5859
// Setting user values into a map before the tree evaluation
59-
_f.fill_from_args(v, x...);
60+
_f.fill_from_args(v, x0, x...);
6061

6162
// Forward/backward algorithm:
6263

@@ -83,12 +84,10 @@ namespace codac2
8384
{
8485
// todo: the above condition !val_expr.da.is_unbounded() should not be necesary,
8586
// possible bug in MulOp in case of unbounded domain?
86-
using X0 = std::tuple_element_t<0,std::tuple<X...>>;
8787

88-
if constexpr(sizeof...(X) == 1 && std::is_same_v<X0,IntervalVector>)
88+
if constexpr(sizeof...(X) == 0 && std::is_same_v<X0,IntervalVector>)
8989
{
90-
X0& x_ = std::get<0>(std::tie(x...));
91-
X0 x_mid = X0(x_.mid());
90+
X0 x_mid = X0(x0.mid());
9291

9392
assert(val_expr.a.size() == val_expr.m.size());
9493
IntervalVector fm { val_expr.a - val_expr.m };
@@ -100,9 +99,9 @@ namespace codac2
10099

101100
else
102101
{
103-
IntervalVector p = x_ - x_mid;
102+
IntervalVector p = x0 - x_mid;
104103
MulOp::bwd(fm, val_expr.da, p);
105-
x_ &= p + x_mid;
104+
x0 &= p + x_mid;
106105
}
107106
}
108107

@@ -114,17 +113,17 @@ namespace codac2
114113

115114
// [4/4] Backward evaluation
116115
_f.expr()->bwd_eval(v); // recursive backward from the root to the leaves
117-
_f.intersect_from_args(v, x...); // updating input values
116+
_f.intersect_from_args(v, x0, x...); // updating input values
118117
}
119118

120-
const AnalyticFunction<typename ExprType<Y>::Type>& fnc() const
119+
const AnalyticFunction<OutputType>& fnc() const
121120
{
122121
return _f;
123122
}
124123

125124
protected:
126125

127-
const AnalyticFunction<typename ExprType<Y>::Type> _f;
126+
const AnalyticFunction<OutputType> _f;
128127
const Collection<CtcBase<Y>> _ctc_y;
129128
bool _with_centered_form;
130129
bool _is_not_in = false;

src/core/contractors/codac2_CtcInverseNotIn.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515

1616
namespace codac2
1717
{
18-
template<typename Y,typename X0=IntervalVector,typename... X>
18+
template<typename Y_, typename X0=IntervalVector, typename... X>
1919
class CtcInverseNotIn : public CtcUnion<X0,X...>
2020
{
2121
public:
2222

23-
CtcInverseNotIn(const AnalyticFunction<typename ExprType<Y>::Type>& f, const Y& y, bool with_centered_form = true)
23+
using Y = typename Wrapper<Y_>::Domain; // Y_ is a possible Eigen expr. type
24+
using OutputType = typename ExprType<Y>::Type;
25+
26+
CtcInverseNotIn(const AnalyticFunction<OutputType>& f, const Y& y, bool with_centered_form = true)
2427
: CtcUnion<X0,X...>(f.input_size())
2528
{
2629
const bool is_not_in = true;
@@ -35,7 +38,7 @@ namespace codac2
3538

3639
template<typename C>
3740
requires IsCtcBaseOrPtr<C,Y>
38-
CtcInverseNotIn(const AnalyticFunction<typename ExprType<Y>::Type>& f, const C& ctc_compl, bool with_centered_form = true)
41+
CtcInverseNotIn(const AnalyticFunction<OutputType>& f, const C& ctc_compl, bool with_centered_form = true)
3942
: CtcUnion<X0,X...>(f.input_size())
4043
{
4144
const bool is_not_in = true;

0 commit comments

Comments
 (0)