List of all members | Public Types | Public Member Functions | Static Public Member Functions
casadi::Callback Class Reference

Callback function functionality. More...

#include <callback.hpp>

Detailed Description

This class provides a public API to the FunctionInternal class that can be subclassed by the user, who is then able to implement the different virtual method. Note that the Function class also provides a public API to FunctionInternal, but only allows calling, not being called.

The user is responsible for not deleting this class for the lifetime of the internal function object.

Author
Joris Gillis, Joel Andersson
Date
2015
Examples:
Function/callback.py, Function/callback_c.cc, and misc/assertion.py.

Definition at line 48 of file casadi/core/callback.hpp.

Inheritance diagram for casadi::Callback:
Inheritance graph
[legend]

Public Types

typedef std::map< std::string,
std::vector< std::string > > 
AuxOut
 

Public Member Functions

 Callback ()
 Default constructor. More...
 
 Callback (const Callback &obj)
 Copy constructor (throws an error) More...
 
virtual ~Callback ()
 Destructor. More...
 
void construct (const std::string &name, const Dict &opts=Dict())
 Construct internal object This is the step that actually construct the internal object, as the class constructor only creates a null pointer. It should be called from the user constructor. More...
 
virtual void init ()
 Initialize the object This function is called after the object construction (for the whole class hierarchy) is complete, but before the finalization step. It is called recursively for the whole class hierarchy, starting with the lowest level. More...
 
virtual void finalize ()
 Finalize the object This function is called after the construction and init steps are completed, but before user functions are called. It is called recursively for the whole class hierarchy, starting with the highest level. More...
 
virtual std::vector< DMeval (const std::vector< DM > &arg) const
 Evaluate numerically, temporary matrices and work vectors. More...
 
virtual casadi_int get_n_in ()
 Get the number of inputs This function is called during construction. More...
 
virtual casadi_int get_n_out ()
 Get the number of outputs This function is called during construction. More...
 
virtual Sparsity get_sparsity_in (casadi_int i)
 Get the sparsity of an input This function is called during construction. More...
 
virtual Sparsity get_sparsity_out (casadi_int i)
 Get the sparsity of an output This function is called during construction. More...
 
virtual std::string get_name_in (casadi_int i)
 Get the sparsity of an input This function is called during construction. More...
 
virtual std::string get_name_out (casadi_int i)
 Get the sparsity of an output This function is called during construction. More...
 
virtual bool uses_output () const
 Do the derivative functions need nondifferentiated outputs? More...
 
casadi_int n_in () const
 Get the number of function inputs. More...
 
casadi_int n_out () const
 Get the number of function outputs. More...
 
const std::vector< std::string > & name_in () const
 Get input scheme. More...
 
const std::string & name_in (casadi_int ind) const
 Get input scheme name by index. More...
 
const std::vector< std::string > & name_out () const
 Get output scheme. More...
 
const std::string & name_out (casadi_int ind) const
 Get output scheme name by index. More...
 
casadi_int index_in (const std::string &name) const
 Find the index for a string describing a particular entry of an input scheme. More...
 
casadi_int index_out (const std::string &name) const
 Find the index for a string describing a particular entry of an output scheme. More...
 
double default_in (casadi_int ind) const
 Get default input value. More...
 
double max_in (casadi_int ind) const
 Get largest input value. More...
 
double min_in (casadi_int ind) const
 Get smallest input value. More...
 
Function factory (const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const AuxOut &aux=AuxOut(), const Dict &opts=Dict()) const
 
Function oracle () const
 Get oracle. More...
 
Function wrap () const
 Wrap in an Function instance consisting of only one MX call. More...
 
std::vector< bool > which_depends (const std::string &s_in, const std::vector< std::string > &s_out, casadi_int order=1, bool tr=false) const
 Which variables enter with some order. More...
 
void print_dimensions (std::ostream &stream=casadi::uout()) const
 Print dimensions of inputs and outputs. More...
 
void print_options (std::ostream &stream=casadi::uout()) const
 Print options to a stream. More...
 
void print_option (const std::string &name, std::ostream &stream=casadi::uout()) const
 Print all information there is to know about a certain option. More...
 
std::vector< MXmapsum (const std::vector< MX > &arg, const std::string &parallelization="serial") const
 Evaluate symbolically in parallel and sum (matrix graph) More...
 
Function map (casadi_int n, const std::string &parallelization="serial") const
 Create a mapped version of this function. More...
 
Function slice (const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts=Dict()) const
 returns a new function with a selection of inputs/outputs of the original More...
 
Function forward (casadi_int nfwd) const
 Get a function that calculates nfwd forward derivatives. More...
 
Function reverse (casadi_int nadj) const
 Get a function that calculates nadj adjoint derivatives. More...
 
std::string generate (const std::string &fname, const Dict &opts=Dict()) const
 Export / Generate C code for the function. More...
 
std::string generate (const Dict &opts=Dict()) const
 Export / Generate C code for the function. More...
 
std::string generate_dependencies (const std::string &fname, const Dict &opts=Dict()) const
 Export / Generate C code for the dependency function. More...
 
Dict stats (casadi_int mem=0) const
 Get all statistics obtained at the end of the last evaluate call. More...
 
bool has_free () const
 Does the function have free variables. More...
 
std::vector< std::string > get_free () const
 Get free variables as a string. More...
 
std::vector< SXfree_sx () const
 Get all the free variables of the function. More...
 
std::vector< MXfree_mx () const
 Get all the free variables of the function. More...
 
void generate_lifted (Function &output_vdef_fcn, Function &output_vinit_fcn) const
 Extract the functions needed for the Lifted Newton method. More...
 
casadi_int n_nodes () const
 Number of nodes in the algorithm. More...
 
casadi_int n_instructions () const
 Number of instruction in the algorithm (SXFunction/MXFunction) More...
 
casadi_int instruction_id (casadi_int k) const
 Identifier index of the instruction (SXFunction/MXFunction) More...
 
std::vector< casadi_int > instruction_input (casadi_int k) const
 Locations in the work vector for the inputs of the instruction (SXFunction/MXFunction) More...
 
double instruction_constant (casadi_int k) const
 Get the floating point output argument of an instruction (SXFunction) More...
 
std::vector< casadi_int > instruction_output (casadi_int k) const
 Location in the work vector for the output of the instruction (SXFunction/MXFunction) More...
 
MX instruction_MX (casadi_int k) const
 Get the MX node corresponding to an instruction (MXFunction) More...
 
size_t sz_arg () const
 Get required length of arg field. More...
 
size_t sz_res () const
 Get required length of res field. More...
 
size_t sz_iw () const
 Get required length of iw field. More...
 
size_t sz_w () const
 Get required length of w field. More...
 
std::string name () const
 Name of the function. More...
 
bool is_a (const std::string &type, bool recursive=true) const
 Check if the function is of a particular type Optionally check if name matches one of the base classes (default true) More...
 
void assert_size_in (casadi_int i, casadi_int nrow, casadi_int ncol) const
 Assert that an input dimension is equal so some given value. More...
 
void assert_size_out (casadi_int i, casadi_int nrow, casadi_int ncol) const
 Assert that an output dimension is equal so some given value. More...
 
casadi_int checkout () const
 Checkout a memory object. More...
 
void release (casadi_int mem) const
 Release a memory object. More...
 
std::vector< std::string > get_function () const
 
Function get_function (const std::string &name) const
 
bool has_function (const std::string &fname) const
 
Dict info () const
 
std::string class_name () const
 Get class name. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
bool is_null () const
 Is a null pointer? More...
 
size_t __hash__ () const
 Returns a number that is unique for a given Node. If the Object does not point to any node, "0" is returned. More...
 
virtual bool has_jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual Function get_jacobian (const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual bool has_forward (casadi_int nfwd) const
 Return function that calculates forward derivatives forward(nfwd) returns a cached instance if available, and calls Function get_forward(casadi_int nfwd) if no cached version is available. More...
 
virtual Function get_forward (casadi_int nfwd, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
 Return function that calculates forward derivatives forward(nfwd) returns a cached instance if available, and calls Function get_forward(casadi_int nfwd) if no cached version is available. More...
 
virtual bool has_reverse (casadi_int nadj) const
 Return function that calculates adjoint derivatives reverse(nadj) returns a cached instance if available, and calls Function get_reverse(casadi_int nadj) if no cached version is available. More...
 
virtual Function get_reverse (casadi_int nadj, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
 Return function that calculates adjoint derivatives reverse(nadj) returns a cached instance if available, and calls Function get_reverse(casadi_int nadj) if no cached version is available. More...
 
void alloc_w (size_t sz_w, bool persist=false)
 Allocate work vectors. More...
 
void alloc_iw (size_t sz_iw, bool persist=false)
 Allocate work vectors. More...
 
void alloc_arg (size_t sz_arg, bool persist=false)
 Allocate work vectors. More...
 
void alloc_res (size_t sz_res, bool persist=false)
 Allocate work vectors. More...
 
Function expand () const
 Expand a function to SX. More...
 
Function expand (const std::string &name, const Dict &opts=Dict()) const
 Expand a function to SX. More...
 
casadi_int size1_in (casadi_int ind) const
 Get input dimension. More...
 
casadi_int size1_in (const std::string &iname) const
 Get input dimension. More...
 
casadi_int size2_in (casadi_int ind) const
 Get input dimension. More...
 
casadi_int size2_in (const std::string &iname) const
 Get input dimension. More...
 
std::pair< casadi_int, casadi_int > size_in (casadi_int ind) const
 Get input dimension. More...
 
std::pair< casadi_int, casadi_int > size_in (const std::string &iname) const
 Get input dimension. More...
 
casadi_int size1_out (casadi_int ind) const
 Get output dimension. More...
 
casadi_int size1_out (const std::string &oname) const
 Get output dimension. More...
 
casadi_int size2_out (casadi_int ind) const
 Get output dimension. More...
 
casadi_int size2_out (const std::string &oname) const
 Get output dimension. More...
 
std::pair< casadi_int, casadi_int > size_out (casadi_int ind) const
 Get output dimension. More...
 
std::pair< casadi_int, casadi_int > size_out (const std::string &oname) const
 Get output dimension. More...
 
casadi_int nnz_in () const
 Get number of input nonzeros. More...
 
casadi_int nnz_in (casadi_int ind) const
 Get number of input nonzeros. More...
 
casadi_int nnz_in (const std::string &iname) const
 Get number of input nonzeros. More...
 
casadi_int nnz_out () const
 Get number of output nonzeros. More...
 
casadi_int nnz_out (casadi_int ind) const
 Get number of output nonzeros. More...
 
casadi_int nnz_out (const std::string &oname) const
 Get number of output nonzeros. More...
 
casadi_int numel_in () const
 Get number of input elements. More...
 
casadi_int numel_in (casadi_int ind) const
 Get number of input elements. More...
 
casadi_int numel_in (const std::string &iname) const
 Get number of input elements. More...
 
casadi_int numel_out () const
 Get number of output elements. More...
 
casadi_int numel_out (casadi_int ind) const
 Get number of output elements. More...
 
casadi_int numel_out (const std::string &oname) const
 Get number of output elements. More...
 
const Sparsitysparsity_in (casadi_int ind) const
 Get sparsity of a given input. More...
 
const Sparsitysparsity_in (const std::string &iname) const
 Get sparsity of a given input. More...
 
const Sparsitysparsity_out (casadi_int ind) const
 Get sparsity of a given output. More...
 
const Sparsitysparsity_out (const std::string &iname) const
 Get sparsity of a given output. More...
 
Function jacobian_old (casadi_int iind, casadi_int oind) const
 Generate a Jacobian function of output oind with respect to input iind. More...
 
Function hessian_old (casadi_int iind, casadi_int oind) const
 Generate a Hessian function of output oind with respect to input iind. More...
 
Function jacobian () const
 Generate a Jacobian function of all the inputs elements with respect to all the output elements). More...
 
void call (const std::vector< DM > &arg, std::vector< DM > &output_res, bool always_inline=false, bool never_inline=false) const
 Evaluate the function symbolically or numerically. More...
 
void call (const std::vector< SX > &arg, std::vector< SX > &output_res, bool always_inline=false, bool never_inline=false) const
 Generate a Jacobian function of output oind with respect to input iind. More...
 
void call (const std::vector< MX > &arg, std::vector< MX > &output_res, bool always_inline=false, bool never_inline=false) const
 Generate a Jacobian function of output oind with respect to input iind. More...
 
void call (const DMDict &arg, DMDict &output_res, bool always_inline=false, bool never_inline=false) const
 Generate a Jacobian function of output oind with respect to input iind. More...
 
void call (const SXDict &arg, SXDict &output_res, bool always_inline=false, bool never_inline=false) const
 Generate a Jacobian function of output oind with respect to input iind. More...
 
void call (const MXDict &arg, MXDict &output_res, bool always_inline=false, bool never_inline=false) const
 Generate a Jacobian function of output oind with respect to input iind. More...
 
Function mapaccum (const std::string &name, casadi_int n, const Dict &opts=Dict()) const
 Create a mapaccumulated version of this function. More...
 
Function mapaccum (const std::string &name, casadi_int n, casadi_int n_accum, const Dict &opts=Dict()) const
 Create a mapaccumulated version of this function. More...
 
Function mapaccum (const std::string &name, casadi_int n, const std::vector< casadi_int > &accum_in, const std::vector< casadi_int > &accum_out, const Dict &opts=Dict()) const
 Create a mapaccumulated version of this function. More...
 
Function mapaccum (const std::string &name, casadi_int n, const std::vector< std::string > &accum_in, const std::vector< std::string > &accum_out, const Dict &opts=Dict()) const
 Create a mapaccumulated version of this function. More...
 
Function map (const std::string &name, const std::string &parallelization, casadi_int n, const std::vector< casadi_int > &reduce_in, const std::vector< casadi_int > &reduce_out, const Dict &opts=Dict()) const
 Map with reduction A subset of the inputs are non-repeated and a subset of the outputs summed up. More...
 
Function map (const std::string &name, const std::string &parallelization, casadi_int n, const std::vector< std::string > &reduce_in, const std::vector< std::string > &reduce_out, const Dict &opts=Dict()) const
 Map with reduction A subset of the inputs are non-repeated and a subset of the outputs summed up. More...
 
const Sparsity sparsity_jac (casadi_int iind, casadi_int oind, bool compact=false, bool symmetric=false) const
 
const Sparsity sparsity_jac (const std::string &iind, casadi_int oind=0, bool compact=false, bool symmetric=false) const
 
const Sparsity sparsity_jac (casadi_int iind, const std::string &oind, bool compact=false, bool symmetric=false) const
 
const Sparsity sparsity_jac (const std::string &iind, const std::string &oind, bool compact=false, bool symmetric=false) const
 
void export_code (const std::string &lang, const std::string &fname, const Dict &options=Dict()) const
 Export function in specific language. More...
 
std::string export_code (const std::string &lang, const Dict &options=Dict()) const
 Export function in specific language. More...
 
const SX sx_in (casadi_int iind) const
 Get symbolic primitives equivalent to the input expressions There is no guarantee that subsequent calls return unique answers. More...
 
const SX sx_in (const std::string &iname) const
 Get symbolic primitives equivalent to the input expressions There is no guarantee that subsequent calls return unique answers. More...
 
const std::vector< SXsx_in () const
 Get symbolic primitives equivalent to the input expressions There is no guarantee that subsequent calls return unique answers. More...
 
const MX mx_in (casadi_int ind) const
 Get symbolic primitives equivalent to the input expressions There is no guarantee that subsequent calls return unique answers. More...
 
const MX mx_in (const std::string &iname) const
 Get symbolic primitives equivalent to the input expressions There is no guarantee that subsequent calls return unique answers. More...
 
const std::vector< MXmx_in () const
 Get symbolic primitives equivalent to the input expressions There is no guarantee that subsequent calls return unique answers. More...
 
const SX sx_out (casadi_int oind) const
 Get symbolic primitives equivalent to the output expressions There is no guarantee that subsequent calls return unique answers. More...
 
const SX sx_out (const std::string &oname) const
 Get symbolic primitives equivalent to the output expressions There is no guarantee that subsequent calls return unique answers. More...
 
const std::vector< SXsx_out () const
 Get symbolic primitives equivalent to the output expressions There is no guarantee that subsequent calls return unique answers. More...
 
const MX mx_out (casadi_int ind) const
 Get symbolic primitives equivalent to the output expressions There is no guarantee that subsequent calls return unique answers. More...
 
const MX mx_out (const std::string &oname) const
 Get symbolic primitives equivalent to the output expressions There is no guarantee that subsequent calls return unique answers. More...
 
const std::vector< MXmx_out () const
 Get symbolic primitives equivalent to the output expressions There is no guarantee that subsequent calls return unique answers. More...
 
bool has_spfwd () const
 Is the class able to propagate seeds through the algorithm? More...
 
bool has_sprev () const
 Is the class able to propagate seeds through the algorithm? More...
 

Static Public Member Functions

static std::string type_name ()
 Get type name. More...
 
static Function conditional (const std::string &name, const std::vector< Function > &f, const Function &f_def, const Dict &opts=Dict())
 Constuct a switch function. More...
 
static Function bspline (const std::string &name, const std::vector< std::vector< double > > &knots, const std::vector< double > &coeffs, const std::vector< casadi_int > &degree, casadi_int m=1, const Dict &opts=Dict())
 BSpline evaluator function. More...
 
static Function bspline_dual (const std::string &name, const std::vector< std::vector< double > > &knots, const std::vector< double > &x, const std::vector< casadi_int > &degree, casadi_int m=1, bool reverse=false, const Dict &opts=Dict())
 Dual BSpline evaluator function. More...
 
static Function if_else (const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
 Constructor (if-else) More...
 
static bool check_name (const std::string &name)
 Check if a string is a valid function name Valid function names consist of. More...
 
static std::string fix_name (const std::string &name)
 Turn a string into a valid function name as defined by "check_name" Non-alphanumeric characters are converted into underscores and multiple consecutive undercores are dropped. More...
 
static Function jit (const std::string &name, const std::string &body, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict())
 To resolve ambiguity on some compilers. More...
 
static Function jit (const std::string &name, const std::string &body, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const std::vector< Sparsity > &sparsity_in, const std::vector< Sparsity > &sparsity_out, const Dict &opts=Dict())
 To resolve ambiguity on some compilers. More...
 

Member Typedef Documentation

typedef std::map<std::string, std::vector<std::string> > casadi::Function::AuxOut
inherited

Definition at line 318 of file function.hpp.

Constructor & Destructor Documentation

casadi::Callback::Callback ( )
casadi::Callback::Callback ( const Callback obj)
virtual casadi::Callback::~Callback ( )
virtual

Member Function Documentation

size_t casadi::SharedObject::__hash__ ( ) const
inherited
void casadi::Callback::alloc_arg ( size_t  sz_arg,
bool  persist = false 
)
void casadi::Callback::alloc_iw ( size_t  sz_iw,
bool  persist = false 
)
void casadi::Callback::alloc_res ( size_t  sz_res,
bool  persist = false 
)
void casadi::Callback::alloc_w ( size_t  sz_w,
bool  persist = false 
)
void casadi::Function::assert_size_in ( casadi_int  i,
casadi_int  nrow,
casadi_int  ncol 
) const
inherited
void casadi::Function::assert_size_out ( casadi_int  i,
casadi_int  nrow,
casadi_int  ncol 
) const
inherited
static Function casadi::Function::bspline ( const std::string &  name,
const std::vector< std::vector< double > > &  knots,
const std::vector< double > &  coeffs,
const std::vector< casadi_int > &  degree,
casadi_int  m = 1,
const Dict opts = Dict() 
)
staticinherited

Requires a known coefficient tensor

static Function casadi::Function::bspline_dual ( const std::string &  name,
const std::vector< std::vector< double > > &  knots,
const std::vector< double > &  x,
const std::vector< casadi_int > &  degree,
casadi_int  m = 1,
bool  reverse = false,
const Dict opts = Dict() 
)
staticinherited

Requires known evaluation positions WARNING: This function may drastically change or be removed

void casadi::Function::call ( const std::vector< DM > &  arg,
std::vector< DM > &  output_res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited
void casadi::Function::call ( const std::vector< SX > &  arg,
std::vector< SX > &  output_res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::jacobian pre-CasADi 3.2
void casadi::Function::call ( const std::vector< MX > &  arg,
std::vector< MX > &  output_res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::jacobian pre-CasADi 3.2
void casadi::Function::call ( const DMDict arg,
DMDict output_res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::jacobian pre-CasADi 3.2
void casadi::Function::call ( const SXDict arg,
SXDict output_res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::jacobian pre-CasADi 3.2
void casadi::Function::call ( const MXDict arg,
MXDict output_res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::jacobian pre-CasADi 3.2
static bool casadi::Function::check_name ( const std::string &  name)
staticinherited
  • At least one character
  • Upper and lower case letters: a-zA-Z
  • Numbers 0-9, but never as first character
  • Underscore, but never as first character and never next to another underscore

May not be one of the following keywords: "null", "jac", "hess"

casadi_int casadi::Function::checkout ( ) const
inherited
std::string casadi::SharedObject::class_name ( ) const
inherited
static Function casadi::Function::conditional ( const std::string &  name,
const std::vector< Function > &  f,
const Function f_def,
const Dict opts = Dict() 
)
staticinherited
void casadi::Callback::construct ( const std::string &  name,
const Dict opts = Dict() 
)
double casadi::Function::default_in ( casadi_int  ind) const
inherited
void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited
virtual std::vector<DM> casadi::Callback::eval ( const std::vector< DM > &  arg) const
virtual
Function casadi::Function::expand ( ) const
inherited
Function casadi::Function::expand ( const std::string &  name,
const Dict opts = Dict() 
) const
inherited
void casadi::Function::export_code ( const std::string &  lang,
const std::string &  fname,
const Dict options = Dict() 
) const
inherited

Only allowed for (a subset of) SX/MX Functions

std::string casadi::Function::export_code ( const std::string &  lang,
const Dict options = Dict() 
) const
inherited

Only allowed for (a subset of) SX/MX Functions

Function casadi::Function::factory ( const std::string &  name,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const AuxOut aux = AuxOut(),
const Dict opts = Dict() 
) const
inherited
virtual void casadi::Callback::finalize ( )
inlinevirtual

Definition at line 83 of file casadi/core/callback.hpp.

static std::string casadi::Function::fix_name ( const std::string &  name)
staticinherited
Function casadi::Function::forward ( casadi_int  nfwd) const
inherited

Returns a function with n_in + n_out + n_in inputs and nfwd outputs. The first n_in inputs correspond to nondifferentiated inputs. The next n_out inputs correspond to nondifferentiated outputs. and the last n_in inputs correspond to forward seeds, stacked horizontally The n_out outputs correspond to forward sensitivities, stacked horizontally. * (n_in = n_in(), n_out = n_out())

The functions returned are cached, meaning that if called multiple timed with the same value, then multiple references to the same function will be returned.

std::vector<MX> casadi::Function::free_mx ( ) const
inherited
std::vector<SX> casadi::Function::free_sx ( ) const
inherited
std::string casadi::Function::generate ( const std::string &  fname,
const Dict opts = Dict() 
) const
inherited
Examples:
SX/generateCode.py.
std::string casadi::Function::generate ( const Dict opts = Dict()) const
inherited
std::string casadi::Function::generate_dependencies ( const std::string &  fname,
const Dict opts = Dict() 
) const
inherited
void casadi::Function::generate_lifted ( Function output_vdef_fcn,
Function output_vinit_fcn 
) const
inherited
virtual Function casadi::Callback::get_forward ( casadi_int  nfwd,
const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
virtual
std::vector<std::string> casadi::Function::get_free ( ) const
inherited
std::vector<std::string> casadi::Function::get_function ( ) const
inherited
Function casadi::Function::get_function ( const std::string &  name) const
inherited
virtual Function casadi::Callback::get_jacobian ( const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
virtual
virtual casadi_int casadi::Callback::get_n_in ( )
virtual
virtual casadi_int casadi::Callback::get_n_out ( )
virtual
virtual std::string casadi::Callback::get_name_in ( casadi_int  i)
virtual
virtual std::string casadi::Callback::get_name_out ( casadi_int  i)
virtual
virtual Function casadi::Callback::get_reverse ( casadi_int  nadj,
const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
virtual
virtual Sparsity casadi::Callback::get_sparsity_in ( casadi_int  i)
virtual
virtual Sparsity casadi::Callback::get_sparsity_out ( casadi_int  i)
virtual
std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 133 of file shared_object.hpp.

virtual bool casadi::Callback::has_forward ( casadi_int  nfwd) const
virtual
bool casadi::Function::has_free ( ) const
inherited
bool casadi::Function::has_function ( const std::string &  fname) const
inherited
virtual bool casadi::Callback::has_jacobian ( ) const
virtual
virtual bool casadi::Callback::has_reverse ( casadi_int  nadj) const
virtual
bool casadi::Function::has_spfwd ( ) const
inherited
bool casadi::Function::has_sprev ( ) const
inherited
Function casadi::Function::hessian_old ( casadi_int  iind,
casadi_int  oind 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::hessian pre-CasADi 3.2
static Function casadi::Function::if_else ( const std::string &  name,
const Function f_true,
const Function f_false,
const Dict opts = Dict() 
)
staticinherited
casadi_int casadi::Function::index_in ( const std::string &  name) const
inherited

example: schemeEntry("x_opt") -> returns NLPSOL_X if FunctionInternal adheres to SCHEME_NLPINput

casadi_int casadi::Function::index_out ( const std::string &  name) const
inherited

example: schemeEntry("x_opt") -> returns NLPSOL_X if FunctionInternal adheres to SCHEME_NLPINput

Dict casadi::Function::info ( ) const
inherited

Obtain information about function

virtual void casadi::Callback::init ( )
inlinevirtual

Definition at line 75 of file casadi/core/callback.hpp.

double casadi::Function::instruction_constant ( casadi_int  k) const
inherited
casadi_int casadi::Function::instruction_id ( casadi_int  k) const
inherited
std::vector<casadi_int> casadi::Function::instruction_input ( casadi_int  k) const
inherited
MX casadi::Function::instruction_MX ( casadi_int  k) const
inherited
std::vector<casadi_int> casadi::Function::instruction_output ( casadi_int  k) const
inherited
bool casadi::Function::is_a ( const std::string &  type,
bool  recursive = true 
) const
inherited
bool casadi::SharedObject::is_null ( ) const
inherited
Function casadi::Function::jacobian ( ) const
inherited
Function casadi::Function::jacobian_old ( casadi_int  iind,
casadi_int  oind 
) const
inherited
Parameters
iindThe index of the input
oindThe index of the output Legacy function: To be deprecated in a future version of CasADi. Exists only for compatibility with Function::jacobian pre-CasADi 3.2
static Function casadi::Function::jit ( const std::string &  name,
const std::string &  body,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const Dict opts = Dict() 
)
staticinherited

Create a just-in-time compiled function from a C language string The names and sparsity patterns of all the inputs and outputs must be provided. If sparsities are not provided, all inputs and outputs are assumed to be scalar. Only specify the function body, assuming that input and output nonzeros are stored in arrays with the specified naming convension. The data type used is 'casadi_real', which is typically equal to 'double` or another data type with the same API as 'double'.

Inputs may be null pointers. This means that the all entries are zero. Outputs may be null points. This means that the corresponding result can be ignored.

If an error occurs in the evaluation, issue "return 1;";

The final generated function will have a structure similar to:

casadi_int fname(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, void* mem) { const casadi_real *x1, *x2; casadi_real *r1, *r2; x1 = *arg++; x2 = *arg++; r1 = *res++; r2 = *res++; <FUNCTION_BODY> return 0; }

static Function casadi::Function::jit ( const std::string &  name,
const std::string &  body,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const std::vector< Sparsity > &  sparsity_in,
const std::vector< Sparsity > &  sparsity_out,
const Dict opts = Dict() 
)
staticinherited

Create a just-in-time compiled function from a C language string The names and sparsity patterns of all the inputs and outputs must be provided. If sparsities are not provided, all inputs and outputs are assumed to be scalar. Only specify the function body, assuming that input and output nonzeros are stored in arrays with the specified naming convension. The data type used is 'casadi_real', which is typically equal to 'double` or another data type with the same API as 'double'.

Inputs may be null pointers. This means that the all entries are zero. Outputs may be null points. This means that the corresponding result can be ignored.

If an error occurs in the evaluation, issue "return 1;";

The final generated function will have a structure similar to:

casadi_int fname(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, void* mem) { const casadi_real *x1, *x2; casadi_real *r1, *r2; x1 = *arg++; x2 = *arg++; r1 = *res++; r2 = *res++; <FUNCTION_BODY> return 0; }

Function casadi::Function::map ( casadi_int  n,
const std::string &  parallelization = "serial" 
) const
inherited

Suppose the function has a signature of:

   f: (a, p) -> ( s )

The the mapped version has the signature:

   F: (A, P) -> (S )

    with
        A: horzcat([a0, a1, ..., a_(N-1)])
        P: horzcat([p0, p1, ..., p_(N-1)])
        S: horzcat([s0, s1, ..., s_(N-1)])
    and
        s0 <- f(a0, p0)
        s1 <- f(a1, p1)
        ...
        s_(N-1) <- f(a_(N-1), p_(N-1))
Parameters
parallelizationType of parallelization used: unroll|serial|openmp
Function casadi::Function::map ( const std::string &  name,
const std::string &  parallelization,
casadi_int  n,
const std::vector< casadi_int > &  reduce_in,
const std::vector< casadi_int > &  reduce_out,
const Dict opts = Dict() 
) const
inherited
Function casadi::Function::map ( const std::string &  name,
const std::string &  parallelization,
casadi_int  n,
const std::vector< std::string > &  reduce_in,
const std::vector< std::string > &  reduce_out,
const Dict opts = Dict() 
) const
inherited
Function casadi::Function::mapaccum ( const std::string &  name,
casadi_int  n,
const Dict opts = Dict() 
) const
inherited

Suppose the function has a signature of:

   f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

   F: (x0, U) -> (X , Y )

    with
        U: horzcat([u0, u1, ..., u_(N-1)])
        X: horzcat([x1, x2, ..., x_N])
        Y: horzcat([y0, y1, ..., y_(N-1)])

    and
        x1, y0 <- f(x0, u0)
        x2, y1 <- f(x1, u1)
        ...
        x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for-loop:

  • much faster at construction time
  • potentially much faster compilation times (for codegen)
  • offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for-loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Function casadi::Function::mapaccum ( const std::string &  name,
casadi_int  n,
casadi_int  n_accum,
const Dict opts = Dict() 
) const
inherited

Suppose the function has a signature of:

   f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

   F: (x0, U) -> (X , Y )

    with
        U: horzcat([u0, u1, ..., u_(N-1)])
        X: horzcat([x1, x2, ..., x_N])
        Y: horzcat([y0, y1, ..., y_(N-1)])

    and
        x1, y0 <- f(x0, u0)
        x2, y1 <- f(x1, u1)
        ...
        x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for-loop:

  • much faster at construction time
  • potentially much faster compilation times (for codegen)
  • offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for-loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Function casadi::Function::mapaccum ( const std::string &  name,
casadi_int  n,
const std::vector< casadi_int > &  accum_in,
const std::vector< casadi_int > &  accum_out,
const Dict opts = Dict() 
) const
inherited

Suppose the function has a signature of:

   f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

   F: (x0, U) -> (X , Y )

    with
        U: horzcat([u0, u1, ..., u_(N-1)])
        X: horzcat([x1, x2, ..., x_N])
        Y: horzcat([y0, y1, ..., y_(N-1)])

    and
        x1, y0 <- f(x0, u0)
        x2, y1 <- f(x1, u1)
        ...
        x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for-loop:

  • much faster at construction time
  • potentially much faster compilation times (for codegen)
  • offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for-loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

Function casadi::Function::mapaccum ( const std::string &  name,
casadi_int  n,
const std::vector< std::string > &  accum_in,
const std::vector< std::string > &  accum_out,
const Dict opts = Dict() 
) const
inherited

Suppose the function has a signature of:

   f: (x, u) -> (x_next , y )

The the mapaccumulated version has the signature:

   F: (x0, U) -> (X , Y )

    with
        U: horzcat([u0, u1, ..., u_(N-1)])
        X: horzcat([x1, x2, ..., x_N])
        Y: horzcat([y0, y1, ..., y_(N-1)])

    and
        x1, y0 <- f(x0, u0)
        x2, y1 <- f(x1, u1)
        ...
        x_N, y_(N-1) <- f(x_(N-1), u_(N-1))

Mapaccum has the following benefits over writing an equivalent for-loop:

  • much faster at construction time
  • potentially much faster compilation times (for codegen)
  • offers a trade-off between memory and evaluation time

The base (settable through the options dictionary, default 10), is used to create a tower of function calls, containing unrolled for-loops of length maximum base.

This technique is much more scalable in terms of memory-usage, but slightly slower at evaluation, than a plain for-loop. The effect is similar to that of a for-loop with a check-pointing instruction after each chunk of iterations with size base.

Set base to -1 to unroll all the way; no gains in memory efficiency here.

std::vector<MX> casadi::Function::mapsum ( const std::vector< MX > &  arg,
const std::string &  parallelization = "serial" 
) const
inherited
Parameters
parallelizationType of parallelization used: unroll|serial|openmp
double casadi::Function::max_in ( casadi_int  ind) const
inherited
double casadi::Function::min_in ( casadi_int  ind) const
inherited
const MX casadi::Function::mx_in ( casadi_int  ind) const
inherited
const MX casadi::Function::mx_in ( const std::string &  iname) const
inlineinherited

Definition at line 721 of file function.hpp.

const std::vector<MX> casadi::Function::mx_in ( ) const
inherited
const MX casadi::Function::mx_out ( casadi_int  ind) const
inherited
const MX casadi::Function::mx_out ( const std::string &  oname) const
inlineinherited

Definition at line 737 of file function.hpp.

const std::vector<MX> casadi::Function::mx_out ( ) const
inherited
casadi_int casadi::Function::n_in ( ) const
inherited
casadi_int casadi::Function::n_instructions ( ) const
inherited
casadi_int casadi::Function::n_nodes ( ) const
inherited
casadi_int casadi::Function::n_out ( ) const
inherited
std::string casadi::Function::name ( ) const
inherited
const std::vector<std::string>& casadi::Function::name_in ( ) const
inherited
const std::string& casadi::Function::name_in ( casadi_int  ind) const
inherited
const std::vector<std::string>& casadi::Function::name_out ( ) const
inherited
const std::string& casadi::Function::name_out ( casadi_int  ind) const
inherited
casadi_int casadi::Function::nnz_in ( ) const
inherited

For a particular input or for all of the inputs

casadi_int casadi::Function::nnz_in ( casadi_int  ind) const
inherited

For a particular input or for all of the inputs

casadi_int casadi::Function::nnz_in ( const std::string &  iname) const
inlineinherited

For a particular input or for all of the inputs

Definition at line 237 of file function.hpp.

casadi_int casadi::Function::nnz_out ( ) const
inherited

For a particular output or for all of the outputs

casadi_int casadi::Function::nnz_out ( casadi_int  ind) const
inherited

For a particular output or for all of the outputs

casadi_int casadi::Function::nnz_out ( const std::string &  oname) const
inlineinherited

For a particular output or for all of the outputs

Definition at line 247 of file function.hpp.

casadi_int casadi::Function::numel_in ( ) const
inherited

For a particular input or for all of the inputs

casadi_int casadi::Function::numel_in ( casadi_int  ind) const
inherited

For a particular input or for all of the inputs

casadi_int casadi::Function::numel_in ( const std::string &  iname) const
inlineinherited

For a particular input or for all of the inputs

Definition at line 257 of file function.hpp.

casadi_int casadi::Function::numel_out ( ) const
inherited

For a particular output or for all of the outputs

casadi_int casadi::Function::numel_out ( casadi_int  ind) const
inherited

For a particular output or for all of the outputs

casadi_int casadi::Function::numel_out ( const std::string &  oname) const
inlineinherited

For a particular output or for all of the outputs

Definition at line 267 of file function.hpp.

Function casadi::Function::oracle ( ) const
inherited
void casadi::Function::print_dimensions ( std::ostream &  stream = casadi::uout()) const
inherited
void casadi::Function::print_option ( const std::string &  name,
std::ostream &  stream = casadi::uout() 
) const
inherited
void casadi::Function::print_options ( std::ostream &  stream = casadi::uout()) const
inherited
void casadi::Function::release ( casadi_int  mem) const
inherited
Function casadi::Function::reverse ( casadi_int  nadj) const
inherited

Returns a function with n_in + n_out + n_out inputs and n_in outputs. The first n_in inputs correspond to nondifferentiated inputs. The next n_out inputs correspond to nondifferentiated outputs. and the last n_out inputs correspond to adjoint seeds, stacked horizontally The n_in outputs correspond to adjoint sensitivities, stacked horizontally. * (n_in = n_in(), n_out = n_out())

(n_in = n_in(), n_out = n_out())

The functions returned are cached, meaning that if called multiple timed with the same value, then multiple references to the same function will be returned.

casadi_int casadi::Function::size1_in ( casadi_int  ind) const
inherited
casadi_int casadi::Function::size1_in ( const std::string &  iname) const
inlineinherited

Definition at line 209 of file function.hpp.

casadi_int casadi::Function::size1_out ( casadi_int  ind) const
inherited
casadi_int casadi::Function::size1_out ( const std::string &  oname) const
inlineinherited

Definition at line 221 of file function.hpp.

casadi_int casadi::Function::size2_in ( casadi_int  ind) const
inherited
casadi_int casadi::Function::size2_in ( const std::string &  iname) const
inlineinherited

Definition at line 211 of file function.hpp.

casadi_int casadi::Function::size2_out ( casadi_int  ind) const
inherited
casadi_int casadi::Function::size2_out ( const std::string &  oname) const
inlineinherited

Definition at line 223 of file function.hpp.

std::pair<casadi_int, casadi_int> casadi::Function::size_in ( casadi_int  ind) const
inherited
std::pair<casadi_int, casadi_int> casadi::Function::size_in ( const std::string &  iname) const
inlineinherited

Definition at line 213 of file function.hpp.

std::pair<casadi_int, casadi_int> casadi::Function::size_out ( casadi_int  ind) const
inherited
std::pair<casadi_int, casadi_int> casadi::Function::size_out ( const std::string &  oname) const
inlineinherited

Definition at line 225 of file function.hpp.

Function casadi::Function::slice ( const std::string &  name,
const std::vector< casadi_int > &  order_in,
const std::vector< casadi_int > &  order_out,
const Dict opts = Dict() 
) const
inherited
const Sparsity& casadi::Function::sparsity_in ( casadi_int  ind) const
inherited
const Sparsity& casadi::Function::sparsity_in ( const std::string &  iname) const
inherited
const Sparsity casadi::Function::sparsity_jac ( casadi_int  iind,
casadi_int  oind,
bool  compact = false,
bool  symmetric = false 
) const
inherited

Get, if necessary generate, the sparsity of a Jacobian block

const Sparsity casadi::Function::sparsity_jac ( const std::string &  iind,
casadi_int  oind = 0,
bool  compact = false,
bool  symmetric = false 
) const
inlineinherited

Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 650 of file function.hpp.

const Sparsity casadi::Function::sparsity_jac ( casadi_int  iind,
const std::string &  oind,
bool  compact = false,
bool  symmetric = false 
) const
inlineinherited

Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 654 of file function.hpp.

const Sparsity casadi::Function::sparsity_jac ( const std::string &  iind,
const std::string &  oind,
bool  compact = false,
bool  symmetric = false 
) const
inlineinherited

Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 658 of file function.hpp.

const Sparsity& casadi::Function::sparsity_out ( casadi_int  ind) const
inherited
const Sparsity& casadi::Function::sparsity_out ( const std::string &  iname) const
inherited
Dict casadi::Function::stats ( casadi_int  mem = 0) const
inherited
const SX casadi::Function::sx_in ( casadi_int  iind) const
inherited
const SX casadi::Function::sx_in ( const std::string &  iname) const
inlineinherited

Definition at line 716 of file function.hpp.

const std::vector<SX> casadi::Function::sx_in ( ) const
inherited
const SX casadi::Function::sx_out ( casadi_int  oind) const
inherited
const SX casadi::Function::sx_out ( const std::string &  oname) const
inlineinherited

Definition at line 732 of file function.hpp.

const std::vector<SX> casadi::Function::sx_out ( ) const
inherited
size_t casadi::Function::sz_arg ( ) const
inherited
size_t casadi::Function::sz_iw ( ) const
inherited
size_t casadi::Function::sz_res ( ) const
inherited
size_t casadi::Function::sz_w ( ) const
inherited
static std::string casadi::Callback::type_name ( )
inlinestatic

Definition at line 51 of file casadi/core/callback.hpp.

virtual bool casadi::Callback::uses_output ( ) const
virtual
std::vector<bool> casadi::Function::which_depends ( const std::string &  s_in,
const std::vector< std::string > &  s_out,
casadi_int  order = 1,
bool  tr = false 
) const
inherited
Parameters
[in]orderOnly 1 (linear) and 2 (nonlinear) allowed
[in]trFlip the relationship. Return which expressions contain the variables
Function casadi::Function::wrap ( ) const
inherited

The documentation for this class was generated from the following file:
Release pointers: extensive python examples, Users Guide (pdf | html )
Official releases: 3.3.0 3.2.3 3.1.1 3.0.0 2.4.2 2.3.0 2.2.0 2.1.1 2.0.0 1.9.0 1.8.0 1.7.1 1.7.0 1.6.1 1.6.0 1.5.0 1.4.0 1.3.0 bleeding edge