codac 2.0.0
Loading...
Searching...
No Matches
codac2_Tube_operator.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "codac2_ExprType.h"
14#include "codac2_Wrapper.h"
15
16namespace codac2
17{
18 template<typename TU>
19 struct TubeOp
20 {
21 using Type = typename ExprType<TU>::Type;
22
23 static typename Type::Domain fwd(const TU& x1, const Interval& x2)
24 {
25 return x1(x2);
26 }
27
28 static Type fwd(const TU& x1, const ScalarType& x2)
29 {
30 IntervalMatrix d(x1.size(),x2.da.cols());
31
32 return {
33 fwd(x1,x2.m),
34 fwd(x1,x2.a),
35 d,
36 x2.def_domain && x1.tdomain()->t0_tf().is_superset(x2.m)
37 };
38 }
39
40 static void bwd(
41 [[maybe_unused]] const TU& x1,
42 [[maybe_unused]] const typename Type::Domain& y,
43 [[maybe_unused]] Interval& x2)
44 {
45 // todo
46 }
47 };
48
49 // todo: merge this code with Traj_operator
50 template<typename TU, typename T, typename S>
51 class AnalyticOperationExpr<TubeOp<TU>,T,S>
52 : public AnalyticExpr<T>, public OperationExprBase<AnalyticExpr<ScalarType>>
53 {
54 public:
55
56 AnalyticOperationExpr(const TU& x1, const ScalarExpr& x2)
57 : OperationExprBase<AnalyticExpr<ScalarType>>(x2), _x1(x1)
58 { }
59
60 std::shared_ptr<ExprBase> copy() const
61 {
62 return std::make_shared<AnalyticOperationExpr<TubeOp<TU>,T,ScalarType>>(*this);
63 }
64
65 void replace_arg(const ExprID& old_arg_id, const std::shared_ptr<ExprBase>& new_expr)
66 {
67 return OperationExprBase<AnalyticExpr<ScalarType>>::replace_arg(old_arg_id, new_expr);
68 }
69
70 T fwd_eval(ValuesMap& v, Index total_input_size, bool natural_eval) const
71 {
72 return AnalyticExpr<T>::init_value(
73 v, TubeOp<TU>::fwd(_x1, std::get<0>(this->_x)->fwd_eval(v, total_input_size, natural_eval)));
74 }
75
76 void bwd_eval(ValuesMap& v) const
77 {
78 TubeOp<TU>::bwd(_x1, AnalyticExpr<T>::value(v).a, std::get<0>(this->_x)->value(v).a);
79 std::get<0>(this->_x)->bwd_eval(v);
80 }
81
82 std::pair<Index,Index> output_shape() const {
83 return _x1.shape();
84 }
85
86 virtual bool belongs_to_args_list(const FunctionArgsList& args) const
87 {
88 return std::get<0>(this->_x)->belongs_to_args_list(args);
89 }
90
91 std::string str(bool in_parentheses = false) const
92 {
93 std::string s = "T"; // user cannot (yet) specify a name for the trajectory
94 return in_parentheses ? "(" + s + ")" : s;
95 }
96
97 virtual bool is_str_leaf() const
98 {
99 return true;
100 }
101
102 protected:
103
104 const TU _x1;
105 };
106}
A base class for expressions representing operations with multiple operands.
Definition codac2_ExprBase.h:164
OperationExprBase(std::shared_ptr< X >... x)
Definition codac2_ExprBase.h:176
std::tuple< std::shared_ptr< X >... > _x
Definition codac2_ExprBase.h:258
Definition codac2_OctaSym.h:21
Eigen::Matrix< Interval,-1,-1 > IntervalMatrix
Alias for a dynamic-size matrix of intervals.
Definition codac2_IntervalMatrix.h:25