codac 2.1.2
Loading...
Searching...
No Matches
codac2_analytic_constants.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Index.h"
13#include "codac2_ExprType.h"
14
15namespace codac2
16{
17 template<typename T>
18 class ConstValueExpr : public AnalyticExpr<T>
19 {
20 public:
21
22 ConstValueExpr(const typename T::Domain& x)
23 : _x(x)
24 { }
25
26 const typename T::Domain& value() const
27 {
28 return _x;
29 }
30
31 std::shared_ptr<ExprBase> copy() const override
32 {
33 return std::make_shared<ConstValueExpr<T>>(*this);
34 }
35
36 T fwd_eval(ValuesMap& v, Index total_input_size, bool natural_eval) const override
37 {
38 if(natural_eval)
39 return AnalyticExpr<T>::init_value(v, T(
40 // the mid is not considered for const values in centered form expression:
41 _x,
42 // the definition domain is necesarily met at this point:
43 true
44 ));
45
46 else
47 return AnalyticExpr<T>::init_value(v, T(
48 // the mid is not considered for const values in centered form expression:
49 _x,
50 _x,
51 // the derivative of a const value is zero:
52 IntervalMatrix::zero(_x.size(),total_input_size),
53 // the definition domain is necesarily met at this point:
54 true
55 ));
56 }
57
58 void bwd_eval(ValuesMap& v) const override
59 {
60 AnalyticExpr<T>::value(v).a &= _x;
61 }
62
63 std::pair<Index,Index> output_shape() const override
64 {
65 if constexpr(std::is_same_v<T,ScalarType>)
66 return {1,1};
67
68 else if constexpr(std::is_same_v<T,VectorType>)
69 return {_x.size(),1};
70
71 else if constexpr(std::is_same_v<T,MatrixType>)
72 return {_x.rows(),_x.cols()};
73
74 else
75 assert_release_constexpr(false && "unknow output shape for constant");
76 }
77
78 void replace_arg([[maybe_unused]] const ExprID& old_arg_id, [[maybe_unused]] const std::shared_ptr<ExprBase>& new_expr) override
79 { }
80
81 virtual bool belongs_to_args_list([[maybe_unused]] const FunctionArgsList& args) const override
82 {
83 return true;
84 }
85
86 virtual std::string str(bool in_parentheses = false) const override;
87
88 virtual bool is_str_leaf() const override
89 {
90 return true;
91 }
92
93 protected:
94
95 const typename T::Domain _x;
96 };
97
98 template<typename T>
99 inline AnalyticExprWrapper<typename ExprType<T>::Type> const_value(const T& x)
100 {
101 return { std::make_shared<ConstValueExpr<typename ExprType<T>::Type>>(x) };
102 }
103}
104
virtual std::shared_ptr< ExprBase > copy() const =0
Creates a copy of the current expression.
Definition codac2_OctaSym.h:21