List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected 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

Extra doc: https://github.com/casadi/casadi/wiki/L_o0

Examples
Function/callback.py, and misc/assertion.py.

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

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

Public Types

typedef std::map< std::string, std::vector< std::string > > AuxOut
 
using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

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. More...
 
virtual void init ()
 Initialize the object. More...
 
virtual void finalize ()
 Finalize the object. More...
 
virtual std::vector< DMeval (const std::vector< DM > &arg) const
 Evaluate numerically, using temporary matrices and work vectors. More...
 
virtual int eval_buffer (const double **arg, const std::vector< casadi_int > &sizes_arg, double **res, const std::vector< casadi_int > &sizes_res) const
 A copy-free low level interface. More...
 
virtual bool has_eval_buffer () const
 Does the Callback class support a copy-free low level interface ? More...
 
virtual casadi_int get_n_in ()
 Get the number of inputs. More...
 
virtual casadi_int get_n_out ()
 Get the number of outputs. More...
 
virtual Sparsity get_sparsity_in (casadi_int i)
 Get the sparsity of an input. More...
 
virtual Sparsity get_sparsity_out (casadi_int i)
 Get the sparsity of an output. More...
 
virtual std::string get_name_in (casadi_int i)
 Get the name of an input. More...
 
virtual std::string get_name_out (casadi_int i)
 Get the name of an output. More...
 
virtual bool uses_output () const
 Do the derivative functions need nondifferentiated outputs? More...
 
virtual Function get_factory (const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux, const Dict &opts) const
 Customize calls to the function factory. 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...
 
std::vector< bool > activity (const std::vector< bool > &arg) const
 Output signal activity induced by a given input activity. 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...
 
bool has_in (const std::string &name) const
 Does the function have a particularly named input? More...
 
bool has_out (const std::string &name) const
 Does the function have a particularly named output? 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...
 
std::vector< double > nominal_in (casadi_int ind) const
 Get nominal input value. More...
 
std::vector< double > nominal_out (casadi_int ind) const
 Get nominal output 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...
 
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...
 
bool has_option (const std::string &option_name) const
 Does a particular option exist. More...
 
void change_option (const std::string &option_name, const GenericType &option_value)
 Change option after object creation for debugging. More...
 
void reset_dump_count ()
 Reset the counter used to name dump files. More...
 
Function jacobian_old (casadi_int iind, casadi_int oind) const
 [DEPRECATED] Replaced by Function::factory. More...
 
Function hessian_old (casadi_int iind, casadi_int oind) const
 [DEPRECATED] Replaced by Function::factory. More...
 
Function jacobian () const
 Calculate all Jacobian blocks. More...
 
bool operator== (const Function &f) const
 Check if same as another function. More...
 
int operator() (const double **arg, double **res, casadi_int *iw, double *w, int mem) const
 Evaluate memory-less, numerically. More...
 
int operator() (const double **arg, double **res, casadi_int *iw, double *w) const
 Evaluate numerically with checkout/release. More...
 
int operator() (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, int mem=0) const
 Evaluate memory-less SXElem. More...
 
int operator() (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, int mem=0) const
 Propagate sparsity forward. More...
 
template<typename M >
void call_gen (const std::map< std::string, M > &arg, std::map< std::string, M > &res, bool always_inline, bool never_inline) const
 Call using a map. More...
 
int eval_activity (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, int mem=0) const
 Propagate signal activity forward (bit set = active (possibly nonzero)) More...
 
int rev (bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, int mem=0) const
 Propagate sparsity backward. More...
 
int rev (std::vector< bvec_t * > arg, std::vector< bvec_t * > res) const
 Propagate sparsity backward with temporary memory allocation. More...
 
std::vector< MXmapsum (const std::vector< MX > &x, 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 map (casadi_int n, const std::string &parallelization, casadi_int max_num_threads) const
 
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...
 
const std::vector< Sparsity > & jac_sparsity (bool compact=false) const
 Get, if necessary generate, the sparsity of all Jacobian blocks. More...
 
Sparsity jac_sparsity (casadi_int oind, casadi_int iind, bool compact=false) const
 Get, if necessary generate, the sparsity of a single Jacobian block. 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...
 
FunctionInternalget () const
 
template<typename T >
T * get () const
 Get a pointer and typecast. More...
 
FunctionInternaloperator-> () const
 Const access functions of the node. More...
 
Dict stats (int mem=0) const
 Get all statistics obtained at the end of the last evaluate call. More...
 
template<>
const SX CASADI_EXPORT sym_in (casadi_int iind) const
 
template<>
const std::vector< SX > CASADI_EXPORT sym_in () const
 
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 &vdef_fcn, Function &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. 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. More...
 
MX instruction_MX (casadi_int k) const
 Get the MX node corresponding to an instruction (MXFunction) More...
 
SX instructions_sx () const
 Get the SX node corresponding to all instructions (SXFunction) 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...
 
void sz_work (size_t &sz_arg, size_t &sz_res, size_t &sz_iw, size_t &sz_w) const
 Get number of temporary variables needed. More...
 
void set_work (const double **&arg, double **&res, casadi_int *&iw, double *&w, int mem=0) const
 Set the (persistent) work vectors. More...
 
void set_temp (const double **arg, double **res, casadi_int *iw, double *w, int mem=0) const
 Set the (temporary) work vectors. More...
 
void setup (const double **arg, double **res, casadi_int *iw, double *w, int mem=0) const
 Set the (persistent and temporary) work vectors. More...
 
void merge (const std::vector< MX > &arg, std::vector< MX > &subs_from, std::vector< MX > &subs_to) const
 List merge opportunitities. More...
 
const 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. 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...
 
void assert_sparsity_out (casadi_int i, const Sparsity &sp, casadi_int n=1, bool allow_all_zero_sparse=true) const
 Assert that an output sparsity is a multiple of some given sparsity. More...
 
casadi_int checkout () const
 Checkout a memory object. More...
 
void release (int mem) const
 Release a memory object. More...
 
void * memory (int ind) const
 Get memory object. More...
 
Dict cache () const
 Get all functions in the cache. More...
 
std::vector< std::string > get_function () const
 Get a list of all functions. More...
 
Function get_function (const std::string &name) const
 Get a dependency function. More...
 
bool has_function (const std::string &fname) const
 Check if a particular dependency exists. More...
 
std::vector< Functionfind_functions (casadi_int max_depth=-1) const
 Get all functions embedded in the expression graphs. More...
 
Function find_function (const std::string &name, casadi_int max_depth=-1) const
 Get a specific function embedded in the expression graphs. More...
 
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...
 
void print_ptr (std::ostream &stream=casadi::uout()) const
 
void own (SharedObjectInternal *node)
 
void assign (SharedObjectInternal *node)
 Assign the node to a node class pointer without reference counting. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. 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. 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. More...
 
virtual bool has_reverse (casadi_int nadj) const
 Return function that calculates adjoint derivatives. 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. More...
 
virtual bool has_jac_sparsity (casadi_int oind, casadi_int iind) const
 Return sparsity of Jacobian of all input elements. More...
 
virtual Sparsity get_jac_sparsity (casadi_int oind, casadi_int iind, bool symmetric) const
 Return sparsity of Jacobian of all input elements. 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...
 
Function transform (const Dict &opts=Dict()) const
 Apply transformation passes. More...
 
Function transform (const std::string &fname, const Dict &opts=Dict()) const
 Apply transformation passes. More...
 
Function transform (const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) const
 Apply transformation passes. More...
 
Function transform (const std::string &fname, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) const
 Apply transformation passes. 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...
 
bool is_diff_in (casadi_int ind) const
 Get differentiability of inputs/output. More...
 
std::vector< bool > is_diff_in () const
 Get differentiability of inputs/output. More...
 
bool is_diff_out (casadi_int ind) const
 Get differentiability of inputs/output. More...
 
std::vector< bool > is_diff_out () const
 Get differentiability of inputs/output. More...
 
Function wrap () const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap (const std::string &name) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const Dict &opts) const
 Wrap in a Function with options. More...
 
Function wrap_as_needed (const std::string &name, const Dict &opts) const
 Wrap in a Function with options. 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 call (const std::vector< DM > &arg, std::vector< DM > &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 > &res, bool always_inline=false, bool never_inline=false) const
 Evaluate the function symbolically or numerically. More...
 
void call (const std::vector< MX > &arg, std::vector< MX > &res, bool always_inline=false, bool never_inline=false) const
 Evaluate the function symbolically or numerically. More...
 
void call (const DMDict &arg, DMDict &res, bool always_inline=false, bool never_inline=false) const
 Evaluate the function symbolically or numerically. More...
 
void call (const SXDict &arg, SXDict &res, bool always_inline=false, bool never_inline=false) const
 Evaluate the function symbolically or numerically. More...
 
void call (const MXDict &arg, MXDict &res, bool always_inline=false, bool never_inline=false) const
 Evaluate the function symbolically or numerically. More...
 
std::vector< DMoperator() (const std::vector< DM > &arg) const
 
std::vector< SXoperator() (const std::vector< SX > &arg) const
 
std::vector< MXoperator() (const std::vector< MX > &arg) const
 
const DMDict operator() (const DMDict &arg) const
 
const SXDict operator() (const SXDict &arg) const
 
const MXDict operator() (const MXDict &arg) const
 
void operator() (std::vector< const double * > arg, std::vector< double * > res) const
 Evaluate with temporary memory allocation. More...
 
void operator() (std::vector< const bvec_t * > arg, std::vector< bvec_t * > res) const
 Evaluate with temporary memory allocation. More...
 
void operator() (std::vector< const SXElem * > arg, std::vector< SXElem * > res) const
 Evaluate with temporary memory allocation. More...
 
template<typename D >
void call_gen (std::vector< const D * > arg, std::vector< D * > res) const
 Evaluate with temporary memory allocation. More...
 
void operator() (VecArg arg, VecRes res) const
 Numerical evaluation. More...
 
void operator() (VecArg arg, MapRes res) const
 Numerical evaluation. More...
 
void operator() (VecArg arg, VPrRes res) const
 Numerical evaluation. More...
 
void operator() (VecArg arg, MPrRes res) const
 Numerical evaluation. More...
 
void operator() (MapArg arg, VecRes res) const
 Numerical evaluation. More...
 
void operator() (MapArg arg, MapRes res) const
 Numerical evaluation. More...
 
void operator() (MapArg arg, VPrRes res) const
 Numerical evaluation. More...
 
void operator() (MapArg arg, MPrRes res) const
 Numerical evaluation. More...
 
std::vector< DMoperator() (const DM &arg0) const
 
std::vector< SXoperator() (const SX &arg0) const
 
std::vector< MXoperator() (const MX &arg0) const
 
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 mapaccum (casadi_int N, const Dict &opts=Dict()) const
 Create a mapaccumulated version of this function. More...
 
Function fold (casadi_int N, 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. 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. More...
 
Function map (casadi_int n, const std::vector< bool > &reduce_in, const std::vector< bool > &reduce_out=std::vector< bool >(), const Dict &opts=Dict()) const
 Map with reduction. More...
 
void generate_in (const std::string &fname, const std::vector< DM > &arg)
 Export an input file that can be passed to generate C code with a main. More...
 
std::vector< DMgenerate_in (const std::string &fname)
 Export an input file that can be passed to generate C code with a main. More...
 
void generate_out (const std::string &fname, const std::vector< DM > &arg)
 Export an output file that can be checked with generated C code output. More...
 
std::vector< DMgenerate_out (const std::string &fname)
 Export an output file that can be checked with generated C code output. More...
 
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...
 
void export_code (const std::string &lang, std::ostream &stream, const Dict &options=Dict()) const
 Export function in specific language. More...
 
void serialize (std::ostream &stream, const Dict &opts=Dict()) const
 Serialize. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
std::string serialize (const Dict &opts=Dict()) const
 Serialize. More...
 
void save (const std::string &fname, const Dict &opts=Dict()) const
 Save Function to a file. More...
 
const SX sx_in (casadi_int iind) const
 Get symbolic primitives equivalent to the input expressions. More...
 
const SX sx_in (const std::string &iname) const
 Get symbolic primitives equivalent to the input expressions. More...
 
const std::vector< SXsx_in () const
 Get symbolic primitives equivalent to the input expressions. More...
 
const MX mx_in (casadi_int ind) const
 Get symbolic primitives equivalent to the input expressions. More...
 
const MX mx_in (const std::string &iname) const
 Get symbolic primitives equivalent to the input expressions. More...
 
const std::vector< MXmx_in () const
 Get symbolic primitives equivalent to the input expressions. More...
 
template<typename T >
const T sym_in (casadi_int iind) const
 Get symbolic primitives equivalent to the input expressions. More...
 
template<typename T >
const T sym_in (const std::string &iname) const
 Get symbolic primitives equivalent to the input expressions. More...
 
template<typename T >
const std::vector< T > sym_in () const
 Get symbolic primitives equivalent to the input expressions. More...
 
const SX sx_out (casadi_int oind) const
 Get symbolic primitives equivalent to the output expressions. More...
 
const SX sx_out (const std::string &oname) const
 Get symbolic primitives equivalent to the output expressions. More...
 
const std::vector< SXsx_out () const
 Get symbolic primitives equivalent to the output expressions. More...
 
const MX mx_out (casadi_int ind) const
 Get symbolic primitives equivalent to the output expressions. More...
 
const MX mx_out (const std::string &oname) const
 Get symbolic primitives equivalent to the output expressions. More...
 
const std::vector< MXmx_out () const
 Get symbolic primitives equivalent to the output expressions. More...
 
std::vector< double > nz_from_in (const std::vector< DM > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< double > nz_from_out (const std::vector< DM > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DMnz_to_in (const std::vector< double > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DMnz_to_out (const std::vector< double > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
DMDict convert_in (const std::vector< DM > &arg) const
 Convert from/to input/output lists/map. More...
 
std::vector< DMconvert_in (const DMDict &arg) const
 Convert from/to input/output lists/map. More...
 
SXDict convert_in (const std::vector< SX > &arg) const
 Convert from/to input/output lists/map. More...
 
std::vector< SXconvert_in (const SXDict &arg) const
 Convert from/to input/output lists/map. More...
 
MXDict convert_in (const std::vector< MX > &arg) const
 Convert from/to input/output lists/map. More...
 
std::vector< MXconvert_in (const MXDict &arg) const
 Convert from/to input/output lists/map. More...
 
DMDict convert_out (const std::vector< DM > &arg) const
 Convert from/to input/output lists/map. More...
 
std::vector< DMconvert_out (const DMDict &arg) const
 Convert from/to input/output lists/map. More...
 
SXDict convert_out (const std::vector< SX > &arg) const
 Convert from/to input/output lists/map. More...
 
std::vector< SXconvert_out (const SXDict &arg) const
 Convert from/to input/output lists/map. More...
 
MXDict convert_out (const std::vector< MX > &arg) const
 Convert from/to input/output lists/map. More...
 
std::vector< MXconvert_out (const MXDict &arg) const
 Convert from/to input/output lists/map. 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 create (FunctionInternal *node)
 Create from node. More...
 
static Function create (FunctionInternal *node, const Dict &opts)
 Create from node and initialize. 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 conditional (const std::string &name, const Function &f, const Dict &opts=Dict())
 Conditional call to a 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 if_else (const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
 Constructor (if-else) More...
 
static bool test_cast (const SharedObjectInternal *ptr)
 Check if a particular cast is allowed. More...
 
static bool check_name (const std::string &name)
 Check if a string is a valid function name. More...
 
static std::string fix_name (const std::string &name)
 Turn a string into a valid function name as defined by "check_name". More...
 
static Function deserialize (std::istream &stream)
 Build function from serialization. More...
 
static Function deserialize (const std::string &s)
 Build function from serialization. More...
 
static Function deserialize (DeserializingStream &s)
 Build function from serialization. More...
 
static Function load (const std::string &filename)
 Build function from serialization. More...
 
static std::vector< SXorder (const std::vector< SX > &expr)
 
static std::vector< MXorder (const std::vector< MX > &expr)
 
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())
 Create a just-in-time compiled function from a C language string. 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())
 Create a just-in-time compiled function from a C language string. More...
 

Protected Member Functions

Function mapaccum (const std::string &name, const std::vector< Function > &chain, casadi_int n_accum=1, const Dict &opts=Dict()) const
 Helper function for mapaccum. More...
 
void count_up ()
 
void count_down ()
 
void construct (const std::string &name, const std::vector< SX > &ex_in, const std::vector< SX > &ex_out, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts)
 Called by constructors. More...
 
void construct (const std::string &name, const std::vector< MX > &ex_in, const std::vector< MX > &ex_out, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts)
 Called by constructors. More...
 
template<typename M >
void construct (const std::string &name, const std::map< std::string, M > &dict, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts)
 Called by constructors. More...
 

Static Protected Member Functions

static bool proceed_to (std::istream &file, const std::string &str)
 Helper function for parsing .casadi files. More...
 
std::vector< const double * > buf_in (VecArg arg) const
 Supported arguments for numerical evaluation and converters. More...
 
std::vector< const double * > buf_in (MapArg arg) const
 Supported arguments for numerical evaluation and converters. More...
 
std::vector< double * > buf_out (VecRes res) const
 Supported arguments for numerical evaluation and converters. More...
 
std::vector< double * > buf_out (VPrRes res) const
 Supported arguments for numerical evaluation and converters. More...
 
std::vector< double * > buf_out (MapRes res) const
 Supported arguments for numerical evaluation and converters. More...
 
std::vector< double * > buf_out (MPrRes res) const
 Supported arguments for numerical evaluation and converters. More...
 
typedef const std::vector< std::vector< double > > & VecArg
 Supported arguments for numerical evaluation and converters. More...
 
typedef std::vector< std::vector< double > > & VecRes
 Supported arguments for numerical evaluation and converters. More...
 
typedef std::vector< std::vector< double > * > VPrRes
 Supported arguments for numerical evaluation and converters. More...
 
typedef const std::map< std::string, std::vector< double > > & MapArg
 Supported arguments for numerical evaluation and converters. More...
 
typedef std::map< std::string, std::vector< double > > & MapRes
 Supported arguments for numerical evaluation and converters. More...
 
typedef std::map< std::string, std::vector< double > * > MPrRes
 Supported arguments for numerical evaluation and converters. More...
 

Member Typedef Documentation

◆ AuxOut

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

Definition at line 447 of file function.hpp.

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

◆ MapArg

typedef const std::map<std::string, std::vector<double> >& casadi::Function::MapArg
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 626 of file function.hpp.

◆ MapRes

typedef std::map<std::string, std::vector<double> >& casadi::Function::MapRes
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 628 of file function.hpp.

◆ MPrRes

typedef std::map<std::string, std::vector<double>*> casadi::Function::MPrRes
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 630 of file function.hpp.

◆ VecArg

typedef const std::vector<std::vector<double> >& casadi::Function::VecArg
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 619 of file function.hpp.

◆ VecRes

typedef std::vector<std::vector<double> >& casadi::Function::VecRes
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 621 of file function.hpp.

◆ VPrRes

typedef std::vector<std::vector<double>*> casadi::Function::VPrRes
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 623 of file function.hpp.

Constructor & Destructor Documentation

◆ Callback() [1/2]

casadi::Callback::Callback ( )

Extra doc: https://github.com/casadi/casadi/wiki/L_o2

Definition at line 29 of file callback.cpp.

29  {
30  }

◆ Callback() [2/2]

casadi::Callback::Callback ( const Callback obj)

Extra doc: https://github.com/casadi/casadi/wiki/L_o3

Definition at line 32 of file callback.cpp.

32  : Function() { // NOLINT
33  casadi_error("Callback objects cannot be copied");
34  }
Function()
Default constructor, null pointer.
Definition: function.cpp:58

◆ ~Callback()

casadi::Callback::~Callback ( )
virtual

Extra doc: https://github.com/casadi/casadi/wiki/L_o4

Definition at line 44 of file callback.cpp.

44  {
45  try {
46  // Make sure that this object isn't used after its deletion
47  if (!is_null()) get<CallbackInternal>()->self_ = nullptr;
48  } catch (...) {
49  casadi_warning("Problem in Callback destructor");
50  }
51  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__hash__
inherited

If the Object does not point to any node, "0" is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_av

Definition at line 123 of file generic_shared_impl.hpp.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ activity()

std::vector< bool > casadi::Function::activity ( const std::vector< bool > &  arg) const
inherited

arg is a flat activity mask over all input nonzeros (size nnz_in(), true = active = possibly nonzero); the result is the corresponding mask over all output nonzeros (size nnz_out()). An output that comes out inactive (false) is guaranteed zero for any value of the active inputs. Unlike sparsity propagation this exploits annihilation: an inactive operand of a multiply kills the product.

Extra doc: https://github.com/casadi/casadi/wiki/L_2ih

Definition at line 1269 of file function.cpp.

1269  {
1270  casadi_assert(arg.size()==static_cast<size_t>(nnz_in()),
1271  "activity: expected mask of size nnz_in()=" + str(nnz_in())
1272  + ", got " + str(arg.size()) + ".");
1273 
1274  // bvec buffers for the concatenated input/output nonzeros
1275  std::vector<bvec_t> in_buf(nnz_in()), out_buf(nnz_out(), 0);
1276  for (casadi_int k=0; k<nnz_in(); ++k) in_buf[k] = arg[k] ? ~static_cast<bvec_t>(0) : 0;
1277 
1278  // Per-input/output pointers into the buffers
1279  std::vector<const bvec_t*> argp(sz_arg(), nullptr);
1280  std::vector<bvec_t*> resp(sz_res(), nullptr);
1281  casadi_int off = 0;
1282  for (casadi_int i=0; i<n_in(); ++i) { argp[i] = get_ptr(in_buf)+off; off += nnz_in(i); }
1283  off = 0;
1284  for (casadi_int i=0; i<n_out(); ++i) { resp[i] = get_ptr(out_buf)+off; off += nnz_out(i); }
1285 
1286  // Work vectors
1287  std::vector<casadi_int> iw(sz_iw());
1288  std::vector<bvec_t> w(sz_w());
1289 
1290  eval_activity(get_ptr(argp), get_ptr(resp), get_ptr(iw), get_ptr(w));
1291 
1292  std::vector<bool> ret(nnz_out());
1293  for (casadi_int k=0; k<nnz_out(); ++k) ret[k] = out_buf[k]!=0;
1294  return ret;
1295  }
casadi_int nnz_out() const
Get number of output nonzeros.
Definition: function.cpp:1007
size_t sz_res() const
Get required length of res field.
Definition: function.cpp:1237
size_t sz_iw() const
Get required length of iw field.
Definition: function.cpp:1239
casadi_int n_out() const
Get the number of function outputs.
Definition: function.cpp:975
casadi_int n_in() const
Get the number of function inputs.
Definition: function.cpp:971
size_t sz_w() const
Get required length of w field.
Definition: function.cpp:1241
size_t sz_arg() const
Get required length of arg field.
Definition: function.cpp:1235
casadi_int nnz_in() const
Get number of input nonzeros.
Definition: function.cpp:1003
int eval_activity(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, int mem=0) const
Propagate signal activity forward (bit set = active (possibly nonzero))
Definition: function.cpp:1260
std::string str(const T &v)
String representation, any type.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.

References casadi::Function::eval_activity(), casadi::get_ptr(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::nnz_in(), casadi::Function::nnz_out(), casadi::str(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), and casadi::Function::sz_w().

Referenced by casadi::Call::create().

◆ assert_size_in()

void casadi::Function::assert_size_in ( casadi_int  i,
casadi_int  nrow,
casadi_int  ncol 
) const
inherited

Definition at line 1982 of file function.cpp.

1982  {
1983  casadi_assert(size1_in(i)==nrow && size2_in(i)==ncol,
1984  "Incorrect shape for " + str(*this) + " input " + str(i) + " \""
1985  + name_in(i) + "\". Expected " + str(nrow) + "-by-" + str(ncol)
1986  + " but got " + str(size1_in(i)) + "-by-" + str(size2_in(i)));
1987 
1988  }
casadi_int size1_in(casadi_int ind) const
Get input dimension.
Definition: function.cpp:979
const std::vector< std::string > & name_in() const
Get input scheme.
Definition: function.cpp:1113
casadi_int size2_in(casadi_int ind) const
Get input dimension.
Definition: function.cpp:983

References casadi::Function::name_in(), casadi::Function::size1_in(), casadi::Function::size2_in(), and casadi::str().

Referenced by casadi::FunctionInternal::forward(), and casadi::FunctionInternal::reverse().

◆ assert_size_out()

void casadi::Function::assert_size_out ( casadi_int  i,
casadi_int  nrow,
casadi_int  ncol 
) const
inherited

Definition at line 1990 of file function.cpp.

1990  {
1991  casadi_assert(size1_out(i)==nrow && size2_out(i)==ncol,
1992  "Incorrect shape for " + str(*this) + " output " + str(i) + " \""
1993  + name_out(i) + "\". Expected " + str(nrow) + "-by-" + str(ncol)
1994  + " but got " + str(size1_out(i)) + "-by-" + str(size2_out(i)));
1995  }
casadi_int size2_out(casadi_int ind) const
Get output dimension.
Definition: function.cpp:991
casadi_int size1_out(casadi_int ind) const
Get output dimension.
Definition: function.cpp:987
const std::vector< std::string > & name_out() const
Get output scheme.
Definition: function.cpp:1117

References casadi::Function::name_out(), casadi::Function::size1_out(), casadi::Function::size2_out(), and casadi::str().

Referenced by casadi::Function::assert_sparsity_out().

◆ assert_sparsity_out()

void casadi::Function::assert_sparsity_out ( casadi_int  i,
const Sparsity sp,
casadi_int  n = 1,
bool  allow_all_zero_sparse = true 
) const
inherited

Definition at line 1997 of file function.cpp.

1998  {
1999  // Assert shape
2000  assert_size_out(i, sp.size1(), sp.size2() * n);
2001  // Quick return if empty sparse
2002  if (allow_all_zero_sparse && sparsity_out(i).nnz() == 0) return;
2003  // Check sparsities
2004  casadi_assert(sparsity_out(i).is_stacked(sp, n), "Mismatching sparsity "
2005  "(but correct dimensions) for " + str(*this) + " output " + name_out(i));
2006  }
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
Definition: function.cpp:1183
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.
Definition: function.cpp:1990

References casadi::Function::assert_size_out(), casadi::Function::name_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Function::sparsity_out(), and casadi::str().

Referenced by casadi::FunctionInternal::forward(), and casadi::FunctionInternal::reverse().

◆ assign()

improper use will cause memory leaks!

Extra doc: https://github.com/casadi/casadi/wiki/L_at

Definition at line 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ bspline()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1wo

Definition at line 943 of file function.cpp.

946  {
947  try {
948  casadi_assert(degree.size()==knots.size(), "Degree list length (" + str(degree.size()) + ") "
949  "must match knot list length (" + str(knots.size()) + ").");
950  MX x = MX::sym("x", degree.size());
951  std::vector<std::string> lookup_mode;
952  Dict opts_remainder = extract_from_dict(opts, "lookup_mode", lookup_mode);
953  Dict opts_bspline;
954  opts_bspline["lookup_mode"] = lookup_mode;
955  MX y = MX::bspline(x, DM(coeffs), knots, degree, m, opts_bspline);
956  return Function(name, {x}, {y}, opts_remainder);
957  } catch(std::exception& e) {
958  THROW_ERROR_NOOBJ("bspline", e.what(), "BSpline");
959  }
960  }
const std::string & name() const
Name of the function.
Definition: function.cpp:1504
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
static MX bspline(const MX &x, const DM &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts=Dict())
Definition: mx.cpp:2224
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
Matrix< double > DM
Definition: dm_fwd.hpp:33
Dict extract_from_dict(const Dict &d, const std::string &key, T &value)

References casadi::MX::bspline(), casadi::extract_from_dict(), casadi::Function::Function(), casadi::Function::name(), casadi::str(), and casadi::GenericMatrix< MX >::sym().

◆ buf_in() [1/2]

std::vector< const double * > casadi::Function::buf_in ( Function::MapArg  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 570 of file function.cpp.

570  {
571  // Return value (RVO)
572  std::vector<const double*> ret(sz_arg(), nullptr);
573 
574  // Read inputs
575  for (auto i=arg.begin(); i!=arg.end(); ++i) {
576  casadi_int ind = index_in(i->first);
577  casadi_assert_dev(i->second.size()==nnz_in(ind));
578  ret[ind] = get_ptr(i->second);
579  }
580 
581  return ret;
582  }
casadi_int index_in(const std::string &name) const
Find the index for a string describing a particular entry of an input scheme.
Definition: function.cpp:1121

References casadi::get_ptr(), casadi::Function::index_in(), casadi::Function::nnz_in(), and casadi::Function::sz_arg().

◆ buf_in() [2/2]

std::vector< const double * > casadi::Function::buf_in ( Function::VecArg  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 536 of file function.cpp.

536  {
537  casadi_assert_dev(arg.size()==n_in());
538  auto arg_it=arg.begin();
539  std::vector<const double*> buf_arg(sz_arg());
540  for (casadi_uint i=0; i<arg.size(); ++i) {
541  casadi_assert_dev(arg_it->size()==nnz_in(i));
542  buf_arg[i] = get_ptr(*arg_it++);
543  }
544  return buf_arg;
545  }

References casadi::get_ptr(), casadi::Function::n_in(), casadi::Function::nnz_in(), and casadi::Function::sz_arg().

◆ buf_out() [1/4]

std::vector< double * > casadi::Function::buf_out ( Function::MapRes  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 584 of file function.cpp.

584  {
585  // Return value (RVO)
586  std::vector<double*> ret(sz_res(), nullptr);
587 
588  // Read outputs
589  for (auto i=res.begin(); i!=res.end(); ++i) {
590  casadi_int ind = index_out(i->first);
591  i->second.resize(nnz_out(ind));
592  ret[ind] = get_ptr(i->second);
593  }
594 
595  return ret;
596  }
casadi_int index_out(const std::string &name) const
Find the index for a string describing a particular entry of an output scheme.
Definition: function.cpp:1129

References casadi::get_ptr(), casadi::Function::index_out(), casadi::Function::nnz_out(), and casadi::Function::sz_res().

◆ buf_out() [2/4]

std::vector< double * > casadi::Function::buf_out ( Function::MPrRes  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 598 of file function.cpp.

598  {
599  // Return value (RVO)
600  std::vector<double*> ret(sz_res(), nullptr);
601 
602  // Read outputs
603  for (auto i=res.begin(); i!=res.end(); ++i) {
604  casadi_int ind = index_out(i->first);
605  casadi_assert_dev(i->second!=0);
606  i->second->resize(nnz_out(ind));
607  ret[ind] = get_ptr(*i->second);
608  }
609 
610  return ret;
611  }

References casadi::get_ptr(), casadi::Function::index_out(), casadi::Function::nnz_out(), and casadi::Function::sz_res().

◆ buf_out() [3/4]

std::vector< double * > casadi::Function::buf_out ( Function::VecRes  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 547 of file function.cpp.

547  {
548  res.resize(n_out());
549  auto res_it=res.begin();
550  std::vector<double*> buf_res(sz_res());
551  for (casadi_uint i=0; i<res.size(); ++i) {
552  res_it->resize(nnz_out(i));
553  buf_res[i] = get_ptr(*res_it++);
554  }
555  return buf_res;
556  }

References casadi::get_ptr(), casadi::Function::n_out(), casadi::Function::nnz_out(), and casadi::Function::sz_res().

◆ buf_out() [4/4]

std::vector< double * > casadi::Function::buf_out ( Function::VPrRes  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w9

Definition at line 558 of file function.cpp.

558  {
559  casadi_assert_dev(res.size()==n_out());
560  auto res_it=res.begin();
561  std::vector<double*> buf_res(sz_res());
562  for (casadi_uint i=0; i<res.size(); ++i) {
563  casadi_assert_dev(*res_it!=0);
564  (*res_it)->resize(nnz_out(i));
565  buf_res[i] = get_ptr(**res_it++);
566  }
567  return buf_res;
568  }

References casadi::get_ptr(), casadi::Function::n_out(), casadi::Function::nnz_out(), and casadi::Function::sz_res().

◆ cache()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_26i

Definition at line 2032 of file function.cpp.

2032  {
2033  try {
2034  return (*this)->cache();
2035  } catch(std::exception& e) {
2036  THROW_ERROR("cache", e.what());
2037  return {};
2038  }
2039  }

◆ call() [1/6]

void casadi::Function::call ( const DMDict arg,
DMDict res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w7

Definition at line 1650 of file function.cpp.

1651  {
1652  try {
1653  call_gen(arg, res, always_inline, never_inline);
1654  } catch(std::exception& e) {
1655  THROW_ERROR("call", e.what());
1656  }
1657  }
void call_gen(std::vector< const D * > arg, std::vector< D * > res) const
Evaluate with temporary memory allocation.
Definition: function.cpp:614

References casadi::Function::call_gen().

◆ call() [2/6]

void casadi::Function::call ( const MXDict arg,
MXDict res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w7

Definition at line 1668 of file function.cpp.

1669  {
1670  try {
1671  call_gen(arg, res, always_inline, never_inline);
1672  } catch(std::exception& e) {
1673  THROW_ERROR("call", e.what());
1674  }
1675  }

References casadi::Function::call_gen().

◆ call() [3/6]

void casadi::Function::call ( const std::vector< DM > &  arg,
std::vector< DM > &  res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w7

Definition at line 509 of file function.cpp.

510  {
511  try {
512  (*this)->call(arg, res, always_inline, never_inline);
513  } catch(std::exception& e) {
514  THROW_ERROR("call", e.what());
515  }
516  }

Referenced by casadi::Function::call_gen(), casadi::construct_nlpsol(), casadi::detect_simple_bounds_gen(), casadi::FunctionInternal::eval_mx(), casadi::Function::map(), casadi::MX::matrix_expand(), casadi::Function::operator()(), and casadi::MX::substitute().

◆ call() [4/6]

void casadi::Function::call ( const std::vector< MX > &  arg,
std::vector< MX > &  res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w7

Definition at line 527 of file function.cpp.

528  {
529  try {
530  (*this)->call(arg, res, always_inline, never_inline);
531  } catch(std::exception& e) {
532  THROW_ERROR("call", e.what());
533  }
534  }

◆ call() [5/6]

void casadi::Function::call ( const std::vector< SX > &  arg,
std::vector< SX > &  res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w7

Definition at line 518 of file function.cpp.

519  {
520  try {
521  (*this)->call(arg, res, always_inline, never_inline);
522  } catch(std::exception& e) {
523  THROW_ERROR("call", e.what());
524  }
525  }

◆ call() [6/6]

void casadi::Function::call ( const SXDict arg,
SXDict res,
bool  always_inline = false,
bool  never_inline = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w7

Definition at line 1659 of file function.cpp.

1660  {
1661  try {
1662  call_gen(arg, res, always_inline, never_inline);
1663  } catch(std::exception& e) {
1664  THROW_ERROR("call", e.what());
1665  }
1666  }

References casadi::Function::call_gen().

◆ call_gen() [1/2]

template<typename M >
void casadi::Function::call_gen ( const std::map< std::string, M > &  arg,
std::map< std::string, M > &  res,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xu

Definition at line 1616 of file function.cpp.

1617  {
1618  // Convert to vector arguments
1619  std::vector<M> arg_v = (*this)->convert_arg(arg);
1620 
1621  // Make call
1622  std::vector<M> res_v;
1623  call(arg_v, res_v, always_inline, never_inline);
1624 
1625  // Save to map
1626  res.clear();
1627  for (casadi_int i=0; i<res_v.size(); ++i) {
1628  res[name_out(i)] = res_v[i];
1629  }
1630  }
void call(const std::vector< DM > &arg, std::vector< DM > &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
Definition: function.cpp:509

References casadi::Function::call(), and casadi::Function::name_out().

◆ call_gen() [2/2]

template<typename D >
void casadi::Function::call_gen ( std::vector< const D * >  arg,
std::vector< D * >  res 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w8

Definition at line 614 of file function.cpp.

614  {
615  // Input buffer
616  casadi_assert_dev(arg.size()>=n_in());
617  arg.resize(sz_arg());
618 
619  // Output buffer
620  casadi_assert_dev(res.size()>=n_out());
621  res.resize(sz_res());
622 
623  // Work vectors
624  std::vector<casadi_int> iw(sz_iw());
625  std::vector<D> w(sz_w());
626 
627  // Evaluate memoryless
628  (*this)(get_ptr(arg), get_ptr(res), get_ptr(iw), get_ptr(w), 0);
629  }

References casadi::get_ptr(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), and casadi::Function::sz_w().

Referenced by casadi::Function::call(), and casadi::Function::operator()().

◆ change_option()

void casadi::Function::change_option ( const std::string &  option_name,
const GenericType option_value 
)
inherited

This is only possible for a selected number of options that do not change the numerical results of the computation, e.g. to enable a more verbose output or saving to file.

Extra doc: https://github.com/casadi/casadi/wiki/L_1w2

Definition at line 1361 of file function.cpp.

1361  {
1362  try {
1363  // Assert existance
1364  if (!has_option(option_name))
1365  casadi_error("Option '" + option_name + "' does not exist");
1366  // Call internal class
1367  (*this)->change_option(option_name, option_value);
1368  } catch(std::exception& e) {
1369  THROW_ERROR("change_option", e.what());
1370  }
1371  }
bool has_option(const std::string &option_name) const
Does a particular option exist.
Definition: function.cpp:1352

References casadi::Function::has_option().

◆ check_name()

bool casadi::Function::check_name ( const std::string &  name)
staticinherited

Valid function names consist of

  • 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"

Extra doc: https://github.com/casadi/casadi/wiki/L_1xx

Definition at line 1513 of file function.cpp.

1513  {
1514  // Check if empty
1515  if (name.empty()) return false;
1516 
1517  // Check if keyword
1518  for (const char* kw : {"null", "jac", "hess"}) {
1519  if (name==kw) return false;
1520  }
1521 
1522  // Make sure that the first character is a letter
1523  auto it=name.begin();
1524  if (!std::isalpha(*it++)) return false;
1525 
1526  // Check remain_ing characters
1527  for (; it!=name.end(); ++it) {
1528  if (*it=='_') {
1529  // Make sure that the next character isn't also an underscore
1530  if (it+1!=name.end() && *(it+1)=='_') return false;
1531  } else {
1532  // Make sure alphanumeric
1533  if (!std::isalnum(*it)) return false;
1534  }
1535  }
1536 
1537  // Valid function name if reached this point
1538  return true;
1539  }

References casadi::Function::name().

Referenced by casadi::CodeGenerator::CodeGenerator(), casadi::Function::fix_name(), and casadi::FunctionInternal::FunctionInternal().

◆ checkout()

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

Definition at line 1970 of file function.cpp.

1970  {
1971  return (*this)->checkout();
1972  }

Referenced by casadi::QpToNlp::alloc_mem(), casadi::FunctionBuffer::FunctionBuffer(), and casadi::FunctionBuffer::operator=().

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ conditional() [1/2]

Function casadi::Function::conditional ( const std::string &  name,
const Function f,
const Dict opts = Dict() 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wn

Definition at line 926 of file function.cpp.

927  {
928  try {
929  // Create a dummy function with the same signature as f
930  std::vector<MX> dummy_in = f.mx_in();
931  std::vector<MX> dummy_out(f.n_out());
932  for (casadi_int i = 0; i < dummy_out.size(); ++i) {
933  dummy_out.at(i) = MX::zeros(f.sparsity_out(i));
934  }
935  Function dummy("dummy_" + f.name(), dummy_in, dummy_out, f.name_in(), f.name_out());
936  // Form a conditional call
937  return if_else(name, f, dummy, opts);
938  } catch(std::exception& e) {
939  THROW_ERROR_NOOBJ("conditional", e.what(), "Switch");
940  }
941  }
static Function if_else(const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
Constructor (if-else)
Definition: function.cpp:962
static MX zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.

References casadi::Function::if_else(), casadi::Function::mx_in(), casadi::Function::n_out(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::sparsity_out(), and casadi::GenericMatrix< MX >::zeros().

◆ conditional() [2/2]

Function casadi::Function::conditional ( const std::string &  name,
const std::vector< Function > &  f,
const Function f_def,
const Dict opts = Dict() 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wm

Definition at line 917 of file function.cpp.

918  {
919  try {
920  return create(new Switch(name, f, f_def), opts);
921  } catch(std::exception& e) {
922  THROW_ERROR_NOOBJ("conditional", e.what(), "Switch");
923  }
924  }
static Function create(FunctionInternal *node)
Create from node.
Definition: function.cpp:488

References casadi::Function::create(), and casadi::Function::name().

Referenced by casadi::MX::conditional(), casadi::Switch::get_forward(), casadi::Switch::get_reverse(), and casadi::DaeBuilderInternal::transition().

◆ construct() [1/4]

void casadi::Callback::construct ( const std::string &  name,
const Dict opts = Dict() 
)

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_o5

Definition at line 36 of file callback.cpp.

36  {
37  if (!is_null()) {
38  casadi_error("Cannot create '" + name + "': Internal class already created");
39  }
40  own(new CallbackInternal(name, this));
41  (*this)->construct(opts);
42  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null(), casadi::Function::name(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

◆ construct() [2/4]

template<typename M >
void casadi::Function::construct ( const std::string &  name,
const std::map< std::string, M > &  dict,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const Dict opts 
)
protectedinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y8

Definition at line 196 of file function.cpp.

199  {
200  std::vector<M> ex_in(name_in.size()), ex_out(name_out.size());
201  for (auto&& i : dict) {
202  std::vector<std::string>::const_iterator it;
203  it = std::find(name_in.begin(), name_in.end(), i.first);
204  if (it!=name_in.end()) {
205  // Input expression
206  ex_in[it-name_in.begin()] = i.second;
207  } else {
208  it = std::find(name_out.begin(), name_out.end(), i.first);
209  if (it!=name_out.end()) {
210  // Output expression
211  ex_out[it-name_out.begin()] = i.second;
212  } else {
213  // Neither
214  casadi_error("Unknown dictionary entry: '" + i.first + "'");
215  }
216  }
217  }
218  construct(name, ex_in, ex_out, name_in, name_out, opts);
219  }
void construct(const std::string &name, const std::vector< SX > &ex_in, const std::vector< SX > &ex_out, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts)
Called by constructors.
Definition: function.cpp:221

References casadi::Function::construct(), casadi::Function::name(), casadi::Function::name_in(), and casadi::Function::name_out().

◆ construct() [3/4]

void casadi::Function::construct ( const std::string &  name,
const std::vector< MX > &  ex_in,
const std::vector< MX > &  ex_out,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const Dict opts 
)
protectedinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y8

Definition at line 249 of file function.cpp.

253  {
254  try {
255  own(new MXFunction(name, ex_in, ex_out, name_in, name_out));
256  (*this)->construct(opts);
257 
258  // Perform post-construction expand
259  auto it = opts.find("post_expand");
260  if (it!=opts.end()) {
261  if (!it->second) return;
262  auto it = opts.find("post_expand_options");
263  if (it==opts.end()) {
264  operator=((*this).expand());
265  } else {
266  operator=((*this).expand((*this).name(), it->second));
267  }
268  }
269 
270  // Perform external transformations
271  it = opts.find("external_transform");
272  if (it!=opts.end()) {
273  auto v = it->second.to_vector_vector();
274  for (const std::vector<GenericType>& vec : v) {
275  casadi_assert(vec.size()>=2, "external_transform: inner list must be length >=2");
276  casadi_assert(vec.size()<=3, "external_transform: inner list must be length <=3");
277  std::string name = vec[0].to_string();
278  std::string op = vec[1].to_string();
279  Dict opts = vec.size()==3 ? vec[2].to_dict() : Dict();
280  operator=(external_transform(name, op, (*this), opts));
281  }
282  }
283 
284  } catch(std::exception& e) {
285  THROW_ERROR_NOOBJ("Function", e.what(), "MXFunction");
286  }
287  }
GenericShared & operator=(const GenericShared &ref)
Assignment operator.
Function external_transform(const std::string &name, const std::string &op, const Function &f, const Dict &opts)
Apply a transformation defined externally.
Definition: tools.cpp:44

References casadi::external_transform(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::GenericShared< SharedObject, SharedObjectInternal >::operator=(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

◆ construct() [4/4]

void casadi::Function::construct ( const std::string &  name,
const std::vector< SX > &  ex_in,
const std::vector< SX > &  ex_out,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const Dict opts 
)
protectedinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y8

Definition at line 221 of file function.cpp.

225  {
226  try {
227  own(new SXFunction(name, ex_in, ex_out, name_in, name_out));
228  (*this)->construct(opts);
229 
230  // Perform external transformations
231  auto it = opts.find("external_transform");
232  if (it!=opts.end()) {
233  auto v = it->second.to_vector_vector();
234  for (const std::vector<GenericType>& vec : v) {
235  casadi_assert(vec.size()>=2, "external_transform: inner list must be length >=2");
236  casadi_assert(vec.size()<=3, "external_transform: inner list must be length <=3");
237  std::string name = vec[0].to_string();
238  std::string op = vec[1].to_string();
239  Dict opts = vec.size()==3 ? vec[2].to_dict() : Dict();
240  operator=(external_transform(name, op, (*this), opts));
241  }
242  }
243 
244  } catch(std::exception& e) {
245  THROW_ERROR_NOOBJ("Function", e.what(), "SXFunction");
246  }
247  }

References casadi::external_transform(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::GenericShared< SharedObject, SharedObjectInternal >::operator=(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

Referenced by casadi::Function::construct(), and casadi::Function::Function().

◆ convert_in() [1/6]

std::vector< DM > casadi::Function::convert_in ( const DMDict arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1817 of file function.cpp.

1817  {
1818  return (*this)->convert_arg(arg);
1819  }

◆ convert_in() [2/6]

std::vector< MX > casadi::Function::convert_in ( const MXDict arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1849 of file function.cpp.

1849  {
1850  return (*this)->convert_arg(arg);
1851  }

◆ convert_in() [3/6]

DMDict casadi::Function::convert_in ( const std::vector< DM > &  arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1813 of file function.cpp.

1813  {
1814  return (*this)->convert_arg(arg);
1815  }

◆ convert_in() [4/6]

MXDict casadi::Function::convert_in ( const std::vector< MX > &  arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1845 of file function.cpp.

1845  {
1846  return (*this)->convert_arg(arg);
1847  }

◆ convert_in() [5/6]

SXDict casadi::Function::convert_in ( const std::vector< SX > &  arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1829 of file function.cpp.

1829  {
1830  return (*this)->convert_arg(arg);
1831  }

◆ convert_in() [6/6]

std::vector< SX > casadi::Function::convert_in ( const SXDict arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1833 of file function.cpp.

1833  {
1834  return (*this)->convert_arg(arg);
1835  }

◆ convert_out() [1/6]

std::vector< DM > casadi::Function::convert_out ( const DMDict arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1825 of file function.cpp.

1825  {
1826  return (*this)->convert_res(arg);
1827  }

◆ convert_out() [2/6]

std::vector< MX > casadi::Function::convert_out ( const MXDict arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1857 of file function.cpp.

1857  {
1858  return (*this)->convert_res(arg);
1859  }

◆ convert_out() [3/6]

DMDict casadi::Function::convert_out ( const std::vector< DM > &  arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1821 of file function.cpp.

1821  {
1822  return (*this)->convert_res(arg);
1823  }

◆ convert_out() [4/6]

MXDict casadi::Function::convert_out ( const std::vector< MX > &  arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1853 of file function.cpp.

1853  {
1854  return (*this)->convert_res(arg);
1855  }

◆ convert_out() [5/6]

SXDict casadi::Function::convert_out ( const std::vector< SX > &  arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1837 of file function.cpp.

1837  {
1838  return (*this)->convert_res(arg);
1839  }

◆ convert_out() [6/6]

std::vector< SX > casadi::Function::convert_out ( const SXDict arg) const
inherited

Will raise an error when an unknown key is used or a list has incorrect size. Does not perform sparsity checking.

Extra doc: https://github.com/casadi/casadi/wiki/L_1x7

Definition at line 1841 of file function.cpp.

1841  {
1842  return (*this)->convert_res(arg);
1843  }

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_down
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

46  {
47 #ifdef WITH_EXTRA_CHECKS
48  casadi_assert_dev(Function::call_depth_==0);
49 #endif // WITH_EXTRA_CHECKS
50  if (!node) return;
51 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 132 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ create() [1/2]

Function casadi::Function::create ( FunctionInternal node)
staticinherited

◆ create() [2/2]

Function casadi::Function::create ( FunctionInternal node,
const Dict opts 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1v7

Definition at line 494 of file function.cpp.

494  {
495  Function ret = create(node);
496  ret->construct(opts);
497  return ret;
498  }

References casadi::ProtoFunction::construct(), and casadi::Function::create().

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
std::string debug_repr(const Internal *) const

◆ default_in()

double casadi::Function::default_in ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vm

Definition at line 1677 of file function.cpp.

1677  {
1678  return (*this)->get_default_in(ind);
1679  }

Referenced by casadi::Blocksqp::feasibilityRestorationPhase(), and casadi::FiniteDiff::get_default_in().

◆ deserialize() [1/3]

Function casadi::Function::deserialize ( const std::string &  s)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y0

Definition at line 1556 of file function.cpp.

1556  {
1557  std::stringstream ss;
1558  ss << s;
1559  return deserialize(ss);
1560  }
static Function deserialize(std::istream &stream)
Build function from serialization.
Definition: function.cpp:1541

References casadi::Function::deserialize().

◆ deserialize() [2/3]

Function casadi::Function::deserialize ( DeserializingStream s)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y2

Definition at line 1491 of file function.cpp.

1491  {
1492  bool is_null;
1493  s.unpack("Function::null", is_null);
1494  if (is_null) return Function();
1496  }
static Function deserialize(DeserializingStream &s)
Deserialize with type disambiguation.

References casadi::FunctionInternal::deserialize(), casadi::Function::Function(), casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null(), and casadi::DeserializingStream::unpack().

◆ deserialize() [3/3]

Function casadi::Function::deserialize ( std::istream &  stream)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xz

Definition at line 1541 of file function.cpp.

1541  {
1542  DeserializingStream s(stream);
1543  return deserialize(s);
1544  }

Referenced by casadi::Function::deserialize().

◆ disp()

void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ eval()

std::vector< DM > casadi::Callback::eval ( const std::vector< DM > &  arg) const
virtual

This signature is not thread-safe. For guaranteed thread-safety, use eval_buffer

Extra doc: https://github.com/casadi/casadi/wiki/L_o8

Definition at line 60 of file callback.cpp.

60  {
61  return (*this)->FunctionInternal::eval_dm(arg);
62  }

◆ eval_activity()

int casadi::Function::eval_activity ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
int  mem = 0 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2ii

Definition at line 1260 of file function.cpp.

1261  {
1262  try {
1263  return (*this)->eval_activity(arg, res, iw, w, memory(mem));
1264  } catch(std::exception& e) {
1265  THROW_ERROR("eval_activity", e.what());
1266  }
1267  }
void * memory(int ind) const
Get memory object.
Definition: function.cpp:1978

References casadi::Function::memory().

Referenced by casadi::Function::activity(), and casadi::Call::eval_activity().

◆ eval_buffer()

int casadi::Callback::eval_buffer ( const double **  arg,
const std::vector< casadi_int > &  sizes_arg,
double **  res,
const std::vector< casadi_int > &  sizes_res 
) const
virtual

In Python, you will be passed two tuples of memoryview objects Note that only the structural nonzeros are present in the memoryview objects/buffers.

Make sure to override has_eval_buffer() to indicate support for this method.

Extra doc: https://github.com/casadi/casadi/wiki/L_o9

Definition at line 53 of file callback.cpp.

54  {
55  casadi_error("eval_buffer not overloaded.");
56  }

◆ expand() [1/2]

Function casadi::Function::expand ( ) const
inherited

◆ expand() [2/2]

Function casadi::Function::expand ( const std::string &  name,
const Dict opts = Dict() 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1v5

Definition at line 317 of file function.cpp.

317  {
318  casadi_assert(!has_free(),
319  "Function with free symbols cannot be expanded. "
320  "List of free variables in your Function: " +
321  join(get_free(), ","));
322 
323  Dict my_opts = (*this)->generate_options("clone");
324  update_dict(my_opts, opts);
325  std::vector<SX> ex_in = sx_in();
326  std::vector<SX> ex_out = Function(*this)(ex_in);
327  return Function(name, ex_in, ex_out, name_in(), name_out(), my_opts);
328  }
std::vector< std::string > get_free() const
Get free variables as a string.
Definition: function.cpp:1382
bool has_free() const
Does the function have free variables.
Definition: function.cpp:1894
const std::vector< SX > sx_in() const
Get symbolic primitives equivalent to the input expressions.
Definition: function.cpp:1765
std::string join(const std::vector< std::string > &l, const std::string &delim)
void update_dict(Dict &target, const Dict &source, bool recurse)
Update the target dictionary in place with source elements.

References casadi::Function::Function(), casadi::Function::get_free(), casadi::Function::has_free(), casadi::join(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::sx_in(), and casadi::update_dict().

◆ export_code() [1/3]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1wz

Definition at line 1498 of file function.cpp.

1498  {
1499  std::stringstream ss;
1500  (*this)->export_code(lang, ss, options);
1501  return ss.str();
1502  }

◆ export_code() [2/3]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1wz

Definition at line 1459 of file function.cpp.

1460  {
1461  auto stream_ptr = Filesystem::ofstream_ptr(fname);
1462  (*this)->export_code(lang, *stream_ptr, options);
1463  }
static std::unique_ptr< std::ostream > ofstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
Definition: filesystem.cpp:115

References casadi::Filesystem::ofstream_ptr().

◆ export_code() [3/3]

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

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1wz

Definition at line 1454 of file function.cpp.

1455  {
1456  (*this)->export_code(lang, stream, options);
1457  }

◆ factory()

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

Definition at line 2008 of file function.cpp.

2013  {
2014  try {
2015  return (*this)->factory(name, s_in, s_out, aux, opts);
2016  } catch(std::exception& e) {
2017  THROW_ERROR("factory", "Failed to create " + name + ":" + str(s_in) + "->" + str(s_out)
2018  + " with " + str(aux) + ":\n" + str(e.what()));
2019  }
2020  }

References casadi::FunctionInternal::factory(), casadi::Function::name(), and casadi::str().

Referenced by casadi::DaeBuilderInternal::create(), casadi::OracleFunction::create_function(), casadi::FunctionInternal::factory(), casadi::KinsolInterface::get_jtimes(), casadi::Function::hessian_old(), casadi::Rootfinder::init(), casadi::Blocksqp::init(), casadi::Function::jacobian_old(), and casadi::Nlpsol::kkt().

◆ finalize()

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

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_o7

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

98 {}

◆ find_function()

Function casadi::Function::find_function ( const std::string &  name,
casadi_int  max_depth = -1 
) const
inherited
Parameters
[in]nameName of function needed
[in]max_depthMaximum depth - a negative number indicates no maximum

Extra doc: https://github.com/casadi/casadi/wiki/L_1y7

Definition at line 2084 of file function.cpp.

2084  {
2085  try {
2086  // If negative, make largest positive number
2087  if (max_depth < 0) max_depth = std::numeric_limits<casadi_int>::max();
2088  // The internal routine uses a map to avoid duplicate functions
2089  std::map<FunctionInternal*, std::pair<Function, size_t> > all_fun;
2090  (*this)->find(all_fun, max_depth);
2091  // Search this map
2092  for (auto&& e : all_fun) {
2093  if (e.second.first.name() == name) return e.second.first;
2094  }
2095  // Not found
2096  casadi_error("'" + name + "' not found");
2097  } catch(std::exception& e) {
2098  THROW_ERROR("find", e.what());
2099  return Function();
2100  }
2101  }

References casadi::Function::Function(), and casadi::Function::name().

◆ find_functions()

std::vector< Function > casadi::Function::find_functions ( casadi_int  max_depth = -1) const
inherited
Parameters
[in]max_depthMaximum depth - a negative number indicates no maximum
Returns
depth-first ordered, unique, list of dependencies

Extra doc: https://github.com/casadi/casadi/wiki/L_1y6

Definition at line 2067 of file function.cpp.

2067  {
2068  try {
2069  // If negative, make largest positive number
2070  if (max_depth < 0) max_depth = std::numeric_limits<casadi_int>::max();
2071  // The internal routine uses a map to avoid duplicate functions
2072  std::map<FunctionInternal*, std::pair<Function, size_t> > all_fun;
2073  (*this)->find(all_fun, max_depth);
2074  // Create return object
2075  std::vector<Function> ret(all_fun.size());
2076  for (auto&& e : all_fun) ret[e.second.second] = e.second.first;
2077  return ret;
2078  } catch(std::exception& e) {
2079  THROW_ERROR("find", e.what());
2080  return {};
2081  }
2082  }

Referenced by casadi::FunctionInternal::codegen_decref(), casadi::FunctionInternal::codegen_incref(), and casadi::DaeBuilder::gather_fun().

◆ fix_name()

std::string casadi::Function::fix_name ( const std::string &  name)
staticinherited

Non-alphanumeric characters are converted into underscores and multiple consecutive undercores are dropped

Extra doc: https://github.com/casadi/casadi/wiki/L_1xy

Definition at line 1562 of file function.cpp.

1562  {
1563  // Quick return if already valid name
1564  if (check_name(name)) return name;
1565 
1566  // If empty, name it "unnamed"
1567  if (name.empty()) return "unnamed";
1568 
1569  // Construct a sane name
1570  std::stringstream ss;
1571 
1572  // If the first character isn't a character, prepend an "a"
1573  if (!std::isalpha(name.front())) ss << "a";
1574 
1575  // Treat other characters
1576  bool previous_is_underscore = false;
1577  for (char c : name) {
1578  if (std::isalnum(c)) {
1579  // Alphanumeric characters
1580  ss << c;
1581  previous_is_underscore = false;
1582  } else if (!previous_is_underscore) {
1583  // Everything else becomes an underscore
1584  ss << '_';
1585  previous_is_underscore = true;
1586  }
1587  }
1588 
1589  // If name became a keyword, append 1
1590  for (const char* kw : {"null", "jac", "hess"}) {
1591  if (ss.str()==kw) ss << "1";
1592  }
1593 
1594  return ss.str();
1595  }
static bool check_name(const std::string &name)
Check if a string is a valid function name.
Definition: function.cpp:1513

References casadi::Function::check_name(), and casadi::Function::name().

◆ fold()

Function casadi::Function::fold ( 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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Definition at line 661 of file function.cpp.

661  {
662  Function base = mapaccum(N, opts);
663  std::vector<MX> base_in = base.mx_in();
664  std::vector<MX> out = base(base_in);
665  out[0] = out[0](Slice(), range((N-1)*size2_out(0), N*size2_out(0))); // NOLINT
666  return Function("fold_"+name(), base_in, out, name_in(), name_out(), opts);
667  }
Function mapaccum(const std::string &name, casadi_int N, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
Definition: function.cpp:671
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.

References casadi::Function::Function(), casadi::Function::mapaccum(), casadi::Function::mx_in(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::range(), and casadi::Function::size2_out().

◆ forward()

Function casadi::Function::forward ( casadi_int  nfwd) const
inherited
   Returns a function with <tt>n_in + n_out + n_in</tt> inputs
   and <tt>nfwd</tt> outputs.
   The first <tt>n_in</tt> inputs correspond to nondifferentiated inputs.
   The next <tt>n_out</tt> inputs correspond to nondifferentiated outputs.
   and the last <tt>n_in</tt> inputs correspond to forward seeds,
   stacked horizontally
   The  <tt>n_out</tt> outputs correspond to forward sensitivities,
   stacked horizontally.     *
   <tt>(n_in = n_in(), n_out = n_out())</tt>

  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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wq

Definition at line 1324 of file function.cpp.

1324  {
1325  try {
1326  return (*this)->forward(nfwd);
1327  } catch(std::exception& e) {
1328  THROW_ERROR("forward", e.what());
1329  }
1330  }

References casadi::FunctionInternal::forward().

Referenced by casadi::SXFunction::ad_forward(), casadi::DaeBuilderInternal::export_fmu(), casadi::FunctionInternal::forward(), casadi::Map::get_forward(), casadi::MapSum::get_forward(), casadi::Nlpsol::get_forward(), casadi::Switch::get_forward(), and casadi::ImplicitFixedStepIntegrator::init().

◆ free_mx()

std::vector< MX > casadi::Function::free_mx ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xb

Definition at line 1878 of file function.cpp.

1878  {
1879  try {
1880  return (*this)->free_mx();
1881  } catch(std::exception& e) {
1882  THROW_ERROR("free_mx", e.what());
1883  }
1884  }

Referenced by casadi::MX::get_free(), and casadi::MX::symvar().

◆ free_sx()

std::vector< SX > casadi::Function::free_sx ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xa

Definition at line 1870 of file function.cpp.

1870  {
1871  try {
1872  return (*this)->free_sx();
1873  } catch(std::exception& e) {
1874  THROW_ERROR("free_sx", e.what());
1875  }
1876  }

Referenced by casadi::Matrix< Scalar >::get_free().

◆ generate() [1/2]

std::string casadi::Function::generate ( const Dict opts = Dict()) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wv

Definition at line 1386 of file function.cpp.

1386  {
1387  return generate(name(), opts);
1388  }
std::string generate(const std::string &fname, const Dict &opts=Dict()) const
Export / Generate C code for the function.
Definition: function.cpp:1390

References casadi::Function::generate(), and casadi::Function::name().

◆ generate() [2/2]

std::string casadi::Function::generate ( const std::string &  fname,
const Dict opts = Dict() 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wu

Examples
SX/generateCode.py.

Definition at line 1390 of file function.cpp.

1390  {
1391  CodeGenerator gen(fname, opts);
1392  gen.add(*this);
1393  return gen.generate();
1394  }

References casadi::CodeGenerator::add(), and casadi::CodeGenerator::generate().

Referenced by casadi::Function::generate().

◆ generate_dependencies()

std::string casadi::Function::generate_dependencies ( const std::string &  fname,
const Dict opts = Dict() 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ww

Definition at line 1396 of file function.cpp.

1396  {
1397  return (*this)->generate_dependencies(fname, opts);
1398  }

◆ generate_in() [1/2]

std::vector< DM > casadi::Function::generate_in ( const std::string &  fname)
inherited
See also
generate_out
convert_in to convert between dict/map and vector

Extra doc: https://github.com/casadi/casadi/wiki/L_1wx

Definition at line 1430 of file function.cpp.

1430  {
1431  DM data = DM::from_file(fname, "txt");
1432  // Empty files are okay
1433  if (data.is_empty(true)) data = DM(0, 1);
1434  casadi_assert(data.is_vector() && data.is_dense(), "Expected dense vector");
1435  casadi_assert(data.numel()==nnz_in(),
1436  "Dimension mismatch: file contains a vector of size " + str(data.numel())
1437  + ", while size " + str(nnz_in()) + " was expected.");
1438 
1439  return nz_to_in(data.nonzeros());
1440  }
std::vector< DM > nz_to_in(const std::vector< double > &arg) const
Convert from/to flat vector of input/output nonzeros.
Definition: function.cpp:1805
static Matrix< double > from_file(const std::string &filename, const std::string &format_hint="")

References casadi::Matrix< double >::from_file(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::is_vector(), casadi::Function::nnz_in(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MatType >::numel(), casadi::Function::nz_to_in(), and casadi::str().

◆ generate_in() [2/2]

void casadi::Function::generate_in ( const std::string &  fname,
const std::vector< DM > &  arg 
)
inherited
See also
generate_out
convert_in to convert between dict/map and vector

Extra doc: https://github.com/casadi/casadi/wiki/L_1wx

Definition at line 1400 of file function.cpp.

1400  {
1401  std::vector<double> d = nz_from_in(arg);
1402 
1403  // Set up output stream
1404  auto of_ptr = Filesystem::ofstream_ptr(fname);
1405  std::ostream& of = *of_ptr;
1406  normalized_setup(of);
1407 
1408  // Encode each output
1409  for (casadi_int i=0; i<d.size(); ++i) {
1410  normalized_out(of, d[i]);
1411  of << std::endl;
1412  }
1413  }
std::vector< double > nz_from_in(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
Definition: function.cpp:1797
void normalized_setup(std::istream &stream)
void normalized_out(std::ostream &stream, double val)

References casadi::normalized_out(), casadi::normalized_setup(), casadi::Function::nz_from_in(), and casadi::Filesystem::ofstream_ptr().

◆ generate_lifted()

void casadi::Function::generate_lifted ( Function vdef_fcn,
Function vinit_fcn 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xc

Definition at line 1898 of file function.cpp.

1898  {
1899  try {
1900  (*this)->generate_lifted(vdef_fcn, vinit_fcn);
1901  } catch(std::exception& e) {
1902  THROW_ERROR("generate_lifted", e.what());
1903  }
1904  }

Referenced by casadi::Scpgen::init().

◆ generate_out() [1/2]

std::vector< DM > casadi::Function::generate_out ( const std::string &  fname)
inherited
See also
generate_in
convert_out to convert between dict/map and vector

Extra doc: https://github.com/casadi/casadi/wiki/L_1wy

Definition at line 1442 of file function.cpp.

1442  {
1443  DM data = DM::from_file(fname, "txt");
1444  // Empty files are okay
1445  if (data.is_empty(true)) data = DM(0, 1);
1446  casadi_assert(data.is_vector() && data.is_dense(), "Expected dense vector");
1447  casadi_assert(data.numel()==nnz_out(),
1448  "Dimension mismatch: file contains a vector of size " + str(data.numel())
1449  + ", while size " + str(nnz_out()) + " was expected.");
1450 
1451  return nz_to_out(data.nonzeros());
1452  }
std::vector< DM > nz_to_out(const std::vector< double > &arg) const
Convert from/to flat vector of input/output nonzeros.
Definition: function.cpp:1809

References casadi::Matrix< double >::from_file(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::is_vector(), casadi::Function::nnz_out(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MatType >::numel(), casadi::Function::nz_to_out(), and casadi::str().

◆ generate_out() [2/2]

void casadi::Function::generate_out ( const std::string &  fname,
const std::vector< DM > &  arg 
)
inherited
See also
generate_in
convert_out to convert between dict/map and vector

Extra doc: https://github.com/casadi/casadi/wiki/L_1wy

Definition at line 1415 of file function.cpp.

1415  {
1416  std::vector<double> d = nz_from_out(res);
1417 
1418  // Set up output stream
1419  auto of_ptr = Filesystem::ofstream_ptr(fname);
1420  std::ostream& of = *of_ptr;
1421  normalized_setup(of);
1422 
1423  // Encode each output
1424  for (casadi_int i=0; i<d.size(); ++i) {
1425  normalized_out(of, d[i]);
1426  of << std::endl;
1427  }
1428  }
std::vector< double > nz_from_out(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
Definition: function.cpp:1801

References casadi::normalized_out(), casadi::normalized_setup(), casadi::Function::nz_from_out(), and casadi::Filesystem::ofstream_ptr().

◆ get() [1/2]

FunctionInternal * casadi::Function::get ( ) const
inherited

Get a const pointer to the node

Definition at line 505 of file function.cpp.

505  {
506  return static_cast<FunctionInternal*>(SharedObject::get());
507  }
SharedObjectInternal * get() const
Get a const pointer to the node.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

Referenced by casadi::FunctionInternal::add_embedded(), casadi::XFunction< DerivedType, MatType, NodeType >::call_forward(), casadi::XFunction< DerivedType, MatType, NodeType >::call_reverse(), casadi::LinearInterpolantJac::codegen_body(), casadi::conic_debug(), casadi::MX::cse(), casadi::CodeGenerator::define_local_mutex(), casadi::LinearInterpolantJac::eval(), casadi::MX::extract(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::XFunction< DerivedType, MatType, NodeType >::get_jacobian(), casadi::LinearInterpolantJac::has_parametric_grid(), casadi::LinearInterpolantJac::has_parametric_values(), casadi::SundialsInterface::init(), casadi::LinearInterpolantJac::init(), casadi::MX::jacobian(), casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::local_mutexes(), casadi::Function::operator->(), casadi::Function::operator==(), casadi::LinearInterpolantJac::serialize_type(), casadi::MX::simplify_const_folding(), casadi::simplify_const_folding_order(), casadi::MX::simplify_ref_count(), casadi::OptiNode::solve_prepare(), casadi::MX::substitute_inplace(), and casadi::CodeGenerator::wrapper().

◆ get() [2/2]

template<typename T >
T* casadi::Function::get ( ) const
inlineinherited

Definition at line 984 of file function.hpp.

984  {
985  T* ret = dynamic_cast<T*>(get());
986  casadi_assert_dev(ret!=nullptr);
987  return ret;
988  }
FunctionInternal * get() const
Definition: function.cpp:505

References casadi::T.

◆ get_factory()

Function casadi::Callback::get_factory ( const std::string &  name,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux,
const Dict opts 
) const
virtual

Extra doc: https://github.com/casadi/casadi/wiki/L_2de

Definition at line 92 of file callback.cpp.

96  {
97  return (*this)->FunctionInternal::factory(name, s_in, s_out, aux, opts);
98  }

References casadi::Function::name().

◆ get_forward()

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

forward(nfwd) returns a cached instance if available, and calls Function get_forward(casadi_int nfwd) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_oi

Definition at line 112 of file callback.cpp.

116  {
117  return (*this)->FunctionInternal::get_forward(nfwd, name, inames, onames, opts);
118  }

References casadi::Function::name().

◆ get_free()

std::vector< std::string > casadi::Function::get_free ( ) const
inherited

◆ get_function() [1/2]

std::vector< std::string > casadi::Function::get_function ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y3

Definition at line 2041 of file function.cpp.

2041  {
2042  try {
2043  return (*this)->get_function();
2044  } catch(std::exception& e) {
2045  THROW_ERROR("get_function", e.what());
2046  return {};
2047  }
2048  }

Referenced by casadi::IdasInterface::psetupF().

◆ get_function() [2/2]

Function casadi::Function::get_function ( const std::string &  name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y4

Definition at line 2050 of file function.cpp.

2050  {
2051  try {
2052  return (*this)->get_function(name);
2053  } catch(std::exception& e) {
2054  THROW_ERROR("get_function", e.what());
2055  }
2056  }

References casadi::Function::name().

◆ get_jac_sparsity()

virtual Sparsity casadi::Callback::get_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  symmetric 
) const
inlinevirtual

with respect to all output elements

Extra doc: https://github.com/casadi/casadi/wiki/L_ok

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

228  {
229  return Sparsity(); }

◆ get_jacobian()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_oh

Definition at line 104 of file callback.cpp.

108  {
109  return (*this)->FunctionInternal::get_jacobian(name, inames, onames, opts);
110  }

References casadi::Function::name().

◆ get_n_in()

casadi_int casadi::Callback::get_n_in ( )
virtual

This function is called during construction.

Extra doc: https://github.com/casadi/casadi/wiki/L_oa

Definition at line 64 of file callback.cpp.

64  {
65  return (*this)->FunctionInternal::get_n_in();
66  }

◆ get_n_out()

casadi_int casadi::Callback::get_n_out ( )
virtual

This function is called during construction.

Extra doc: https://github.com/casadi/casadi/wiki/L_ob

Definition at line 68 of file callback.cpp.

68  {
69  return (*this)->FunctionInternal::get_n_out();
70  }

◆ get_name_in()

std::string casadi::Callback::get_name_in ( casadi_int  i)
virtual

This function is called during construction.

Extra doc: https://github.com/casadi/casadi/wiki/L_oe

Definition at line 80 of file callback.cpp.

80  {
81  return (*this)->FunctionInternal::get_name_in(i);
82  }

◆ get_name_out()

std::string casadi::Callback::get_name_out ( casadi_int  i)
virtual

This function is called during construction.

Extra doc: https://github.com/casadi/casadi/wiki/L_of

Definition at line 84 of file callback.cpp.

84  {
85  return (*this)->FunctionInternal::get_name_out(i);
86  }

◆ get_reverse()

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

reverse(nadj) returns a cached instance if available, and calls Function get_reverse(casadi_int nadj) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_oj

Definition at line 124 of file callback.cpp.

128  {
129  return (*this)->FunctionInternal::get_reverse(nadj, name, inames, onames, opts);
130  }

References casadi::Function::name().

◆ get_sparsity_in()

Sparsity casadi::Callback::get_sparsity_in ( casadi_int  i)
virtual

This function is called during construction.

Extra doc: https://github.com/casadi/casadi/wiki/L_oc

Definition at line 72 of file callback.cpp.

72  {
73  return (*this)->FunctionInternal::get_sparsity_in(i);
74  }

◆ get_sparsity_out()

Sparsity casadi::Callback::get_sparsity_out ( casadi_int  i)
virtual

This function is called during construction.

Extra doc: https://github.com/casadi/casadi/wiki/L_od

Definition at line 76 of file callback.cpp.

76  {
77  return (*this)->FunctionInternal::get_sparsity_out(i);
78  }

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ getCount()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::getCount
inherited

Definition at line 102 of file generic_shared_impl.hpp.

138  {
139  return (*this)->getCount();
140  }

◆ has_eval_buffer()

bool casadi::Callback::has_eval_buffer ( ) const
virtual

Extra doc: https://github.com/casadi/casadi/wiki/L_265

Definition at line 57 of file callback.cpp.

57  {
58  return false;
59  }

◆ has_forward()

bool casadi::Callback::has_forward ( casadi_int  nfwd) const
virtual

forward(nfwd) returns a cached instance if available, and calls Function get_forward(casadi_int nfwd) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_oi

Definition at line 120 of file callback.cpp.

120  {
121  return (*this)->FunctionInternal::has_forward(nfwd);
122  }

◆ has_free()

bool casadi::Function::has_free ( ) const
inherited

◆ has_function()

bool casadi::Function::has_function ( const std::string &  fname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y5

Definition at line 2058 of file function.cpp.

2058  {
2059  try {
2060  return (*this)->has_function(fname);
2061  } catch(std::exception& e) {
2062  THROW_ERROR("has_function", e.what());
2063  return false;
2064  }
2065  }

◆ has_in()

bool casadi::Function::has_in ( const std::string &  name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2c9

Definition at line 1137 of file function.cpp.

1137  {
1138  for (const std::string& s : (*this)->name_in_) {
1139  if (s==name) return true;
1140  }
1141  return false;
1142  }

References casadi::Function::name().

◆ has_jac_sparsity()

virtual bool casadi::Callback::has_jac_sparsity ( casadi_int  oind,
casadi_int  iind 
) const
inlinevirtual

with respect to all output elements

Extra doc: https://github.com/casadi/casadi/wiki/L_ok

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

227 { return false; }

◆ has_jacobian()

bool casadi::Callback::has_jacobian ( ) const
virtual

Extra doc: https://github.com/casadi/casadi/wiki/L_oh

Definition at line 100 of file callback.cpp.

100  {
101  return (*this)->FunctionInternal::has_jacobian();
102  }

◆ has_option()

bool casadi::Function::has_option ( const std::string &  option_name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w1

Definition at line 1352 of file function.cpp.

1352  {
1353  try {
1354  return (*this)->has_option(option_name);
1355  } catch(std::exception& e) {
1356  THROW_ERROR("has_option", e.what());
1357  return false; // never reached
1358  }
1359  }

Referenced by casadi::Function::change_option().

◆ has_out()

bool casadi::Function::has_out ( const std::string &  name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2ca

Definition at line 1144 of file function.cpp.

1144  {
1145  for (const std::string& s : (*this)->name_out_) {
1146  if (s==name) return true;
1147  }
1148  return false;
1149  }

References casadi::Function::name().

◆ has_reverse()

bool casadi::Callback::has_reverse ( casadi_int  nadj) const
virtual

reverse(nadj) returns a cached instance if available, and calls Function get_reverse(casadi_int nadj) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_oj

Definition at line 132 of file callback.cpp.

132  {
133  return (*this)->FunctionInternal::has_reverse(nadj);
134  }

◆ has_spfwd()

bool casadi::Function::has_spfwd ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xl

Definition at line 1886 of file function.cpp.

1886  {
1887  return (*this)->has_spfwd();
1888  }

◆ has_sprev()

bool casadi::Function::has_sprev ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xl

Definition at line 1890 of file function.cpp.

1890  {
1891  return (*this)->has_sprev();
1892  }

◆ hessian_old()

Function casadi::Function::hessian_old ( casadi_int  iind,
casadi_int  oind 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w5

Definition at line 1048 of file function.cpp.

1048  {
1049  // Redirect to factory class
1050  std::vector<std::string> s_in = name_in();
1051  std::vector<std::string> s_out = name_out();
1052  s_out.insert(s_out.begin(), "grad:" + name_out(oind) + ":" + name_in(iind));
1053  s_out.insert(s_out.begin(),
1054  "hess:" + name_out(oind) + ":" + name_in(iind) + ":" + name_in(iind));
1055  return factory(name() + "_hess", s_in, s_out);
1056  }
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
Definition: function.cpp:2009

References casadi::Function::factory(), casadi::Function::name(), casadi::Function::name_in(), and casadi::Function::name_out().

◆ if_else()

Function casadi::Function::if_else ( const std::string &  name,
const Function f_true,
const Function f_false,
const Dict opts = Dict() 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wp

Definition at line 962 of file function.cpp.

963  {
964  try {
965  return create(new Switch(name, std::vector<Function>(1, f_false), f_true), opts);
966  } catch(std::exception& e) {
967  THROW_ERROR_NOOBJ("if_else", e.what(), "Switch");
968  }
969  }

References casadi::Function::create(), and casadi::Function::name().

Referenced by casadi::Function::conditional(), and casadi::MX::if_else().

◆ index_in()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vk

Definition at line 1121 of file function.cpp.

1121  {
1122  try {
1123  return (*this)->index_in(name);
1124  } catch(std::exception& e) {
1125  THROW_ERROR("index_in", e.what());
1126  }
1127  }

References casadi::Function::name().

Referenced by casadi::Function::buf_in(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::Function::map(), casadi::Function::mapaccum(), casadi::Function::sparsity_in(), casadi::DaeBuilderInternal::transition(), and casadi::DaeBuilderInternal::update_dependencies().

◆ index_out()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vl

Definition at line 1129 of file function.cpp.

1129  {
1130  try {
1131  return (*this)->index_out(name);
1132  } catch(std::exception& e) {
1133  THROW_ERROR("index_out", e.what());
1134  }
1135  }

References casadi::Function::name().

Referenced by casadi::Function::buf_out(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::Function::map(), casadi::Function::mapaccum(), casadi::Function::sparsity_out(), and casadi::DaeBuilderInternal::update_dependencies().

◆ info()

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

Obtain information about function

Definition at line 2138 of file function.cpp.

2138  {
2139  return (*this)->info();
2140  }

◆ init()

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

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_o6

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

88 {}

◆ instruction_constant()

double casadi::Function::instruction_constant ( casadi_int  k) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xh

Definition at line 1946 of file function.cpp.

1946  {
1947  try {
1948  return (*this)->instruction_constant(k);
1949  } catch(std::exception& e) {
1950  THROW_ERROR("instruction_constant", e.what());
1951  }
1952  }

Referenced by casadi::SXFunction::export_code_body().

◆ instruction_id()

casadi_int casadi::Function::instruction_id ( casadi_int  k) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xf

Definition at line 1930 of file function.cpp.

1930  {
1931  try {
1932  return (*this)->instruction_id(k);
1933  } catch(std::exception& e) {
1934  THROW_ERROR("instruction_id", e.what());
1935  }
1936  }

Referenced by casadi::MXFunction::export_code_body(), casadi::SXFunction::export_code_body(), and casadi::Onnx::load().

◆ instruction_input()

std::vector< casadi_int > casadi::Function::instruction_input ( casadi_int  k) const
inherited

(SXFunction/MXFunction)

Extra doc: https://github.com/casadi/casadi/wiki/L_1xg

Definition at line 1938 of file function.cpp.

1938  {
1939  try {
1940  return (*this)->instruction_input(k);
1941  } catch(std::exception& e) {
1942  THROW_ERROR("instruction_input", e.what());
1943  }
1944  }

Referenced by casadi::MXFunction::export_code_body(), casadi::SXFunction::export_code_body(), and casadi::Onnx::load().

◆ instruction_MX()

MX casadi::Function::instruction_MX ( casadi_int  k) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xj

Definition at line 1914 of file function.cpp.

1914  {
1915  try {
1916  return (*this)->instruction_MX(k);
1917  } catch(std::exception& e) {
1918  THROW_ERROR("instruction_MX", e.what());
1919  }
1920  }

Referenced by casadi::MXFunction::export_code_body(), and casadi::Onnx::load().

◆ instruction_output()

std::vector< casadi_int > casadi::Function::instruction_output ( casadi_int  k) const
inherited

(SXFunction/MXFunction)

Extra doc: https://github.com/casadi/casadi/wiki/L_1xi

Definition at line 1954 of file function.cpp.

1954  {
1955  try {
1956  return (*this)->instruction_output(k);
1957  } catch(std::exception& e) {
1958  THROW_ERROR("instruction_output", e.what());
1959  }
1960  }

Referenced by casadi::MXFunction::export_code_body(), casadi::SXFunction::export_code_body(), and casadi::Onnx::load().

◆ instructions_sx()

SX casadi::Function::instructions_sx ( ) const
inherited

Note: input and output instructions have no SX representation. This method returns nan for those instructions.

Extra doc: https://github.com/casadi/casadi/wiki/L_1xk

Definition at line 1922 of file function.cpp.

1922  {
1923  try {
1924  return (*this)->instructions_sx();
1925  } catch(std::exception& e) {
1926  THROW_ERROR("instructions_sx", e.what());
1927  }
1928  }

◆ is_a()

bool casadi::Function::is_a ( const std::string &  type,
bool  recursive = true 
) const
inherited

Optionally check if name matches one of the base classes (default true)

Extra doc: https://github.com/casadi/casadi/wiki/L_1xw

Definition at line 1861 of file function.cpp.

1861  {
1862  return (*this)->is_a(type, recursive);
1863  }

Referenced by casadi::Integrator::augmented_dae(), casadi::Integrator::get_forward_dae(), casadi::MXFunction::get_stats(), casadi::Function::map(), and casadi::Function::transform().

◆ is_diff_in() [1/2]

std::vector< bool > casadi::Function::is_diff_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vt

Definition at line 1215 of file function.cpp.

1215  {
1216  try {
1217  return (*this)->is_diff_in_;
1218  } catch(std::exception& e) {
1219  THROW_ERROR("is_diff_in", e.what());
1220  }
1221  }

◆ is_diff_in() [2/2]

bool casadi::Function::is_diff_in ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vt

Definition at line 1199 of file function.cpp.

1199  {
1200  try {
1201  return (*this)->is_diff_in_.at(ind);
1202  } catch(std::exception& e) {
1203  THROW_ERROR("is_diff_in", e.what());
1204  }
1205  }

Referenced by casadi::FunctionInternal::get_sparsity_out(), casadi::Map::init(), and casadi::MapSum::init().

◆ is_diff_out() [1/2]

std::vector< bool > casadi::Function::is_diff_out ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vt

Definition at line 1223 of file function.cpp.

1223  {
1224  try {
1225  return (*this)->is_diff_out_;
1226  } catch(std::exception& e) {
1227  THROW_ERROR("is_diff_out", e.what());
1228  }
1229  }

◆ is_diff_out() [2/2]

bool casadi::Function::is_diff_out ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vt

Definition at line 1207 of file function.cpp.

1207  {
1208  try {
1209  return (*this)->is_diff_out_.at(ind);
1210  } catch(std::exception& e) {
1211  THROW_ERROR("is_diff_out", e.what());
1212  }
1213  }

Referenced by casadi::FunctionInternal::get_sparsity_out(), casadi::Map::init(), and casadi::MapSum::init().

◆ is_null()

Definition at line 116 of file generic_shared_impl.hpp.

120  {
121  return node==nullptr;
122  }

◆ jac_sparsity() [1/2]

const std::vector< Sparsity > & casadi::Function::jac_sparsity ( bool  compact = false) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ws

Definition at line 1092 of file function.cpp.

1092  {
1093  // Make sure all are calculated
1094  for (casadi_int oind = 0; oind < n_out(); ++oind) {
1095  for (casadi_int iind = 0; iind < n_in(); ++iind) {
1096  (void)jac_sparsity(oind, iind, compact);
1097  }
1098  }
1099  // Return reference to internal cache
1100  return (*this)->jac_sparsity_[compact];
1101  }
const std::vector< Sparsity > & jac_sparsity(bool compact=false) const
Get, if necessary generate, the sparsity of all Jacobian blocks.
Definition: function.cpp:1092

References casadi::Function::n_in(), and casadi::Function::n_out().

Referenced by casadi::_jacobian_sparsity(), casadi::CodeGenerator::add(), casadi::FunctionInternal::get_sparsity_out(), casadi::Integrator::sp_jac_dae(), casadi::Integrator::sp_jac_rdae(), and casadi::DaeBuilderInternal::update_dependencies().

◆ jac_sparsity() [2/2]

Sparsity casadi::Function::jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  compact = false 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wt

Definition at line 1103 of file function.cpp.

1103  {
1104  try {
1105  bool symm = (*this)->jac_is_symm(oind, iind);
1106  symm = symm && sparsity_out(oind).is_dense();
1107  return (*this)->jac_sparsity(oind, iind, compact, symm);
1108  } catch(std::exception& e) {
1109  THROW_ERROR("jac_sparsity", e.what());
1110  }
1111  }
bool is_dense() const
Is dense?
Definition: sparsity.cpp:273

References casadi::Sparsity::is_dense(), and casadi::Function::sparsity_out().

◆ jacobian()

Function casadi::Function::jacobian ( ) const
inherited

Generates a function that takes all non-differentiated inputs and outputs and calculates all Jacobian blocks. Inputs that are not needed by the routine are all-zero sparse matrices with the correct dimensions. Output blocks that are not calculated, e.g. if the corresponding input or output is marked non-differentiated are also all-zero sparse. The Jacobian blocks are sorted starting by all the blocks for the first output, then all the blocks for the second output and so on. E.g. f : (x, y) -> (r, s) results in the function jac_f : (x, y, out_r, out_s) -> (jac_r_x, jac_r_y, jac_s_x, jac_s_y)

This function is cached.

Extra doc: https://github.com/casadi/casadi/wiki/L_1w6

Definition at line 1068 of file function.cpp.

1068  {
1069  try {
1070  return (*this)->jacobian();
1071  } catch(std::exception& e) {
1072  THROW_ERROR("jacobian", e.what());
1073  }
1074  }

References casadi::FunctionInternal::jacobian().

Referenced by casadi::DaeBuilderInternal::CallIO::calc_jac(), and casadi::FunctionInternal::jacobian().

◆ jacobian_old()

Function casadi::Function::jacobian_old ( casadi_int  iind,
casadi_int  oind 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w4

Definition at line 1040 of file function.cpp.

1040  {
1041  // Redirect to factory class
1042  std::vector<std::string> s_in = name_in();
1043  std::vector<std::string> s_out = name_out();
1044  s_out.insert(s_out.begin(), "jac:" + name_out(oind) + ":" + name_in(iind));
1045  return factory(name() + "_jac", s_in, s_out);
1046  }

References casadi::Function::factory(), casadi::Function::name(), casadi::Function::name_in(), and casadi::Function::name_out().

◆ jit() [1/2]

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

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; }

Extra doc: https://github.com/casadi/casadi/wiki/L_1v3

Definition at line 289 of file function.cpp.

292  {
293  // Pass empty vectors -> default values
294  std::vector<Sparsity> sparsity_in, sparsity_out;
295  return jit(name, body, name_in, name_out, sparsity_in, sparsity_out, opts);
296  }
const Sparsity & sparsity_in(casadi_int ind) const
Get sparsity of a given input.
Definition: function.cpp:1167
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())
Create a just-in-time compiled function from a C language string.
Definition: function.cpp:289

References casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::sparsity_in(), and casadi::Function::sparsity_out().

Referenced by casadi::JitFunction::get_jacobian().

◆ jit() [2/2]

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

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; }

Extra doc: https://github.com/casadi/casadi/wiki/L_1v3

Definition at line 298 of file function.cpp.

303  {
304  try {
305  return create(new JitFunction(name, body, name_in, name_out,
306  sparsity_in, sparsity_out), opts);
307  } catch(std::exception& e) {
308  THROW_ERROR_NOOBJ("jit", e.what(), "JitFunction");
309  }
310  }

References casadi::Function::create(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::sparsity_in(), and casadi::Function::sparsity_out().

◆ load()

Function casadi::Function::load ( const std::string &  filename)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1y1

Definition at line 1546 of file function.cpp.

1546  {
1547  FileDeserializer fs(filename);
1548  auto t = fs.pop_type();
1549  if (t==SerializerBase::SerializationType::SERIALIZED_FUNCTION) {
1550  return fs.blind_unpack_function();
1551  } else {
1552  casadi_error("File is not loadable with 'load'. Use 'FileDeserializer' instead.");
1553  }
1554  }
std::string filename(const std::string &path)
Definition: ghc.cpp:55

References casadi::DeserializerBase::blind_unpack_function(), casadi::filename(), and casadi::DeserializerBase::pop_type().

Referenced by casadi::DaeBuilderInternal::load_fmi_description().

◆ map() [1/5]

Function casadi::Function::map ( casadi_int  n,
const std::string &  parallelization,
casadi_int  max_num_threads 
) const
inherited

Definition at line 830 of file function.cpp.

831  {
832  casadi_assert(max_num_threads>=1, "max_num_threads invalid.");
833  // No need for logic when we are not saturating the limit
834  if (n<=max_num_threads) return map(n, parallelization);
835 
836  // Floored division
837  casadi_int d = n/max_num_threads;
838  if (d*max_num_threads==n) {
839  // Easy when n is divisable by max_num_threads
840  return map(d, "serial").map(max_num_threads, parallelization);
841  } else {
842  // Create a base map that computes a bit too much
843  Function base = map(d+1, "serial").map(max_num_threads, parallelization);
844  std::vector<MX> ret_in, base_in;
845  casadi_int rem = (d+1)*max_num_threads-n;
846  for (casadi_int i=0;i<n_in();++i) {
847  MX arg = MX::sym("arg", repmat(sparsity_in(i), 1, n));
848  ret_in.push_back(arg);
849  MX last_arg = arg(Slice(), range((n-1)*size2_in(i), n*size2_in(i))); // NOLINT
850  base_in.push_back(horzcat(arg, repmat(last_arg, 1, rem)));
851  }
852  std::vector<MX> ret_out = base(base_in);
853  for (casadi_int i=0;i<n_out();++i) {
854  ret_out[i] = horzsplit(ret_out[i], {0, n*size2_out(i), ret_out[i].size2()})[0];
855  }
856  return Function("helper", ret_in, ret_out, name_in(), name_out());
857  }
858  }
Function map(casadi_int n, const std::string &parallelization="serial") const
Create a mapped version of this function.
Definition: function.cpp:861

References casadi::Function::Function(), casadi::Function::map(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::range(), casadi::Function::size2_in(), casadi::Function::size2_out(), casadi::Function::sparsity_in(), and casadi::GenericMatrix< MX >::sym().

◆ map() [2/5]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1wj

Definition at line 861 of file function.cpp.

861  {
862  // Make sure not degenerate
863  casadi_assert(n>0, "Degenerate map operation");
864  // Quick return if possible
865  if (n==1) return *this;
866  // Unroll?
867  if (parallelization=="unroll" || parallelization=="inline") {
868  // Construct symbolic inputs
869  std::vector<MX> arg(n_in());
870  std::vector<std::vector<MX>> v(n, arg);
871  std::vector<MX> tmp(n);
872  for (casadi_int i=0; i<arg.size(); ++i) {
873  for (casadi_int k=0; k<n; ++k) {
874  tmp[k] = v[k][i] = MX::sym(name_in(i)+"_"+str(k), sparsity_in(i));
875  }
876  arg[i] = horzcat(tmp);
877  }
878  // Evaluate
879  if (parallelization=="unroll") {
880  for (auto&& w : v) w = (*this)(w);
881  } else {
882  for (auto&& w : v) call(std::vector<MX>(w), w, !is_a("SXFunction"), false);
883  }
884  // Gather outputs
885  std::vector<MX> res(n_out());
886  for (casadi_int i=0; i<res.size(); ++i) {
887  for (casadi_int k=0; k<n; ++k) tmp[k] = v[k][i];
888  res[i] = horzcat(tmp);
889  }
890  // Construct function
891  return Function(name() + "_" + str(n), arg, res, name_in(), name_out());
892  } else {
893  // Generate/retrieve potentially cached map
894  return (*this)->map(n, parallelization);
895  }
896  }
bool is_a(const std::string &type, bool recursive=true) const
Check if the function is of a particular type.
Definition: function.cpp:1861

References casadi::Function::call(), casadi::Function::Function(), casadi::Function::is_a(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::sparsity_in(), casadi::str(), and casadi::GenericMatrix< MX >::sym().

Referenced by casadi::Dple::get_forward(), casadi::Expm::get_forward(), casadi::External::get_forward(), casadi::Map::get_forward(), casadi::Dple::get_reverse(), casadi::Expm::get_reverse(), casadi::External::get_reverse(), casadi::Map::get_reverse(), and casadi::Function::map().

◆ map() [3/5]

Function casadi::Function::map ( casadi_int  n,
const std::vector< bool > &  reduce_in,
const std::vector< bool > &  reduce_out = std::vector<bool>(),
const Dict opts = Dict() 
) const
inherited

A subset of the inputs are non-repeated and a subset of the outputs summed up.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wk

Definition at line 789 of file function.cpp.

792  {
793  return MapSum::create("mapsum_" + str(n) + "_" + name(), "serial",
794  *this, n, reduce_in, reduce_out, opts);
795  }
static Function create(const std::string &name, const std::string &parallelization, const Function &f, casadi_int n, const std::vector< bool > &reduce_in, const std::vector< bool > &reduce_out, const Dict &opts=Dict())
Definition: mapsum.cpp:31

References casadi::MapSum::create(), casadi::Function::name(), and casadi::str().

◆ map() [4/5]

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

A subset of the inputs are non-repeated and a subset of the outputs summed up.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wk

Definition at line 797 of file function.cpp.

799  {
800  // Wrap in an MXFunction
801  Function f = map(n, parallelization);
802  // Start with the fully mapped inputs
803  std::vector<MX> arg = f.mx_in();
804  std::vector<MX> f_arg = arg;
805  // Replace reduced inputs
806  for (casadi_int i : reduce_in) {
807  arg[i] = mx_in(i);
808  f_arg[i] = repmat(arg[i], 1, n);
809  }
810  // Get fully mapped outputs
811  std::vector<MX> res = f(f_arg);
812  // Replace reduced outputs
813  for (casadi_int i : reduce_out) {
814  res[i] = repsum(res[i], 1, n);
815  }
816  // Construct return
817  return Function(name, arg, res, name_in(), name_out());
818  }
const std::vector< MX > mx_in() const
Get symbolic primitives equivalent to the input expressions.
Definition: function.cpp:1789

References casadi::Function::Function(), casadi::Function::map(), casadi::Function::mx_in(), casadi::Function::name(), casadi::Function::name_in(), and casadi::Function::name_out().

◆ map() [5/5]

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

A subset of the inputs are non-repeated and a subset of the outputs summed up.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wk

Definition at line 820 of file function.cpp.

822  {
823  std::vector<casadi_int> reduce_in_num, reduce_out_num;
824  for (const std::string& s : reduce_in) reduce_in_num.push_back(index_in(s));
825  for (const std::string& s : reduce_out) reduce_out_num.push_back(index_out(s));
826  return map(name, parallelization, n, reduce_in_num, reduce_out_num, opts);
827  }

References casadi::Function::index_in(), casadi::Function::index_out(), casadi::Function::map(), and casadi::Function::name().

◆ mapaccum() [1/6]

Function casadi::Function::mapaccum ( 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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Definition at line 668 of file function.cpp.

668  {
669  return mapaccum("mapaccum_"+name(), N, opts);
670  }

References casadi::Function::mapaccum(), and casadi::Function::name().

◆ mapaccum() [2/6]

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Definition at line 674 of file function.cpp.

675  {
676  Dict options = opts;
677 
678  // Default base
679  casadi_int base = 10;
680  auto it = options.find("base");
681  if (it!=options.end()) {
682  base = it->second;
683  options.erase(it);
684  }
685 
686  casadi_assert(N>0, "mapaccum: N must be positive");
687 
688  if (base==-1)
689  return mapaccum(name, std::vector<Function>(N, *this), n_accum, options);
690  casadi_assert(base>=2, "mapaccum: base must be positive");
691 
692  // Decompose N into
693  std::vector<Function> chain;
694  Function c = *this;
695  while (N!=0) {
696  casadi_int r = N % base;
697  chain.insert(chain.end(), r, c);
698  N = (N-r)/base;
699  c = c.mapaccum(c.name()+"_acc"+str(base), std::vector<Function>(base, c), n_accum, options);
700  }
701  return mapaccum(name, chain, n_accum, options);
702  }

References casadi::Function::mapaccum(), casadi::Function::name(), and casadi::str().

◆ mapaccum() [3/6]

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Definition at line 671 of file function.cpp.

671  {
672  return mapaccum(name, N, 1, opts);
673  }

References casadi::Function::name().

Referenced by casadi::MX::cumsum(), casadi::Function::fold(), and casadi::Function::mapaccum().

◆ mapaccum() [4/6]

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Definition at line 749 of file function.cpp.

752  {
753  // Shorthands
754  casadi_int n_in = this->n_in(), n_out = this->n_out();
755  // Consistency checks
756  casadi_assert_dev(in_range(accum_in, n_in) && isUnique(accum_in));
757  casadi_assert_dev(in_range(accum_out, n_out) && isUnique(accum_out));
758  casadi_assert_dev(accum_in.size()==accum_out.size());
759  casadi_int n_accum=accum_in.size();
760 
761  // Quick return if no need to reorder
762  if (accum_in==range(n_accum) && accum_out==range(n_accum)) {
763  return mapaccum(name, n, n_accum, opts);
764  }
765 
766  // Need to do some reordering
767  std::vector<casadi_int> temp_in = complement(accum_in, n_in);
768  std::vector<casadi_int> order_in = accum_in;
769  order_in.insert(order_in.end(), temp_in.begin(), temp_in.end());
770  std::vector<casadi_int> temp_out = complement(accum_out, n_out);
771  std::vector<casadi_int> order_out = accum_out;
772  order_out.insert(order_out.end(), temp_out.begin(), temp_out.end());
773  Function ret = slice("slice_" + name, order_in, order_out);
774  ret = ret.mapaccum("mapacc_" + name, n, n_accum, opts);
775  return ret.slice(name, lookupvector(order_in, n_in),
776  lookupvector(order_out, n_out), opts);
777  }
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
Definition: function.cpp:899
bool isUnique(const std::vector< T > &v)
std::vector< casadi_int > lookupvector(const std::vector< casadi_int > &v, casadi_int size)
Returns a vector for quickly looking up entries of supplied list.
bool in_range(const std::vector< T > &v, casadi_int upper)
Check if for each element of v holds: v_i < upper.
std::vector< casadi_int > complement(const std::vector< casadi_int > &v, casadi_int size)
Returns the list of all i in [0, size[ not found in supplied list.

References casadi::complement(), casadi::in_range(), casadi::isUnique(), casadi::lookupvector(), casadi::Function::mapaccum(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::name(), casadi::range(), and casadi::Function::slice().

◆ mapaccum() [5/6]

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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wi

Definition at line 779 of file function.cpp.

782  {
783  std::vector<casadi_int> accum_in_num, accum_out_num;
784  for (const std::string& s : accum_in) accum_in_num.push_back(index_in(s));
785  for (const std::string& s : accum_out) accum_out_num.push_back(index_out(s));
786  return mapaccum(name, n, accum_in_num, accum_out_num, opts);
787  }

References casadi::Function::index_in(), casadi::Function::index_out(), casadi::Function::mapaccum(), and casadi::Function::name().

◆ mapaccum() [6/6]

Function casadi::Function::mapaccum ( const std::string &  name,
const std::vector< Function > &  chain,
casadi_int  n_accum = 1,
const Dict opts = Dict() 
) const
protectedinherited

Definition at line 704 of file function.cpp.

706  {
707  // Shorthands
708  casadi_int n_in = this->n_in(), n_out = this->n_out();
709  // Consistency checks
710  casadi_assert(!chain.empty(), "mapaccum: chain must be non-empty");
711  casadi_assert(n_accum<=std::min(n_in, n_out), "mapaccum: too many accumulators");
712  // Quick return?
713  if (chain.size()==1) return chain[0];
714  // Get symbolic expressions for inputs and outputs
715  std::vector<MX> arg = mx_in();
716  std::vector<MX> res;
717  // Vectorized inputs and outputs
718  std::vector<std::vector<MX>> varg(n_in), vres(n_out);
719  for (casadi_int i=0; i<n_accum; ++i) varg[i].push_back(arg[i]);
720  // For each function call
721  for (const auto& f : chain) {
722 
723  // Stacked input expressions
724  for (casadi_int i=n_accum; i<n_in; ++i) {
725  arg[i] = MX::sym(name_in(i) + "_" + str(i), f.sparsity_in(i));
726  varg[i].push_back(arg[i]);
727  }
728 
729  // Call f
730  res = f(arg);
731  // Save output expressions
732  for (casadi_int i=0; i<n_out; ++i) vres[i].push_back(res[i]);
733  // Copy function output to input
734  std::copy_n(res.begin(), n_accum, arg.begin());
735  for (casadi_int i=0; i<n_accum; ++i) {
736  // Ony get last component (allows nested calls)
737  casadi_int ncol_out=f.size2_out(i), ncol_in=size2_in(i);
738  if (ncol_out>ncol_in) {
739  arg[i] = horzsplit(arg[i], {0, ncol_out-ncol_in, ncol_out}).back();
740  }
741  }
742  }
743  // Construct return
744  for (casadi_int i=0; i<n_in; ++i) arg[i] = horzcat(varg[i]);
745  for (casadi_int i=0; i<n_out; ++i) res[i] = horzcat(vres[i]);
746  return Function(name, arg, res, name_in(), name_out(), opts);
747  }

References casadi::Function::Function(), casadi::Function::mx_in(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::size2_in(), casadi::str(), and casadi::GenericMatrix< MX >::sym().

◆ mapsum()

std::vector< MX > casadi::Function::mapsum ( const std::vector< MX > &  x,
const std::string &  parallelization = "serial" 
) const
inherited
Parameters
parallelizationType of parallelization used: unroll|serial|openmp

Extra doc: https://github.com/casadi/casadi/wiki/L_1wh

Definition at line 908 of file function.cpp.

909  {
910  try {
911  return (*this)->mapsum_mx(x, parallelization);
912  } catch(std::exception& e) {
913  THROW_ERROR("mapsum", e.what());
914  }
915  }

◆ max_in()

double casadi::Function::max_in ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vn

Definition at line 1681 of file function.cpp.

1681  {
1682  return (*this)->get_max_in(ind);
1683  }

◆ memory()

void * casadi::Function::memory ( int  ind) const
inherited

◆ merge()

void casadi::Function::merge ( const std::vector< MX > &  arg,
std::vector< MX > &  subs_from,
std::vector< MX > &  subs_to 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2b6

Definition at line 1865 of file function.cpp.

1866  {
1867  (*this)->merge(arg, subs_from, subs_to);
1868  }

◆ min_in()

double casadi::Function::min_in ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vo

Definition at line 1685 of file function.cpp.

1685  {
1686  return (*this)->get_min_in(ind);
1687  }

◆ mx_in() [1/3]

const std::vector< MX > casadi::Function::mx_in ( ) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

Definition at line 1789 of file function.cpp.

1789  {
1790  return (*this)->mx_in();
1791  }

Referenced by casadi::Function::map(), and casadi::Function::mapaccum().

◆ mx_in() [2/3]

const MX casadi::Function::mx_in ( casadi_int  ind) const
inherited

◆ mx_in() [3/3]

const MX casadi::Function::mx_in ( const std::string &  iname) const
inlineinherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

Definition at line 1015 of file function.hpp.

1015  {
1016  return mx_in(index_in(iname));
1017  }

◆ mx_out() [1/3]

const std::vector< MX > casadi::Function::mx_out ( ) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x5

Definition at line 1793 of file function.cpp.

1793  {
1794  return (*this)->mx_out();
1795  }

◆ mx_out() [2/3]

const MX casadi::Function::mx_out ( casadi_int  ind) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x5

Definition at line 1785 of file function.cpp.

1785  {
1786  return (*this)->mx_out(ind);
1787  }

◆ mx_out() [3/3]

const MX casadi::Function::mx_out ( const std::string &  oname) const
inlineinherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x5

Definition at line 1043 of file function.hpp.

1043  {
1044  return mx_out(index_out(oname));
1045  }
const std::vector< MX > mx_out() const
Get symbolic primitives equivalent to the output expressions.
Definition: function.cpp:1793

◆ n_in()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1v8

Definition at line 971 of file function.cpp.

971  {
972  return (*this)->n_in_;
973  }

Referenced by casadi::Function::activity(), casadi::CodeGenerator::add(), casadi::Function::buf_in(), casadi::OracleFunction::calc_function(), casadi::DaeBuilderInternal::CallIO::calc_jac(), casadi::Call::Call(), casadi::Function::call_gen(), casadi::Nlpsol::callback(), casadi::FiniteDiff::codegen_body(), casadi::Sqpmethod::codegen_qp_ela_solve(), casadi::Feasiblesqpmethod::codegen_qp_solve(), casadi::Sqpmethod::codegen_qp_solve(), casadi::construct_nlpsol(), casadi::Call::create(), casadi::MapSum::create(), casadi::OracleFunction::create_function(), casadi::FiniteDiff::eval(), casadi::Scpgen::eval_exp(), casadi::Scpgen::eval_mat(), casadi::Scpgen::eval_res(), casadi::CallSX::eval_sx(), casadi::Scpgen::eval_vec(), casadi::SXFunction::ExtendedAlgEl::ExtendedAlgEl(), casadi::External::factory(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::FunctionInternal::forward(), casadi::CodeGenerator::generate_dump(), casadi::CodeGenerator::generate_print(), casadi::FiniteDiff::get_default_in(), casadi::FunctionInternal::get_n_in(), casadi::FiniteDiff::get_n_in(), casadi::Switch::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::FiniteDiff::get_name_in(), casadi::FunctionInternal::get_name_out(), casadi::FunctionInternal::get_sparsity_in(), casadi::FiniteDiff::get_sparsity_in(), casadi::FunctionInternal::get_sparsity_out(), casadi::Integrator::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::BonminInterface::init(), casadi::GurobiInterface::init(), casadi::IpoptInterface::init(), casadi::FastNewton::init(), casadi::Feasiblesqpmethod::init(), casadi::Newton::init(), casadi::Sqpmethod::init(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::Function::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::Onnx::load(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::Function::map(), casadi::Function::mapaccum(), casadi::MapSum::MapSum(), casadi::SymbolicQr::nfact(), casadi::SXFunction::print(), casadi::SXNode::print_compact(), casadi::qpsol_nlp(), casadi::Function::rev(), casadi::FunctionInternal::reverse(), casadi::simpleIntegrator(), casadi::simpleIRK(), casadi::simpleRK(), casadi::WorhpInterface::solve(), casadi::Scpgen::solve(), casadi::SymbolicQr::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Scpgen::solve_qp(), casadi::Sqpmethod::solve_QP(), and casadi::ThreadsWork().

◆ n_instructions()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1xe

Definition at line 1906 of file function.cpp.

1906  {
1907  try {
1908  return (*this)->n_instructions();
1909  } catch(std::exception& e) {
1910  THROW_ERROR("n_instructions", e.what());
1911  }
1912  }

Referenced by casadi::MXFunction::export_code_body(), casadi::SXFunction::export_code_body(), casadi::Onnx::load(), and casadi::transform_stats().

◆ n_nodes()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1xd

Definition at line 1962 of file function.cpp.

1962  {
1963  try {
1964  return (*this)->n_nodes();
1965  } catch(std::exception& e) {
1966  THROW_ERROR("n_nodes", e.what());
1967  }
1968  }

Referenced by casadi::Scpgen::init(), casadi::MX::n_nodes(), and casadi::transform_stats().

◆ n_out()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1v9

Definition at line 975 of file function.cpp.

975  {
976  return (*this)->n_out_;
977  }

Referenced by casadi::Function::activity(), casadi::CodeGenerator::add(), casadi::Function::buf_out(), casadi::OracleFunction::calc_function(), casadi::DaeBuilderInternal::CallIO::calc_jac(), casadi::Function::call_gen(), casadi::Nlpsol::callback(), casadi::FiniteDiff::codegen_body(), casadi::Sqpmethod::codegen_qp_ela_solve(), casadi::Feasiblesqpmethod::codegen_qp_solve(), casadi::Sqpmethod::codegen_qp_solve(), casadi::Function::conditional(), casadi::construct_nlpsol(), casadi::Call::create(), casadi::MapSum::create(), casadi::OracleFunction::create_function(), casadi::FiniteDiff::eval(), casadi::Scpgen::eval_exp(), casadi::Scpgen::eval_mat(), casadi::Scpgen::eval_res(), casadi::CallSX::eval_sx(), casadi::Scpgen::eval_vec(), casadi::MXFunction::export_code_body(), casadi::SXFunction::ExtendedAlgEl::ExtendedAlgEl(), casadi::External::factory(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::FunctionInternal::forward(), casadi::CodeGenerator::generate_dump(), casadi::CodeGenerator::generate_print(), casadi::FunctionInternal::get_n_in(), casadi::FiniteDiff::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::FiniteDiff::get_n_out(), casadi::Switch::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::FiniteDiff::get_name_in(), casadi::FunctionInternal::get_sparsity_in(), casadi::FiniteDiff::get_sparsity_in(), casadi::Integrator::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::BonminInterface::init(), casadi::GurobiInterface::init(), casadi::IpoptInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Sqpmethod::init(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::Function::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::Onnx::load(), casadi::Function::map(), casadi::Function::mapaccum(), casadi::MapSum::MapSum(), casadi::SymbolicQr::nfact(), casadi::Call::nout(), casadi::SXFunction::print(), casadi::qpsol_nlp(), casadi::Function::rev(), casadi::FunctionInternal::reverse(), casadi::simpleIntegrator(), casadi::simpleIRK(), casadi::simpleRK(), casadi::WorhpInterface::solve(), casadi::Scpgen::solve(), casadi::SymbolicQr::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Scpgen::solve_qp(), casadi::Sqpmethod::solve_QP(), and casadi::ThreadsWork().

◆ name()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1xv

Definition at line 1504 of file function.cpp.

1504  {
1505  if (is_null()) {
1506  static std::string null = "null";
1507  return null;
1508  } else {
1509  return (*this)->name_;
1510  }
1511  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::CodeGenerator::add(), casadi::DaeBuilderInternal::add_fun(), casadi::Integrator::augmented_dae(), casadi::Function::bspline(), casadi::Call::Call(), casadi::Function::check_name(), casadi::Function::conditional(), construct(), casadi::Function::construct(), casadi::construct_nlpsol(), casadi::MapSum::create(), casadi::Map::create(), casadi::FixedStepIntegrator::create_advanced(), casadi::Call::disp(), casadi::Switch::disp_more(), casadi::Function::expand(), casadi::Function::factory(), casadi::Function::find_function(), casadi::Function::fix_name(), casadi::Function::fold(), casadi::Function::Function(), casadi::FunctionInternal::FunctionInternal(), casadi::Function::generate(), casadi::CodeGenerator::generate_dump(), casadi::CodeGenerator::generate_print(), get_factory(), get_forward(), casadi::MapSum::get_forward(), casadi::MXFunction::get_function(), casadi::SXFunction::get_function(), casadi::Function::get_function(), get_jacobian(), casadi::FunctionInternal::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::FunctionInternal::get_name_out(), get_reverse(), casadi::MapSum::get_reverse(), casadi::FunctionInternal::get_sparsity_in(), casadi::FunctionInternal::get_sparsity_out(), casadi::GraphBuilder::GraphBuilder(), casadi::Function::has_in(), casadi::Function::has_out(), casadi::Function::hessian_old(), casadi::Function::if_else(), casadi::Function::index_in(), casadi::Function::index_out(), casadi::FunctionInternal::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::Rootfinder::init(), casadi::SundialsInterface::init(), casadi::FunctionInternal::jac_is_symm(), casadi::Function::jacobian_old(), casadi::Function::jit(), casadi::Onnx::load(), casadi::FunctionInternal::map(), casadi::Function::map(), casadi::Function::mapaccum(), casadi::SXFunction::print(), casadi::SXNode::print_compact(), casadi::Function::print_option(), casadi::OptiNode::scale_helper(), casadi::OracleFunction::set_function(), casadi::RungeKutta::setup_step(), casadi::Function::slice(), casadi::FunctionInternal::tocache(), casadi::FunctionInternal::tocache_if_missing(), casadi::Function::transform(), casadi::Function::wrap(), and casadi::Function::wrap_as_needed().

◆ name_in() [1/2]

const std::vector< std::string > & casadi::Function::name_in ( ) const
inherited

◆ name_in() [2/2]

const std::string & casadi::Function::name_in ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vi

Definition at line 1151 of file function.cpp.

1151  {
1152  try {
1153  return (*this)->name_in_.at(ind);
1154  } catch(std::exception& e) {
1155  THROW_ERROR("name_in", e.what());
1156  }
1157  }

◆ name_out() [1/2]

const std::vector< std::string > & casadi::Function::name_out ( ) const
inherited

◆ name_out() [2/2]

const std::string & casadi::Function::name_out ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vj

Definition at line 1159 of file function.cpp.

1159  {
1160  try {
1161  return (*this)->name_out_.at(ind);
1162  } catch(std::exception& e) {
1163  THROW_ERROR("name_out", e.what());
1164  }
1165  }

◆ nnz_in() [1/3]

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

◆ nnz_in() [2/3]

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

For a particular input or for all of the inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vc

Definition at line 1019 of file function.cpp.

1019  {
1020  return (*this)->nnz_in(ind);
1021  }

◆ nnz_in() [3/3]

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

For a particular input or for all of the inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vc

Definition at line 302 of file function.hpp.

302 {return nnz_in(index_in(iname));}

References casadi::Function::nnz_in().

Referenced by casadi::Function::nnz_in().

◆ nnz_out() [1/3]

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

◆ nnz_out() [2/3]

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

For a particular output or for all of the outputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vd

Definition at line 1023 of file function.cpp.

1023  {
1024  return (*this)->nnz_out(ind);
1025  }

◆ nnz_out() [3/3]

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

For a particular output or for all of the outputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vd

Definition at line 313 of file function.hpp.

313 {return nnz_out(index_out(oname));}

References casadi::Function::nnz_out().

Referenced by casadi::Function::nnz_out().

◆ nominal_in()

std::vector< double > casadi::Function::nominal_in ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vp

Definition at line 1689 of file function.cpp.

1689  {
1690  return (*this)->get_nominal_in(ind);
1691  }

Referenced by casadi::Integrator::init().

◆ nominal_out()

std::vector< double > casadi::Function::nominal_out ( casadi_int  ind) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vq

Definition at line 1693 of file function.cpp.

1693  {
1694  return (*this)->get_nominal_out(ind);
1695  }

◆ numel_in() [1/3]

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

For a particular input or for all of the inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1ve

Definition at line 1011 of file function.cpp.

1011  {
1012  return (*this)->numel_in();
1013  }

Referenced by casadi::Integrator::init().

◆ numel_in() [2/3]

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

For a particular input or for all of the inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1ve

Definition at line 1027 of file function.cpp.

1027  {
1028  return (*this)->numel_in(ind);
1029  }

◆ numel_in() [3/3]

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

For a particular input or for all of the inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1ve

Definition at line 336 of file function.hpp.

336 {return numel_in(index_in(iname));}
casadi_int numel_in() const
Get number of input elements.
Definition: function.cpp:1011

References casadi::Function::numel_in().

Referenced by casadi::Function::numel_in().

◆ numel_out() [1/3]

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

For a particular output or for all of the outputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vf

Definition at line 1015 of file function.cpp.

1015  {
1016  return (*this)->numel_out();
1017  }

Referenced by casadi::Integrator::init(), and casadi::Nlpsol::init().

◆ numel_out() [2/3]

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

For a particular output or for all of the outputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vf

Definition at line 1031 of file function.cpp.

1031  {
1032  return (*this)->numel_out(ind);
1033  }

◆ numel_out() [3/3]

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

For a particular output or for all of the outputs

Extra doc: https://github.com/casadi/casadi/wiki/L_1vf

Definition at line 347 of file function.hpp.

347 {return numel_out(index_out(oname));}
casadi_int numel_out() const
Get number of output elements.
Definition: function.cpp:1015

References casadi::Function::numel_out().

Referenced by casadi::Function::numel_out().

◆ nz_from_in()

std::vector< double > casadi::Function::nz_from_in ( const std::vector< DM > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x6

Definition at line 1797 of file function.cpp.

1797  {
1798  return (*this)->nz_in(arg);
1799  }

Referenced by casadi::Function::generate_in().

◆ nz_from_out()

std::vector< double > casadi::Function::nz_from_out ( const std::vector< DM > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x6

Definition at line 1801 of file function.cpp.

1801  {
1802  return (*this)->nz_out(res);
1803  }

Referenced by casadi::Function::generate_out().

◆ nz_to_in()

std::vector< DM > casadi::Function::nz_to_in ( const std::vector< double > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x6

Definition at line 1805 of file function.cpp.

1805  {
1806  return (*this)->nz_in(arg);
1807  }

Referenced by casadi::Function::generate_in().

◆ nz_to_out()

std::vector< DM > casadi::Function::nz_to_out ( const std::vector< double > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x6

Definition at line 1809 of file function.cpp.

1809  {
1810  return (*this)->nz_out(res);
1811  }

Referenced by casadi::Function::generate_out().

◆ operator()() [1/24]

int casadi::Function::operator() ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
int  mem = 0 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1we

Definition at line 1243 of file function.cpp.

1244  {
1245  try {
1246  return (*this)->sp_forward(arg, res, iw, w, memory(mem));
1247  } catch(std::exception& e) {
1248  THROW_ERROR("operator()", e.what());
1249  }
1250  }

References casadi::Function::memory().

◆ operator()() [2/24]

std::vector<DM> casadi::Function::operator() ( const DM arg0) const
inlineinherited

Functor shorthand for evaluation, single argument (only C++)

Definition at line 651 of file function.hpp.

651  {
652  return operator()(std::vector<DM>{arg0});
653  }
std::vector< DM > operator()(const std::vector< DM > &arg) const
Definition: function.cpp:1597

◆ operator()() [3/24]

const DMDict casadi::Function::operator() ( const DMDict arg) const
inherited

Functor shorthand for evaluation

Definition at line 1632 of file function.cpp.

1632  {
1633  DMDict res;
1634  call(arg, res);
1635  return res;
1636  }
std::map< std::string, DM > DMDict
Definition: dm_fwd.hpp:36

References casadi::Function::call().

◆ operator()() [4/24]

int casadi::Function::operator() ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wc

Definition at line 1702 of file function.cpp.

1703  {
1704  scoped_checkout<Function> mem(*this);
1705  return operator()(arg, res, iw, w, mem);
1706  }

References casadi::Function::operator()().

◆ operator()() [5/24]

int casadi::Function::operator() ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
int  mem 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wb

Definition at line 1708 of file function.cpp.

1709  {
1710  try {
1711 #ifdef WITH_EXTRA_CHECKS
1712  // Should never happen
1713  casadi_assert_dev(call_depth_>=0);
1714  call_depth_++;
1715  // For consistency check
1716  casadi_int depth = call_depth_;
1717 #endif // WITH_EXTRA_CHECKS
1718  int ret = (*this)->eval_gen(arg, res, iw, w, memory(mem), false, false);
1719 #ifdef WITH_EXTRA_CHECKS
1720  // Consitency check
1721  casadi_assert_dev(call_depth_==depth);
1722  call_depth_--;
1723 #endif // WITH_EXTRA_CHECKS
1724  return ret;
1725  } catch (KeyboardInterruptException& e) {
1726  (void)e; // unused
1727 #ifdef WITH_EXTRA_CHECKS
1728  call_depth_--;
1729 #endif // WITH_EXTRA_CHECKS
1730  throw;
1731  } catch(std::exception& e) {
1732 #ifdef WITH_EXTRA_CHECKS
1733  call_depth_--;
1734 #endif // WITH_EXTRA_CHECKS
1735  (*this)->print_in(uerr(), arg, true);
1736  THROW_ERROR("operator()", e.what());
1737  }
1738  }
std::ostream & uerr()

References casadi::Function::memory(), casadi::uerr(), and casadi::CasadiException::what().

◆ operator()() [6/24]

std::vector<MX> casadi::Function::operator() ( const MX arg0) const
inlineinherited

Functor shorthand for evaluation, single argument (only C++)

Definition at line 657 of file function.hpp.

657  {
658  return operator()(std::vector<MX>{arg0});
659  }

◆ operator()() [7/24]

const MXDict casadi::Function::operator() ( const MXDict arg) const
inherited

Functor shorthand for evaluation

Definition at line 1644 of file function.cpp.

1644  {
1645  MXDict res;
1646  call(arg, res);
1647  return res;
1648  }
std::map< std::string, MX > MXDict
Definition: mx.hpp:1110

References casadi::Function::call().

◆ operator()() [8/24]

std::vector< DM > casadi::Function::operator() ( const std::vector< DM > &  arg) const
inherited

Functor shorthand for evaluation

Definition at line 1597 of file function.cpp.

1597  {
1598  std::vector<DM> res;
1599  call(arg, res);
1600  return res;
1601  }

References casadi::Function::call().

Referenced by casadi::Function::operator()().

◆ operator()() [9/24]

std::vector< MX > casadi::Function::operator() ( const std::vector< MX > &  arg) const
inherited

Functor shorthand for evaluation

Definition at line 1609 of file function.cpp.

1609  {
1610  std::vector<MX> res;
1611  call(arg, res);
1612  return res;
1613  }

References casadi::Function::call().

◆ operator()() [10/24]

std::vector< SX > casadi::Function::operator() ( const std::vector< SX > &  arg) const
inherited

Functor shorthand for evaluation

Definition at line 1603 of file function.cpp.

1603  {
1604  std::vector<SX> res;
1605  call(arg, res);
1606  return res;
1607  }

References casadi::Function::call().

◆ operator()() [11/24]

std::vector<SX> casadi::Function::operator() ( const SX arg0) const
inlineinherited

Functor shorthand for evaluation, single argument (only C++)

Definition at line 654 of file function.hpp.

654  {
655  return operator()(std::vector<SX>{arg0});
656  }

◆ operator()() [12/24]

const SXDict casadi::Function::operator() ( const SXDict arg) const
inherited

Functor shorthand for evaluation

Definition at line 1638 of file function.cpp.

1638  {
1639  SXDict res;
1640  call(arg, res);
1641  return res;
1642  }
std::map< std::string, SX > SXDict
Definition: sx_fwd.hpp:40

References casadi::Function::call().

◆ operator()() [13/24]

int casadi::Function::operator() ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem w,
int  mem = 0 
) const
inherited

Same syntax as the double version, allowing use in templated code

Extra doc: https://github.com/casadi/casadi/wiki/L_1wd

Definition at line 1740 of file function.cpp.

1741  {
1742  try {
1743  return (*this)->eval_sx(arg, res, iw, w, memory(mem), false, false);
1744  } catch(std::exception& e) {
1745  THROW_ERROR("operator()", e.what());
1746  }
1747  }

References casadi::Function::memory().

◆ operator()() [14/24]

void casadi::Function::operator() ( MapArg  arg,
MapRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 644 of file function.hpp.

644 { (*this)(buf_in(arg), buf_out(res)); }
std::vector< double * > buf_out(VecRes res) const
Supported arguments for numerical evaluation and converters.
Definition: function.cpp:547
std::vector< const double * > buf_in(VecArg arg) const
Supported arguments for numerical evaluation and converters.
Definition: function.cpp:536

◆ operator()() [15/24]

void casadi::Function::operator() ( MapArg  arg,
MPrRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 646 of file function.hpp.

646 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator()() [16/24]

void casadi::Function::operator() ( MapArg  arg,
VecRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 643 of file function.hpp.

643 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator()() [17/24]

void casadi::Function::operator() ( MapArg  arg,
VPrRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 645 of file function.hpp.

645 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator()() [18/24]

void casadi::Function::operator() ( std::vector< const bvec_t * >  arg,
std::vector< bvec_t * >  res 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w8

Definition at line 636 of file function.cpp.

636  {
637  call_gen(arg, res);
638  }

References casadi::Function::call_gen().

◆ operator()() [19/24]

void casadi::Function::operator() ( std::vector< const double * >  arg,
std::vector< double * >  res 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w8

Definition at line 632 of file function.cpp.

632  {
633  call_gen(arg, res);
634  }

References casadi::Function::call_gen().

◆ operator()() [20/24]

void casadi::Function::operator() ( std::vector< const SXElem * >  arg,
std::vector< SXElem * >  res 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w8

Definition at line 640 of file function.cpp.

640  {
641  call_gen(arg, res);
642  }

References casadi::Function::call_gen().

◆ operator()() [21/24]

void casadi::Function::operator() ( VecArg  arg,
MapRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 639 of file function.hpp.

639 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator()() [22/24]

void casadi::Function::operator() ( VecArg  arg,
MPrRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 641 of file function.hpp.

641 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator()() [23/24]

void casadi::Function::operator() ( VecArg  arg,
VecRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 638 of file function.hpp.

638 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator()() [24/24]

void casadi::Function::operator() ( VecArg  arg,
VPrRes  res 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wa

Definition at line 640 of file function.hpp.

640 { (*this)(buf_in(arg), buf_out(res)); }

◆ operator->()

FunctionInternal * casadi::Function::operator-> ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x3

Definition at line 500 of file function.cpp.

500  {
501  casadi_assert_dev(!is_null());
502  return get();
503  }

References casadi::Function::get(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

◆ operator==()

bool casadi::Function::operator== ( const Function f) const
inherited

Definition at line 2128 of file function.cpp.

2128  {
2129  try {
2130  casadi_assert(!is_null(), "lhs is null");
2131  casadi_assert(!f.is_null(), "rhs is null");
2132  return get()==f.get();
2133  } catch(std::exception& e) {
2134  THROW_ERROR("operator==", e.what());
2135  }
2136  }

References casadi::Function::get(), casadi::GenericShared< Shared, Internal >::is_null(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

◆ oracle()

Function casadi::Function::oracle ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vu

Definition at line 2104 of file function.cpp.

2104  {
2105  try {
2106  return (*this)->oracle();
2107  } catch(std::exception& e) {
2108  THROW_ERROR("oracle", e.what());
2109  }
2110  }

References casadi::FunctionInternal::oracle().

◆ order() [1/2]

std::vector< MX > casadi::Function::order ( const std::vector< MX > &  expr)
staticinherited

Definition at line 2146 of file function.cpp.

2146  {
2147  return MXFunction::order(expr);
2148  }
static std::vector< MX > order(const std::vector< MX > &expr)

References casadi::MXFunction::order().

◆ order() [2/2]

std::vector< SX > casadi::Function::order ( const std::vector< SX > &  expr)
staticinherited

Definition at line 2142 of file function.cpp.

2142  {
2143  return SXFunction::order(expr);
2144  }
static std::vector< SX > order(const std::vector< SX > &expr)

References casadi::SXFunction::order().

Referenced by casadi::SerializerBase::pack(), and casadi::Function::which_depends().

◆ own()

Assign the node to a node class pointer (or null)

Definition at line 89 of file generic_shared_impl.hpp.

◆ print_dimensions()

void casadi::Function::print_dimensions ( std::ostream &  stream = casadi::uout()) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vy

Definition at line 1340 of file function.cpp.

1340  {
1341  (*this)->print_dimensions(stream);
1342  }

◆ print_option()

void casadi::Function::print_option ( const std::string &  name,
std::ostream &  stream = casadi::uout() 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1w0

Definition at line 1348 of file function.cpp.

1348  {
1349  (*this)->print_option(name, stream);
1350  }

References casadi::Function::name().

◆ print_options()

void casadi::Function::print_options ( std::ostream &  stream = casadi::uout()) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vz

Definition at line 1344 of file function.cpp.

1344  {
1345  (*this)->print_options(stream);
1346  }

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ proceed_to()

bool casadi::Function::proceed_to ( std::istream &  file,
const std::string &  str 
)
staticprotectedinherited

Definition at line 64 of file function.cpp.

64  {
65  // Make sure that the file is ready for reading
66  if (!file.good()) return false;
67  // Have we already wrapped around once?
68  //bool wrapped_around = false;
69  // Read line-by-line
70  std::string tmp;
71  while (true) {
72  // Read a word
73  std::streampos cur_pos = file.tellg();
74  file >> tmp;
75  if (!file.good()) return false;
76 
77  // Check if match
78  if (str==tmp) return true;
79 
80  // If comment, continue to the end of the line
81  if (tmp.at(0)=='#') {
82  file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
83  continue;
84  }
85 
86  // If mismatching name, rewind and break
87  file.seekg(cur_pos);
88  return false;
89  }
90  }

References casadi::str().

◆ release()

void casadi::Function::release ( int  mem) const
inherited

Definition at line 1974 of file function.cpp.

1974  {
1975  (*this)->release(mem);
1976  }

Referenced by casadi::QpToNlp::free_mem(), casadi::Sqpmethod::free_mem(), casadi::FunctionBuffer::operator=(), and casadi::FunctionBuffer::~FunctionBuffer().

◆ reset_dump_count()

void casadi::Function::reset_dump_count ( )
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dy

Definition at line 1373 of file function.cpp.

1373  {
1374  try {
1375  (*this)->reset_dump_count();
1376  } catch(std::exception& e) {
1377  THROW_ERROR("reset_dump_count", e.what());
1378  }
1379  }

◆ rev() [1/2]

int casadi::Function::rev ( bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
int  mem = 0 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wf

Definition at line 1252 of file function.cpp.

1252  {
1253  try {
1254  return (*this)->sp_reverse(arg, res, iw, w, memory(mem));
1255  } catch(std::exception& e) {
1256  THROW_ERROR("rev", e.what());
1257  }
1258  }

References casadi::Function::memory().

Referenced by casadi::_which_depends(), casadi::Function::rev(), casadi::Call::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), and casadi::Rootfinder::sp_reverse().

◆ rev() [2/2]

int casadi::Function::rev ( std::vector< bvec_t * >  arg,
std::vector< bvec_t * >  res 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1wg

Definition at line 644 of file function.cpp.

644  {
645  // Input buffer
646  casadi_assert_dev(arg.size()>=n_in());
647  arg.resize(sz_arg());
648 
649  // Output buffer
650  casadi_assert_dev(res.size()>=n_out());
651  res.resize(sz_res());
652 
653  // Work vectors
654  std::vector<casadi_int> iw(sz_iw());
655  std::vector<bvec_t> w(sz_w());
656 
657  // Evaluate memoryless
658  return rev(get_ptr(arg), get_ptr(res), get_ptr(iw), get_ptr(w), 0);
659  }
int rev(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, int mem=0) const
Propagate sparsity backward.
Definition: function.cpp:1252

References casadi::get_ptr(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::rev(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), and casadi::Function::sz_w().

◆ reverse()

Function casadi::Function::reverse ( casadi_int  nadj) const
inherited
   Returns a function with <tt>n_in + n_out + n_out</tt> inputs
   and <tt>n_in</tt> outputs.
   The first <tt>n_in</tt> inputs correspond to nondifferentiated inputs.
   The next <tt>n_out</tt> inputs correspond to nondifferentiated outputs.
   and the last <tt>n_out</tt> inputs correspond to adjoint seeds,
   stacked horizontally
   The  <tt>n_in</tt> outputs correspond to adjoint sensitivities,
   stacked horizontally.     *
   <tt>(n_in = n_in(), n_out = n_out())</tt>

   <tt>(n_in = n_in(), n_out = n_out())</tt>

  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.

Extra doc: https://github.com/casadi/casadi/wiki/L_1wr

Definition at line 1332 of file function.cpp.

1332  {
1333  try {
1334  return (*this)->reverse(nadj);
1335  } catch(std::exception& e) {
1336  THROW_ERROR("reverse", e.what());
1337  }
1338  }

References casadi::FunctionInternal::reverse().

Referenced by casadi::SXFunction::ad_reverse(), casadi::DaeBuilderInternal::export_fmu(), casadi::Map::get_reverse(), casadi::MapSum::get_reverse(), casadi::Nlpsol::get_reverse(), casadi::Switch::get_reverse(), casadi::Integrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::FunctionInternal::reverse(), and casadi::RungeKutta::setup_step().

◆ save()

void casadi::Function::save ( const std::string &  fname,
const Dict opts = Dict() 
) const
inherited
See also
load

Extra doc: https://github.com/casadi/casadi/wiki/L_240

Definition at line 1466 of file function.cpp.

1466  {
1467  FileSerializer fs(fname, opts);
1468  fs.pack(*this);
1469  }

References casadi::SerializerBase::pack().

◆ serialize() [1/3]

std::string casadi::Function::serialize ( const Dict opts = Dict()) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x2

Definition at line 1471 of file function.cpp.

1471  {
1472  std::stringstream ss;
1473  serialize(ss, opts);
1474  return ss.str();
1475  }
void serialize(std::ostream &stream, const Dict &opts=Dict()) const
Serialize.
Definition: function.cpp:1477

References casadi::Function::serialize().

◆ serialize() [2/3]

void casadi::Function::serialize ( SerializingStream s) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x1

Definition at line 1482 of file function.cpp.

1482  {
1483  if (is_null()) {
1484  s.pack("Function::null", true);
1485  } else {
1486  s.pack("Function::null", false);
1487  (*this)->serialize(s);
1488  }
1489  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null(), and casadi::SerializingStream::pack().

◆ serialize() [3/3]

void casadi::Function::serialize ( std::ostream &  stream,
const Dict opts = Dict() 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1x0

Definition at line 1477 of file function.cpp.

1477  {
1478  SerializingStream s(stream, opts);
1479  serialize(s);
1480  }

Referenced by casadi::MX::cse(), and casadi::Function::serialize().

◆ set_temp()

void casadi::Function::set_temp ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
int  mem = 0 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xs

Definition at line 1306 of file function.cpp.

1307  {
1308  try {
1309  (*this)->set_temp(memory(mem), arg, res, iw, w);
1310  } catch(std::exception& e) {
1311  THROW_ERROR("set_temp", e.what());
1312  }
1313  }

References casadi::Function::memory().

◆ set_work()

void casadi::Function::set_work ( const double **&  arg,
double **&  res,
casadi_int *&  iw,
double *&  w,
int  mem = 0 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xr

Definition at line 1297 of file function.cpp.

1298  {
1299  try {
1300  (*this)->set_work(memory(mem), arg, res, iw, w);
1301  } catch(std::exception& e) {
1302  THROW_ERROR("set_work", e.what());
1303  }
1304  }

References casadi::Function::memory().

◆ setup()

void casadi::Function::setup ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
int  mem = 0 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1xt

Definition at line 1315 of file function.cpp.

1316  {
1317  try {
1318  (*this)->setup(memory(mem), arg, res, iw, w);
1319  } catch(std::exception& e) {
1320  THROW_ERROR("setup", e.what());
1321  }
1322  }

References casadi::Function::memory().

◆ size1_in() [1/2]

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

◆ size1_in() [2/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1va

Definition at line 271 of file function.hpp.

271 {return size1_in(index_in(iname));}

References casadi::Function::size1_in().

Referenced by casadi::Function::size1_in().

◆ size1_out() [1/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vb

Definition at line 987 of file function.cpp.

987  {
988  return (*this)->size1_out(ind);
989  }

Referenced by casadi::Function::assert_size_out(), casadi::construct_nlpsol(), casadi::Call::create(), casadi::Blocksqp::init(), and casadi::Onnx::load().

◆ size1_out() [2/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vb

Definition at line 285 of file function.hpp.

285 {return size1_out(index_out(oname));}

References casadi::Function::size1_out().

Referenced by casadi::Function::size1_out().

◆ size2_in() [1/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1va

Definition at line 983 of file function.cpp.

983  {
984  return (*this)->size2_in(ind);
985  }

Referenced by casadi::Function::assert_size_in(), casadi::FiniteDiff::get_sparsity_in(), casadi::Function::map(), and casadi::Function::mapaccum().

◆ size2_in() [2/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1va

Definition at line 273 of file function.hpp.

273 {return size2_in(index_in(iname));}

References casadi::Function::size2_in().

Referenced by casadi::Function::size2_in().

◆ size2_out() [1/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vb

Definition at line 991 of file function.cpp.

991  {
992  return (*this)->size2_out(ind);
993  }

Referenced by casadi::Function::assert_size_out(), casadi::Call::create(), casadi::Function::fold(), casadi::Onnx::load(), and casadi::Function::map().

◆ size2_out() [2/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vb

Definition at line 287 of file function.hpp.

287 {return size2_out(index_out(oname));}

References casadi::Function::size2_out().

Referenced by casadi::Function::size2_out().

◆ size_in() [1/2]

std::pair< casadi_int, casadi_int > casadi::Function::size_in ( casadi_int  ind) const
inherited

◆ size_in() [2/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1va

Definition at line 275 of file function.hpp.

275  {
276  return size_in(index_in(iname));
277  }
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get input dimension.
Definition: function.cpp:995

◆ size_out() [1/2]

std::pair< casadi_int, casadi_int > casadi::Function::size_out ( casadi_int  ind) const
inherited

◆ size_out() [2/2]

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vb

Definition at line 289 of file function.hpp.

289  {
290  return size_out(index_out(oname));
291  }
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Get output dimension.
Definition: function.cpp:999

◆ slice()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1wl

Definition at line 898 of file function.cpp.

900  {
901  try {
902  return (*this)->slice(name, order_in, order_out, opts);
903  } catch(std::exception& e) {
904  THROW_ERROR("slice", e.what());
905  }
906  }

References casadi::Function::name(), and casadi::FunctionInternal::slice().

Referenced by casadi::Function::mapaccum(), and casadi::FunctionInternal::slice().

◆ sparsity_in() [1/2]

const Sparsity & casadi::Function::sparsity_in ( casadi_int  ind) const
inherited

◆ sparsity_in() [2/2]

const Sparsity & casadi::Function::sparsity_in ( const std::string &  iname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vr

Definition at line 1175 of file function.cpp.

1175  {
1176  try {
1177  return sparsity_in(index_in(iname));
1178  } catch(std::exception& e) {
1179  THROW_ERROR("sparsity_in", e.what());
1180  }
1181  }

References casadi::Function::index_in(), and casadi::Function::sparsity_in().

◆ sparsity_jac() [1/4]

const Sparsity casadi::Function::sparsity_jac ( casadi_int  iind,
casadi_int  oind,
bool  compact = false,
bool  symmetric = false 
) const
inherited

[DEPRECATED] Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 1058 of file function.cpp.

1059  {
1060  try {
1061  return (*this)->jac_sparsity(oind, iind, compact, symmetric);
1062  } catch(std::exception& e) {
1063  THROW_ERROR("sparsity_jac", e.what());
1064  }
1065  }

Referenced by casadi::Blocksqp::init().

◆ sparsity_jac() [2/4]

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

[DEPRECATED] Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 544 of file function.hpp.

545  {
546  return sparsity_jac(iind, index_out(oind), compact, symmetric);
547  }
const Sparsity sparsity_jac(casadi_int iind, casadi_int oind, bool compact=false, bool symmetric=false) const
Definition: function.cpp:1059

◆ sparsity_jac() [3/4]

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

[DEPRECATED] Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 540 of file function.hpp.

541  {
542  return sparsity_jac(index_in(iind), oind, compact, symmetric);
543  }

◆ sparsity_jac() [4/4]

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

[DEPRECATED] Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 548 of file function.hpp.

549  {
550  return sparsity_jac(index_in(iind), index_out(oind), compact, symmetric);
551  }

◆ sparsity_out() [1/2]

const Sparsity & casadi::Function::sparsity_out ( casadi_int  ind) const
inherited

◆ sparsity_out() [2/2]

const Sparsity & casadi::Function::sparsity_out ( const std::string &  iname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vs

Definition at line 1191 of file function.cpp.

1191  {
1192  try {
1193  return sparsity_out(index_out(iname));
1194  } catch(std::exception& e) {
1195  THROW_ERROR("sparsity_out", e.what());
1196  }
1197  }

References casadi::Function::index_out(), and casadi::Function::sparsity_out().

◆ stats()

Dict casadi::Function::stats ( int  mem = 0) const
inherited

Definition at line 1080 of file function.cpp.

1080  {
1081  if (!(*this)->has_memory(mem)) {
1082  THROW_ERROR("stats",
1083  "No stats available: Function/solver was not yet numerically evaluated.");
1084  }
1085  try {
1086  return (*this)->get_stats(memory(mem));
1087  } catch(std::exception& e) {
1088  THROW_ERROR("stats", e.what());
1089  }
1090  }

References casadi::Function::memory().

Referenced by casadi::DaeBuilder::get(), casadi::MXFunction::get_stats(), casadi::ImplicitToNlp::get_stats(), casadi::FunctionBuffer::stats(), and casadi::OptiNode::stats().

◆ swap()

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ sx_in() [1/3]

const std::vector< SX > casadi::Function::sx_in ( ) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

Definition at line 1765 of file function.cpp.

1765  {
1766  try {
1767  return (*this)->sx_in();
1768  } catch(std::exception& e) {
1769  THROW_ERROR("sx_in", e.what());
1770  }
1771  }

Referenced by casadi::Function::expand(), and casadi::Function::sym_in().

◆ sx_in() [2/3]

const SX casadi::Function::sx_in ( casadi_int  iind) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

Definition at line 1749 of file function.cpp.

1749  {
1750  try {
1751  return (*this)->sx_in(iind);
1752  } catch(std::exception& e) {
1753  THROW_ERROR("sx_in", e.what());
1754  }
1755  }

Referenced by casadi::Matrix< Scalar >::get_input(), casadi::AmplInterface::init(), casadi::qpsol_nlp(), and casadi::Function::transform().

◆ sx_in() [3/3]

const SX casadi::Function::sx_in ( const std::string &  iname) const
inlineinherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

Definition at line 1010 of file function.hpp.

1010  {
1011  return sx_in(index_in(iname));
1012  }

◆ sx_out() [1/3]

const std::vector< SX > casadi::Function::sx_out ( ) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x5

Definition at line 1773 of file function.cpp.

1773  {
1774  try {
1775  return (*this)->sx_out();
1776  } catch(std::exception& e) {
1777  THROW_ERROR("sx_out", e.what());
1778  }
1779  }

◆ sx_out() [2/3]

const SX casadi::Function::sx_out ( casadi_int  oind) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x5

Definition at line 1757 of file function.cpp.

1757  {
1758  try {
1759  return (*this)->sx_out(oind);
1760  } catch(std::exception& e) {
1761  THROW_ERROR("sx_out", e.what());
1762  }
1763  }

◆ sx_out() [3/3]

const SX casadi::Function::sx_out ( const std::string &  oname) const
inlineinherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x5

Definition at line 1038 of file function.hpp.

1038  {
1039  return sx_out(index_out(oname));
1040  }
const std::vector< SX > sx_out() const
Get symbolic primitives equivalent to the output expressions.
Definition: function.cpp:1773

◆ sym_in() [1/5]

template<>
const std::vector< MX > CASADI_EXPORT casadi::Function::sym_in ( ) const
inherited

Definition at line 2246 of file function.cpp.

2246  {
2247  return sx_in();
2248  }

References casadi::Function::sx_in().

◆ sym_in() [2/5]

template<typename T >
const std::vector<T> casadi::Function::sym_in ( ) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

◆ sym_in() [3/5]

template<>
const MX CASADI_EXPORT casadi::Function::sym_in ( casadi_int  iind) const
inherited

Definition at line 2237 of file function.cpp.

2237  {
2238  return sx_in(iind);
2239  }

References casadi::Function::sx_in().

◆ sym_in() [4/5]

template<typename T >
const T casadi::Function::sym_in ( casadi_int  iind) const
inherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

References casadi::T.

Referenced by casadi::construct_nlpsol().

◆ sym_in() [5/5]

template<typename T >
const T casadi::Function::sym_in ( const std::string &  iname) const
inlineinherited

There is no guarantee that subsequent calls return unique answers

Extra doc: https://github.com/casadi/casadi/wiki/L_1x4

Definition at line 1023 of file function.hpp.

1023  {
1024  return sym_in<T>(index_in(iname));
1025  }

References casadi::T.

◆ sz_arg()

size_t casadi::Function::sz_arg ( ) const
inherited

◆ sz_iw()

size_t casadi::Function::sz_iw ( ) const
inherited

◆ sz_res()

size_t casadi::Function::sz_res ( ) const
inherited

◆ sz_w()

size_t casadi::Function::sz_w ( ) const
inherited

◆ sz_work()

void casadi::Function::sz_work ( size_t &  sz_arg,
size_t &  sz_res,
size_t &  sz_iw,
size_t &  sz_w 
) const
inherited

◆ test_cast()

bool casadi::Function::test_cast ( const SharedObjectInternal ptr)
staticinherited

Definition at line 1076 of file function.cpp.

1076  {
1077  return dynamic_cast<const FunctionInternal*>(ptr)!=nullptr;
1078  }

◆ transform() [1/4]

Function casadi::Function::transform ( const Dict opts = Dict()) const
inherited

Options:

  • passes (OT_VECTORVECTOR): an ordered list of passes. Each pass is a list whose first entry is the verb:
    • {"simplify", task, ...}: graph simplification passes applied in order (cse, ref_count, const_folding, combine_terms, empty_inputs). An integer before a task sets its run count (N>0: N times, 0: until a fixed point); the default is 1.
    • {"expand"}: expand to an SXFunction
    • {"external", library, operation, opts}: apply an externally defined transform (opts is an optional dict)
  • boolean shorthands (used only when "passes" is absent): empty_inputs, combine_terms, cse, ref_count, const_folding. These build a single "simplify" pass.

The dict-only form applies a default simplification flow when empty. The (passes, opts) form runs an explicit pipeline; its opts accepts only "verbose" (the boolean simplify options are rejected there).

Extra doc: https://github.com/casadi/casadi/wiki/L_2ig

Definition at line 359 of file function.cpp.

359  {
360  return transform(name(), opts);
361  }
Function transform(const Dict &opts=Dict()) const
Apply transformation passes.
Definition: function.cpp:359

References casadi::Function::name().

Referenced by casadi::Function::transform(), and casadi::MX::transform().

◆ transform() [2/4]

Function casadi::Function::transform ( const std::string &  fname,
const Dict opts = Dict() 
) const
inherited

Options:

  • passes (OT_VECTORVECTOR): an ordered list of passes. Each pass is a list whose first entry is the verb:
    • {"simplify", task, ...}: graph simplification passes applied in order (cse, ref_count, const_folding, combine_terms, empty_inputs). An integer before a task sets its run count (N>0: N times, 0: until a fixed point); the default is 1.
    • {"expand"}: expand to an SXFunction
    • {"external", library, operation, opts}: apply an externally defined transform (opts is an optional dict)
  • boolean shorthands (used only when "passes" is absent): empty_inputs, combine_terms, cse, ref_count, const_folding. These build a single "simplify" pass.

The dict-only form applies a default simplification flow when empty. The (passes, opts) form runs an explicit pipeline; its opts accepts only "verbose" (the boolean simplify options are rejected there).

Extra doc: https://github.com/casadi/casadi/wiki/L_2ig

Definition at line 363 of file function.cpp.

363  {
364  try {
365  // Boolean shorthands (defaults reproduce the meaningful default flow)
366  bool empty_inputs = true;
367  bool combine_terms = false;
368  bool cse = true;
369  bool ref_count = true;
370  bool const_folding = true;
371  bool verbose = false;
372  for (auto&& op : opts) {
373  if (op.first=="empty_inputs") {
374  empty_inputs = op.second;
375  } else if (op.first=="combine_terms") {
376  combine_terms = op.second;
377  } else if (op.first=="cse") {
378  cse = op.second;
379  } else if (op.first=="ref_count") {
380  ref_count = op.second;
381  } else if (op.first=="const_folding") {
382  const_folding = op.second;
383  } else if (op.first=="verbose") {
384  verbose = op.second;
385  } else {
386  casadi_error("transform: no such option: " + std::string(op.first) + ".\n");
387  }
388  }
389  std::vector<GenericType> simp = {std::string("simplify")};
390  if (empty_inputs) simp.push_back("empty_inputs");
391  if (combine_terms) simp.push_back("combine_terms");
392  if (cse) simp.push_back("cse");
393  if (ref_count) { simp.push_back(0); simp.push_back("ref_count"); } // 0 = fixed point
394  if (const_folding) simp.push_back("const_folding");
395  return transform(fname, std::vector<std::vector<GenericType> >{simp}, {{"verbose", verbose}});
396  } catch(std::exception& e) {
397  THROW_ERROR("transform", e.what());
398  }
399  }

References casadi::Function::transform().

◆ transform() [3/4]

Function casadi::Function::transform ( const std::string &  fname,
const std::vector< std::vector< GenericType > > &  passes,
const Dict opts = Dict() 
) const
inherited

Options:

  • passes (OT_VECTORVECTOR): an ordered list of passes. Each pass is a list whose first entry is the verb:
    • {"simplify", task, ...}: graph simplification passes applied in order (cse, ref_count, const_folding, combine_terms, empty_inputs). An integer before a task sets its run count (N>0: N times, 0: until a fixed point); the default is 1.
    • {"expand"}: expand to an SXFunction
    • {"external", library, operation, opts}: apply an externally defined transform (opts is an optional dict)
  • boolean shorthands (used only when "passes" is absent): empty_inputs, combine_terms, cse, ref_count, const_folding. These build a single "simplify" pass.

The dict-only form applies a default simplification flow when empty. The (passes, opts) form runs an explicit pipeline; its opts accepts only "verbose" (the boolean simplify options are rejected there).

Extra doc: https://github.com/casadi/casadi/wiki/L_2ig

Definition at line 406 of file function.cpp.

408  {
409  try {
410  // Only 'verbose' is accepted here; boolean simplify options belong to the
411  // dict-only overload
412  bool verbose = false;
413  for (auto&& op : opts) {
414  if (op.first=="verbose") {
415  verbose = op.second;
416  } else {
417  casadi_error("transform(passes, opts): unsupported option '" + std::string(op.first)
418  + "' (boolean simplify options are only allowed in the dict-only form).\n");
419  }
420  }
421 
422  if (verbose) {
423  uout() << "transform(" << transform_passes_str(passes) << ")" << std::endl;
424  uout() << " start: " << transform_stats(*this) << std::endl;
425  }
426 
427  // Run the pipeline
428  Function f = *this;
429  for (const auto& pass : passes) {
430  casadi_assert(!pass.empty(), "transform: each pass must be a non-empty list");
431  std::string verb = pass.front().to_string();
432  if (verb=="simplify") {
433  // Tasks are strings; an optional integer before a task sets its run
434  // count (N>0: run N times, 0: run until a fixed point). Default: 1.
435  std::vector<std::pair<std::string, casadi_int> > tasks;
436  casadi_int count = 1;
437  bool have_count = false;
438  for (size_t i=1; i<pass.size(); ++i) {
439  if (pass[i].is_int()) {
440  count = pass[i].to_int();
441  have_count = true;
442  } else {
443  tasks.push_back({pass[i].to_string(), count});
444  count = 1;
445  have_count = false;
446  }
447  }
448  casadi_assert(!have_count,
449  "transform 'simplify': trailing run count with no following task");
450  f = f->simplify_passes(tasks);
451  } else if (verb=="expand") {
452  casadi_assert(pass.size()==1, "transform: 'expand' pass takes no arguments");
453  f = f.expand();
454  } else if (verb=="external") {
455  casadi_assert(pass.size()>=3 && pass.size()<=4,
456  "transform: 'external' pass must be {\"external\", library, operation[, opts]}");
457  std::string lib = pass[1].to_string();
458  std::string op = pass[2].to_string();
459  Dict eopts = pass.size()==4 ? pass[3].to_dict() : Dict();
460  f = external_transform(lib, op, f, eopts);
461  } else {
462  casadi_error("transform: unknown pass verb '" + verb + "'");
463  }
464  if (verbose) {
465  uout() << " after " << transform_passes_str({pass}) << ": "
466  << transform_stats(f) << std::endl;
467  }
468  }
469 
470  // Optionally rename the result (type-preserving for SX/MX functions)
471  if (!fname.empty() && fname!=f.name()) {
472  Dict ropts{{"allow_free", true}, {"allow_duplicate_io_names", true}};
473  std::vector<std::string> ni = f.name_in(), no = f.name_out();
474  if (f.is_a("SXFunction", true)) {
475  std::vector<SX> arg = f.sx_in();
476  f = Function(fname, arg, f(arg), ni, no, ropts);
477  } else {
478  std::vector<MX> arg = f.mx_in();
479  f = Function(fname, arg, f(arg), ni, no, ropts);
480  }
481  }
482  return f;
483  } catch(std::exception& e) {
484  THROW_ERROR("transform", e.what());
485  }
486  }
std::string transform_stats(const Function &f)
Definition: function.cpp:352
std::string transform_passes_str(const std::vector< std::vector< GenericType > > &ps)
Definition: function.cpp:338
std::ostream & uout()

References casadi::Function::expand(), casadi::external_transform(), casadi::Function::Function(), casadi::Function::is_a(), casadi::Function::mx_in(), casadi::Function::name(), casadi::Function::name_in(), casadi::Function::name_out(), casadi::FunctionInternal::simplify_passes(), casadi::Function::sx_in(), casadi::transform_passes_str(), casadi::transform_stats(), and casadi::uout().

◆ transform() [4/4]

Function casadi::Function::transform ( const std::vector< std::vector< GenericType > > &  passes,
const Dict opts = Dict() 
) const
inherited

Options:

  • passes (OT_VECTORVECTOR): an ordered list of passes. Each pass is a list whose first entry is the verb:
    • {"simplify", task, ...}: graph simplification passes applied in order (cse, ref_count, const_folding, combine_terms, empty_inputs). An integer before a task sets its run count (N>0: N times, 0: until a fixed point); the default is 1.
    • {"expand"}: expand to an SXFunction
    • {"external", library, operation, opts}: apply an externally defined transform (opts is an optional dict)
  • boolean shorthands (used only when "passes" is absent): empty_inputs, combine_terms, cse, ref_count, const_folding. These build a single "simplify" pass.

The dict-only form applies a default simplification flow when empty. The (passes, opts) form runs an explicit pipeline; its opts accepts only "verbose" (the boolean simplify options are rejected there).

Extra doc: https://github.com/casadi/casadi/wiki/L_2ig

Definition at line 401 of file function.cpp.

402  {
403  return transform(name(), passes, opts);
404  }

References casadi::Function::name(), and casadi::Function::transform().

◆ type_name()

static std::string casadi::Callback::type_name ( )
inlinestatic

Extra doc: https://github.com/casadi/casadi/wiki/L_o1

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

54 {return "Callback";}

◆ uses_output()

bool casadi::Callback::uses_output ( ) const
virtual

Extra doc: https://github.com/casadi/casadi/wiki/L_og

Definition at line 88 of file callback.cpp.

88  {
89  return (*this)->FunctionInternal::uses_output();
90  }

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_aw

Definition at line 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

◆ which_depends()

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

Extra doc: https://github.com/casadi/casadi/wiki/L_1vx

Definition at line 2022 of file function.cpp.

2024  {
2025  try {
2026  return (*this)->which_depends(s_in, s_out, order, tr);
2027  } catch(std::exception& e) {
2028  THROW_ERROR("which_depends", e.what());
2029  }
2030  }
static std::vector< SX > order(const std::vector< SX > &expr)
Definition: function.cpp:2142

References casadi::Function::order().

Referenced by casadi::BonminInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), and casadi::FunctionInternal::which_depends().

◆ wrap() [1/2]

Function casadi::Function::wrap ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vv

Definition at line 2112 of file function.cpp.

2112  {
2113  return (*this)->wrap();
2114  }

References casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::which_depends().

◆ wrap() [2/2]

Function casadi::Function::wrap ( const std::string &  name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vv

Definition at line 2116 of file function.cpp.

2116  {
2117  return (*this)->wrap(name);
2118  }

References casadi::Function::name(), and casadi::FunctionInternal::wrap().

◆ wrap_as_needed() [1/2]

Function casadi::Function::wrap_as_needed ( const Dict opts) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vw

Definition at line 2120 of file function.cpp.

2120  {
2121  return (*this)->wrap_as_needed(opts);
2122  }

References casadi::FunctionInternal::wrap_as_needed().

Referenced by casadi::MapSum::create().

◆ wrap_as_needed() [2/2]

Function casadi::Function::wrap_as_needed ( const std::string &  name,
const Dict opts 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1vw

Definition at line 2124 of file function.cpp.

2124  {
2125  return (*this)->wrap_as_needed(name, opts);
2126  }

References casadi::Function::name(), and casadi::FunctionInternal::wrap_as_needed().


The documentation for this class was generated from the following files: