26 #ifndef CASADI_MX_FUNCTION_HPP
27 #define CASADI_MX_FUNCTION_HPP
34 #include "x_function.hpp"
35 #include "mx_node.hpp"
53 std::vector<casadi_int>
arg;
56 std::vector<casadi_int>
res;
103 const std::vector<MX>& input,
const std::vector<MX>& output,
104 const std::vector<std::string>& name_in,
105 const std::vector<std::string>& name_out);
115 int eval(
const double** arg,
double** res, casadi_int* iw,
double* w,
void* mem)
const override;
120 void disp_more(std::ostream& stream)
const override;
125 std::string
class_name()
const override {
return "MXFunction";}
130 bool is_a(
const std::string& type,
bool recursive)
const override;
141 Dict get_stats(
void* mem)
const override;
144 Dict generate_options(
const std::string& target=
"clone")
const override;
149 void init(
const Dict& opts)
override;
181 static std::vector<MX> order(
const std::vector<MX>& expr);
188 void generate_lifted(
Function& vdef_fcn,
Function& vinit_fcn)
const override;
191 bool should_inline(
bool with_sx,
bool always_inline,
bool never_inline)
const override;
197 casadi_int* iw,
SXElem* w,
void* mem,
198 bool always_inline,
bool never_inline)
const override;
204 bool always_inline,
bool never_inline)
const override;
209 void ad_forward(
const std::vector<std::vector<MX> >& fwdSeed,
210 std::vector<std::vector<MX> >& fwdSens)
const;
215 void ad_reverse(
const std::vector<std::vector<MX> >& adjSeed,
216 std::vector<std::vector<MX> >& adjSens)
const;
219 std::vector<MX> symbolic_output(
const std::vector<MX>& arg)
const override;
225 casadi_int* iw,
bvec_t* w,
void* mem)
const override;
230 int sp_reverse(
bvec_t** arg,
bvec_t** res, casadi_int* iw,
bvec_t* w,
void* mem)
const override;
233 std::string print(
const AlgEl& el)
const;
236 void print_arg(std::ostream &stream, casadi_int k,
const AlgEl& el,
const double** arg)
const;
239 void print_arg(
CodeGenerator& g, casadi_int k,
const AlgEl& el,
240 const std::vector<casadi_int>& arg,
const std::vector<bool>& arg_is_ref)
const;
243 void print_res(std::ostream &stream, casadi_int k,
const AlgEl& el,
double** res)
const;
246 void print_res(
CodeGenerator& g, casadi_int k,
const AlgEl& el,
247 const std::vector<casadi_int>& res,
const std::vector<bool>& res_is_ref)
const;
253 const MX mx_in(casadi_int ind)
const override;
254 const std::vector<MX> mx_in()
const override;
258 std::vector<MX>
free_mx()
const override {
return free_vars_;}
263 bool has_free()
const override {
return !free_vars_.empty();}
268 std::vector<std::string>
get_free()
const override {
269 std::vector<std::string> ret;
270 for (
auto&& e : free_vars_) ret.push_back(e.name());
277 casadi_int
n_nodes()
const override {
return algorithm_.size();}
284 MX instruction_MX(casadi_int k)
const override;
289 casadi_int
instruction_id(casadi_int k)
const override {
return algorithm_.at(k).op;}
294 double get_default_in(casadi_int ind)
const override {
return default_in_.at(ind);}
299 std::vector<casadi_int> instruction_input(casadi_int k)
const override;
304 std::vector<casadi_int> instruction_output(casadi_int k)
const override;
309 void export_code_body(
const std::string& lang,
310 std::ostream &stream,
const Dict& options)
const override;
313 void substitute_inplace(std::vector<MX>& vdef, std::vector<MX>& ex)
const;
316 void find(std::map<FunctionInternal*, Function>& all_fun, casadi_int max_depth)
const override;
321 void change_option(
const std::string& option_name,
const GenericType& option_value)
override;
Helper class for C code generation.
Helper class for Serialization.
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
Internal node class for MXFunction.
static const Options options_
Options.
std::vector< casadi_int > workloc_
Offsets for elements in the w_ vector.
bool live_variables_
Live variables?
std::vector< double > default_in_
Default input values.
casadi_int instruction_id(casadi_int k) const override
Get an atomic operation operator index.
double get_default_in(casadi_int ind) const override
Get default input value.
casadi_int n_nodes() const override
Number of nodes in the algorithm.
std::vector< bool > workstate_
std::vector< std::string > get_free() const override
Print free variables.
bool has_free() const override
Does the function have free variables.
bool print_instructions_
Print instructions during evaluation.
MXAlgEl AlgEl
An element of the algorithm, namely an MX node.
casadi_int n_instructions() const override
Get the number of atomic operations.
std::vector< AlgEl > algorithm_
All the runtime elements in the order of evaluation.
const Options & get_options() const override
Options.
std::vector< MX > free_mx() const override
Get free variables (MX)
std::vector< MX > free_vars_
Free variables.
std::string class_name() const override
Get type name.
Base class for FunctionInternal and LinsolInternal.
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
Internal node class for the base class of SXFunction and MXFunction.
unsigned long long bvec_t
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros
std::vector< MX > MXVector
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
An element of the algorithm, namely an MX node.
MX data
Data associated with the operation.
std::vector< casadi_int > arg
Work vector indices of the arguments.
casadi_int op
Operator index.
std::vector< casadi_int > res
Work vector indices of the results.
Options metadata for a class.