codac 1.5.6
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 template<typename TR, typename T, typename S>
48 class AnalyticOperationExpr<TrajectoryOp<TR>,T,S>
49 : public AnalyticExpr<typename TR::Type>, public OperationExprBase<AnalyticExpr<ScalarType>>
50 {
51 public:
52
53 AnalyticOperationExpr(const TR& x1, const ScalarExpr& x2)
54 : OperationExprBase<AnalyticExpr<ScalarType>>(x2), _x1(x1)
55 { }
56
57 std::shared_ptr<ExprBase> copy() const
58 {
59 return std::make_shared<AnalyticOperationExpr<TrajectoryOp<TR>,T,ScalarType>>(*this);
60 }
61
62 void replace_arg(const ExprID& old_arg_id, const std::shared_ptr<ExprBase>& new_expr)
63 {
64 return OperationExprBase<AnalyticExpr<ScalarType>>::replace_arg(old_arg_id, new_expr);
65 }
66
67 T fwd_eval(ValuesMap& v, Index total_input_size, bool natural_eval) const
68 {
69 return AnalyticExpr<T>::init_value(
70 v, TrajectoryOp<TR>::fwd(_x1, std::get<0>(this->_x)->fwd_eval(v, total_input_size, natural_eval)));
71 }
72
73 void bwd_eval(ValuesMap& v) const
74 {
75 TrajectoryOp<TR>::bwd(_x1, AnalyticExpr<T>::value(v).a, std::get<0>(this->_x)->value(v).a);
76 std::get<0>(this->_x)->bwd_eval(v);
77 }
78
79 std::pair<Index,Index> output_shape() const {
80 return _x1.shape();
81 }
82
83 virtual bool belongs_to_args_list(const FunctionArgsList& args) const
84 {
85 return std::get<0>(this->_x)->belongs_to_args_list(args);
86 }
87
88 std::string str(bool in_parentheses = false) const
89 {
90 std::string s = "T"; // user cannot (yet) specify a name for the trajectory
91 return in_parentheses ? "(" + s + ")" : s;
92 }
93
94 virtual bool is_str_leaf() const
95 {
96 return true;
97 }
98
99 protected:
100
101 const TR _x1;
102 };
103}
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