codac 2.0.0
Loading...
Searching...
No Matches
codac2_Traj_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 TR>
19 struct TrajectoryOp
20 {
21 static typename TR::Type::Domain fwd(const TR& x1, const Interval& x2)
22 {
23 return x1(x2);
24 }
25
26 static typename TR::Type fwd(const TR& x1, const ScalarType& x2)
27 {
28 IntervalMatrix d(x1.size(),x2.da.cols());
29
30 return {
31 fwd(x1,x2.m),
32 fwd(x1,x2.a),
33 d,
34 x2.def_domain && x1.tdomain().is_superset(x2.m)
35 };
36 }
37
38 static void bwd(
39 [[maybe_unused]] const TR& x1,
40 [[maybe_unused]] const typename TR::Type::Domain& y,
41 [[maybe_unused]] Interval& x2)
42 {
43 // todo
44 }
45 };
46
47 // todo: merge this code with SlicedTube_operator
48 template<typename TR, typename T, typename S>
49 class AnalyticOperationExpr<TrajectoryOp<TR>,T,S>
50 : public AnalyticExpr<typename TR::Type>, public OperationExprBase<AnalyticExpr<ScalarType>>
51 {
52 public:
53
54 AnalyticOperationExpr(const TR& x1, const ScalarExpr& x2)
55 : OperationExprBase<AnalyticExpr<ScalarType>>(x2), _x1(x1)
56 { }
57
58 std::shared_ptr<ExprBase> copy() const
59 {
60 return std::make_shared<AnalyticOperationExpr<TrajectoryOp<TR>,T,ScalarType>>(*this);
61 }
62
63 void replace_arg(const ExprID& old_arg_id, const std::shared_ptr<ExprBase>& new_expr)
64 {
65 return OperationExprBase<AnalyticExpr<ScalarType>>::replace_arg(old_arg_id, new_expr);
66 }
67
68 T fwd_eval(ValuesMap& v, Index total_input_size, bool natural_eval) const
69 {
70 return AnalyticExpr<T>::init_value(
71 v, TrajectoryOp<TR>::fwd(_x1, std::get<0>(this->_x)->fwd_eval(v, total_input_size, natural_eval)));
72 }
73
74 void bwd_eval(ValuesMap& v) const
75 {
76 TrajectoryOp<TR>::bwd(_x1, AnalyticExpr<T>::value(v).a, std::get<0>(this->_x)->value(v).a);
77 std::get<0>(this->_x)->bwd_eval(v);
78 }
79
80 std::pair<Index,Index> output_shape() const {
81 return _x1.shape();
82 }
83
84 virtual bool belongs_to_args_list(const FunctionArgsList& args) const
85 {
86 return std::get<0>(this->_x)->belongs_to_args_list(args);
87 }
88
89 std::string str(bool in_parentheses = false) const
90 {
91 std::string s = "T"; // user cannot (yet) specify a name for the trajectory
92 return in_parentheses ? "(" + s + ")" : s;
93 }
94
95 virtual bool is_str_leaf() const
96 {
97 return true;
98 }
99
100 protected:
101
102 const TR _x1;
103 };
104}
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