23 static std::string str(
const X1& x1, Index i, Index j)
25 return x1->str(!x1->is_str_leaf()) +
"[" + std::to_string(i) +
":" + std::to_string(j) +
"]";
29 static std::pair<Index,Index> output_shape(
const X1& s1, Index i, Index j)
31 auto shape1=s1->output_shape();
32 assert_release(shape1.second==1 && i<=j && j<shape1.first);
36 static IntervalVector fwd(
const IntervalVector& x1, Index i, Index j);
37 static VectorType fwd_natural(
const VectorType& x1, Index i, Index j);
38 static VectorType fwd_centered(
const VectorType& x1, Index i, Index j);
39 static void bwd(
const IntervalVector& y, IntervalVector& x1, Index i, Index j);
45 class AnalyticOperationExpr<SubvectorOp,VectorType,VectorType> :
public AnalyticExpr<VectorType>,
public OperationExprBase<AnalyticExpr<VectorType>>
49 AnalyticOperationExpr(
const std::shared_ptr<AnalyticExpr<VectorType>>& x1, Index i, Index j)
53 AnalyticOperationExpr(
const AnalyticOperationExpr& e)
57 std::shared_ptr<ExprBase> copy()
const
59 return std::make_shared<AnalyticOperationExpr<SubvectorOp,VectorType,VectorType>>(*this);
62 void replace_arg(
const ExprID& old_arg_id,
const std::shared_ptr<ExprBase>& new_expr)
67 VectorType fwd_eval(ValuesMap& v, Index total_input_size,
bool natural_eval)
const
70 return AnalyticExpr<VectorType>::init_value(
71 v, SubvectorOp::fwd_natural(std::get<0>(this->
_x)->fwd_eval(v, total_input_size, natural_eval), _i, _j));
73 return AnalyticExpr<VectorType>::init_value(
74 v, SubvectorOp::fwd_centered(std::get<0>(this->
_x)->fwd_eval(v, total_input_size, natural_eval), _i, _j));
77 void bwd_eval(ValuesMap& v)
const
79 SubvectorOp::bwd(AnalyticExpr<VectorType>::value(v).a, std::get<0>(this->
_x)->value(v).a, _i, _j);
80 std::get<0>(this->
_x)->bwd_eval(v);
83 std::pair<Index,Index> output_shape()
const {
84 return SubvectorOp::output_shape(std::get<0>(this->
_x),_i,_j);
87 virtual bool belongs_to_args_list(
const FunctionArgsList& args)
const
89 return std::get<0>(this->
_x)->belongs_to_args_list(args);
92 std::string str(
bool in_parentheses =
false)
const
95 std::string s = SubvectorOp::str(std::get<0>(this->
_x), _i, _j);
96 return in_parentheses ?
"(" + s +
")" : s;
99 virtual bool is_str_leaf()
const
111 inline IntervalVector SubvectorOp::fwd(
const IntervalVector& x1, Index i, Index j)
113 assert(i >= 0 && i < x1.size() && j >= i && j < x1.size());
114 return x1.subvector(i,j);
117 inline VectorType SubvectorOp::fwd_natural(
const VectorType& x1, Index i, Index j)
119 assert(i >= 0 && i < x1.a.rows() && j >= i && j < x1.a.rows());
126 inline VectorType SubvectorOp::fwd_centered(
const VectorType& x1, Index i, Index j)
128 if(centered_form_not_available_for_args(x1))
129 return fwd_natural(x1,i,j);
131 assert(i >= 0 && i < x1.a.rows() && j >= i && j < x1.a.rows());
135 x1.da.block(i,0,j-i+1,x1.da.cols()),
140 inline void SubvectorOp::bwd(
const IntervalVector& y, IntervalVector& x1, Index i, Index j)
142 assert(i >= 0 && i < x1.size() && j >= i && j < x1.size());
143 assert(j-i < y.size());
144 for(Index k = 0 ; k < j-i+1 ; k++)
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