52 FunctionBase(
const std::vector<std::reference_wrapper<VarBase>>&
args,
const std::shared_ptr<E>& y)
65 :
_y(std::dynamic_pointer_cast<E>(y->copy())),
_args(
args)
103 const std::shared_ptr<E>&
expr()
const
117 template<
typename... X>
120 auto expr_copy =
expr()->copy();
122 (expr_copy->replace_arg(
_args[i++]->unique_id(), this->
__get_copy(x)), ...);
123 assert_release(i == this->
args().size() &&
124 "Invalid arguments: wrong number of input arguments");
125 return std::dynamic_pointer_cast<E>(expr_copy);
139 std::shared_ptr<E>
operator()(
const std::vector<std::shared_ptr<ExprBase>>& x)
const
141 assert_release(x.size() == this->args().size() &&
142 "Invalid arguments: wrong number of input arguments");
143 auto expr_copy =
expr()->copy();
144 for(
size_t i = 0 ; i < x.size() ; i++)
145 expr_copy->replace_arg(
_args[i]->unique_id(), x[i]->copy());
146 return std::dynamic_pointer_cast<E>(expr_copy);
157 return this->
_args.total_size();
172 return std::dynamic_pointer_cast<X>(x->copy());
183 std::shared_ptr<ExprBase>
__get_copy(
const AnalyticExprWrapper<X>& x)
const
198 if constexpr(std::is_base_of_v<VarBase,A>)
199 return std::dynamic_pointer_cast<A>(x.copy());
203 return const_value(x);
207 const std::shared_ptr<E>
_y;
A container class to manage a collection of function arguments.
Definition codac2_FunctionArgsList.h:25
auto __get_copy(const A &x) const
Helper function to get a copy of various expression types.
Definition codac2_FunctionBase.h:196
std::shared_ptr< ExprBase > __get_copy(const AnalyticExprWrapper< X > &x) const
Helper function to get a copy of an AnalyticExprWrapper.
Definition codac2_FunctionBase.h:183
const FunctionArgsList & args() const
Returns the arguments of the function.
Definition codac2_FunctionBase.h:93
virtual ~FunctionBase()
Virtual destructor.
Definition codac2_FunctionBase.h:85
std::shared_ptr< E > operator()(const X &... x) const
Applies this function to the arguments and returns the resulting expression.
Definition codac2_FunctionBase.h:118
const FunctionArgsList _args
arguments of the function
Definition codac2_FunctionBase.h:208
FunctionBase(const std::vector< std::reference_wrapper< VarBase > > &args, const std::shared_ptr< E > &y)
Constructs a FunctionBase with a list of arguments and a shared pointer to an output expression.
Definition codac2_FunctionBase.h:52
std::shared_ptr< X > __get_copy(std::shared_ptr< X > x) const
Helper function to get a copy of a an expression.
Definition codac2_FunctionBase.h:170
Index input_size() const
Calculates the total size of the function arguments, as the sum of the sizes of each argument.
Definition codac2_FunctionBase.h:155
const std::shared_ptr< E > _y
expression that defines the function
Definition codac2_FunctionBase.h:207
FunctionBase(const FunctionArgsList &args, const std::shared_ptr< E > &y)
Constructs a FunctionBase with a list of arguments and a shared pointer to an output expression.
Definition codac2_FunctionBase.h:64
std::shared_ptr< E > operator()(const std::vector< std::shared_ptr< ExprBase > > &x) const
Applies this function to the arguments and returns the resulting expression.
Definition codac2_FunctionBase.h:139
FunctionBase(const FunctionBase< E > &f)
Copy constructor.
Definition codac2_FunctionBase.h:75
const std::shared_ptr< E > & expr() const
Returns the expression associated with the function.
Definition codac2_FunctionBase.h:103