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