26 #ifndef CASADI_SX_FUNCTION_HPP
27 #define CASADI_SX_FUNCTION_HPP
29 #include "x_function.hpp"
54 public XFunction<SXFunction, Matrix<SXElem>, SXNode>{
62 const std::vector<std::string>& name_in,
63 const std::vector<std::string>& name_out);
73 int eval(
const double** arg,
double** res, casadi_int* iw,
double* w,
void* mem)
const override;
79 casadi_int* iw,
SXElem* w,
void* mem,
80 bool always_inline,
bool never_inline)
const override;
86 bool always_inline,
bool never_inline)
const override;
89 bool should_inline(
bool with_sx,
bool always_inline,
bool never_inline)
const override;
94 void ad_forward(
const std::vector<std::vector<SX> >& fseed,
95 std::vector<std::vector<SX> >& fsens)
const;
100 void ad_reverse(
const std::vector<std::vector<SX> >& aseed,
101 std::vector<std::vector<SX> >& asens)
const;
106 bool is_smooth()
const;
112 void print_arg(std::ostream &stream, casadi_int k,
const ScalarAtomic& el,
113 const double* w)
const;
119 void print_res(std::ostream &stream, casadi_int k,
const ScalarAtomic& el,
120 const double* w)
const;
128 void disp_more(std::ostream& stream)
const override;
133 std::string
class_name()
const override {
return "SXFunction";}
138 bool is_a(
const std::string& type,
bool recursive)
const override;
144 const SX sx_in(casadi_int ind)
const override;
145 const std::vector<SX> sx_in()
const override;
150 std::vector<SX> ret(free_vars_.size());
151 std::copy(free_vars_.begin(), free_vars_.end(), ret.begin());
158 bool has_free()
const override {
return !free_vars_.empty();}
163 std::vector<std::string>
get_free()
const override {
164 std::vector<std::string> ret;
165 for (
auto&& e : free_vars_) ret.push_back(e.name());
172 std::vector<std::string> get_function()
const override;
177 const Function& get_function(
const std::string &name)
const override;
182 SX hess(casadi_int iind=0, casadi_int oind=0);
192 casadi_int
instruction_id(casadi_int k)
const override {
return algorithm_.at(k).op;}
198 auto e = algorithm_.at(k);
201 return vector_static_cast<casadi_int>(m.
dep);
215 return algorithm_.at(k).d;
222 auto e = algorithm_.at(k);
225 return vector_static_cast<casadi_int>(m.
res);
236 casadi_int
n_nodes()
const override {
return algorithm_.size() - nnz_out();}
310 size_t sz_arg = 0, sz_res = 0, sz_iw = 0, sz_w = 0;
311 size_t sz_w_arg = 0, sz_w_res = 0;
312 std::vector<ExtendedAlgEl>
el;
320 static std::vector<SX> order(
const std::vector<SX>& expr);
331 Dict generate_options(
const std::string& target=
"clone")
const override;
336 void init(
const Dict& opts)
override;
341 void init_copy_elision();
362 casadi_int* iw,
bvec_t* w,
void* mem)
const override;
368 casadi_int* iw,
bvec_t* w,
void* mem)
const override;
373 int sp_reverse(
bvec_t** arg,
bvec_t** res, casadi_int* iw,
bvec_t* w,
void* mem)
const override;
378 SX instructions_sx()
const override;
382 casadi_int max_depth)
const override;
387 void change_option(
const std::string& option_name,
const GenericType& option_value)
override;
392 double get_default_in(casadi_int ind)
const override {
return default_in_.at(ind);}
397 void export_code_body(
const std::string& lang,
398 std::ostream &stream,
const Dict& options)
const override;
411 void call_fwd(
const AlgEl& e,
const T** arg, T** res, casadi_int* iw, T* w)
const;
415 casadi_int* iw,
bvec_t* w)
const;
418 void call_rev(
const AlgEl& e, T** arg, T** res, casadi_int* iw, T* w)
const;
420 template<
typename T,
typename CT>
422 CT*** call_arg, T*** call_res, casadi_int** call_iw, T** call_w, T** nz_in, T** nz_out)
const;
Helper class for C code generation.
Helper class for Serialization.
Internal class for Function.
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
Sparse matrix class. SX and DM are specializations.
Base class for FunctionInternal and LinsolInternal.
The basic scalar symbolic class of CasADi.
Internal node class for SXFunction.
std::vector< SXElem > operations_
The expressions corresponding to each binary operation.
std::string class_name() const override
Get type name.
SXFunction(const std::string &name, const std::vector< Matrix< SXElem > > &inputv, const std::vector< Matrix< SXElem > > &outputv, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out)
Constructor.
casadi_int n_nodes() const override
Number of nodes in the algorithm.
casadi_int instruction_id(casadi_int k) const override
Get an atomic operation operator index.
std::vector< SX > free_sx() const override
Get free variables (SX)
SX hess(casadi_int iind=0, casadi_int oind=0)
Hessian (forward over adjoint) via source code transformation.
static const Options options_
Options.
std::vector< bool > copy_elision_
Copy elision per algel.
ScalarAtomic AlgEl
DATA MEMBERS.
std::vector< casadi_int > instruction_output(casadi_int k) const override
Get the (integer) output argument of an atomic operation.
bool has_free() const override
Does the function have free variables.
double get_default_in(casadi_int ind) const override
Get default input value.
std::vector< SXElem > constants_
The expressions corresponding to each constant.
const Options & get_options() const override
Options.
bool just_in_time_opencl_
With just-in-time compilation using OpenCL.
std::vector< std::string > get_free() const override
Print free variables.
std::vector< AlgEl > algorithm_
all binary nodes of the tree in the order of execution
std::vector< SXElem > free_vars_
Free variables.
std::vector< double > default_in_
Default input values.
std::vector< casadi_int > instruction_input(casadi_int k) const override
Get the (integer) input arguments of an atomic operation.
double instruction_constant(casadi_int k) const override
Get the floating point output argument of an atomic operation.
bool print_instructions_
Print each operation during evaluation.
bool live_variables_
Live variables?
casadi_int n_instructions() const override
Get the number of atomic operations.
bool just_in_time_sparsity_
With just-in-time compilation for the sparsity propagation.
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.
Options metadata for a class.
std::vector< ExtendedAlgEl > el
std::vector< int > copy_elision_offset
std::vector< int > copy_elision_arg
std::vector< int > f_nnz_out
std::vector< int > f_nnz_in
An atomic operation for the SXElem virtual machine.
Easy access to all the functions for a particular type.