List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions
casadi::FmuFunction Class Reference

#include <fmu_function.hpp>

Detailed Description


List of available options
IdTypeDescriptionUsed in
abstolOT_DOUBLEAbsolute error tolerance, scaled by nominal valuecasadi::FmuFunction
ad_weightOT_DOUBLEWeighting factor for derivative calculation.When there is an option of either using forward or reverse mode directional derivatives, the condition ad_weight*nf<=(1-ad_weight)*na is used where nf and na are estimates of the number of forward/reverse mode directional derivatives needed. By default, ad_weight is calculated automatically, but this can be overridden by setting this option. In particular, 0 means forcing forward mode and 1 forcing reverse mode. Leave unset for (class specific) heuristics.casadi::FunctionInternal
ad_weight_spOT_DOUBLEWeighting factor for sparsity pattern calculation calculation.Overrides default behavior. Set to 0 and 1 to force forward and reverse mode respectively. Cf. option "ad_weight". When set to -1, sparsity is completely ignored and dense matrices are used.casadi::FunctionInternal
always_inlineOT_BOOLForce inlining.casadi::FunctionInternal
asymmetric_hessian_coloringOT_BOOLCalculate Hessian using unidirectional graph coloring (star coloring). Ensures that upper and lower triangular parts are calculated separately, which may be desirable for diagnostics. If both symmetric coloring ('hessian_coloring' option) and asymmetric coloring is enabled, the symmetric coloring will be used.casadi::FmuFunction
auxOT_STRINGVECTORAuxilliary variablescasadi::FmuFunction
cacheOT_DICTPrepopulate the function cache. Default: emptycasadi::FunctionInternal
check_hessianOT_BOOL[DEPRECATED] Renamed 'validate_hessian'casadi::FmuFunction
compilerOT_STRINGJust-in-time compiler plugin to be used.casadi::FunctionInternal
custom_jacobianOT_FUNCTIONOverride CasADi's AD. Use together with 'jac_penalty': 0. Note: Highly experimental. Syntax may break often.casadi::FunctionInternal
der_optionsOT_DICTDefault options to be used to populate forward_options, reverse_options, and jacobian_options before those options are merged in.casadi::FunctionInternal
derivative_ofOT_FUNCTIONThe function is a derivative of another function. The type of derivative (directional derivative, Jacobian) is inferred from the function name.casadi::FunctionInternal
dumpOT_BOOLDump function to file upon first evaluation. [false]casadi::FunctionInternal
dump_dirOT_STRINGDirectory to dump inputs/outputs and traces to. Make sure the directory exists [.]casadi::FunctionInternal
dump_formatOT_STRINGChoose file format to dump matrices. See DM.from_file [mtx]casadi::FunctionInternal
dump_inOT_BOOLDump numerical values of inputs to file (readable with DM.from_file) [default: false] A counter is used to generate unique names. The counter may be reset using reset_dump_count.casadi::FunctionInternal
dump_outOT_BOOLDump numerical values of outputs to file (readable with DM.from_file) [default: false] A counter is used to generate unique names. The counter may be reset using reset_dump_count.casadi::FunctionInternal
enable_adOT_BOOL[DEPRECATED] Renamed uses_directional_derivativescasadi::FmuFunction
enable_adjoint_hessianOT_BOOLUse finite differencing of adjoints for Hessian calculation.casadi::FmuFunction
enable_adjoint_jacobianOT_BOOLAllow Jacobian calculation using adjoint mode AD.casadi::FmuFunction
enable_fdOT_BOOLEnable derivative calculation by finite differencing. [default: false]]casadi::FunctionInternal
enable_forwardOT_BOOLEnable derivative calculation using generated functions for Jacobian-times-vector products - typically using forward mode AD - if available. [default: true]casadi::FunctionInternal
enable_forward_jacobianOT_BOOLAllow Jacobian calculation using forward mode AD.casadi::FmuFunction
enable_jacobianOT_BOOLEnable derivative calculation using generated functions for Jacobians of all differentiable outputs with respect to all differentiable inputs - if available. [default: true]casadi::FunctionInternal
enable_reverseOT_BOOLEnable derivative calculation using generated functions for transposed Jacobian-times-vector products - typically using reverse mode AD - if available. [default: true]casadi::FunctionInternal
error_on_failOT_BOOLThrow exceptions when function evaluation fails (default true).casadi::ProtoFunction
external_transformOT_VECTORVECTORList of external_transform instruction arguments. Default: emptycasadi::FunctionInternal
fd_flipOT_BOOLAllow flipping the sign of the finite difference step to keep it in boundscasadi::FmuFunction
fd_methodOT_STRINGMethod for finite differencing [default 'central']casadi::FunctionInternal
fd_optionsOT_DICTOptions to be passed to the finite difference instancecasadi::FunctionInternal
forward_optionsOT_DICTOptions to be passed to a forward mode constructorcasadi::FunctionInternal
gather_statsOT_BOOLDeprecated option (ignored): Statistics are now always collected.casadi::FunctionInternal
hessian_coloringOT_BOOLCalculate Hessian using symmetry exploiting graph coloring (star coloring).casadi::FmuFunction
inputs_checkOT_BOOLThrow exceptions when the numerical values of the inputs don't make sensecasadi::FunctionInternal
is_diff_inOT_BOOLVECTORIndicate for each input if it should be differentiable.casadi::FunctionInternal
is_diff_outOT_BOOLVECTORIndicate for each output if it should be differentiable.casadi::FunctionInternal
jac_penaltyOT_DOUBLEWhen requested for a number of forward/reverse directions, it may be cheaper to compute first the full jacobian and then multiply with seeds, rather than obtain the requested directions in a straightforward manner. Casadi uses a heuristic to decide which is cheaper. A high value of 'jac_penalty' makes it less likely for the heurstic to chose the full Jacobian strategy. The special value -1 indicates never to use the full Jacobian strategycasadi::FunctionInternal
jacobian_optionsOT_DICTOptions to be passed to a Jacobian constructorcasadi::FunctionInternal
jitOT_BOOLUse just-in-time compiler to speed up the evaluationcasadi::FunctionInternal
jit_cleanupOT_BOOLCleanup up the temporary source file that jit creates. Default: truecasadi::FunctionInternal
jit_nameOT_STRINGThe file name used to write out code. The actual file names used depend on 'jit_temp_suffix' and include extensions. Default: 'jit_tmp'casadi::FunctionInternal
jit_optionsOT_DICTOptions to be passed to the jit compiler.casadi::FunctionInternal
jit_serializeOT_STRINGSpecify behaviour when serializing a jitted function: SOURCE|link|embed.casadi::FunctionInternal
jit_temp_suffixOT_BOOLUse a temporary (seemingly random) filename suffix for generated code and libraries. This is desired for thread-safety. This behaviour may defeat caching compiler wrappers. Default: truecasadi::FunctionInternal
make_symmetricOT_BOOLEnsure Hessian is symmetriccasadi::FmuFunction
max_ioOT_INTAcceptable number of inputs and outputs. Warn if exceeded.casadi::FunctionInternal
max_num_dirOT_INTSpecify the maximum number of directions for derivative functions. Overrules the builtin optimized_num_dir.casadi::FunctionInternal
nadjOT_INTNumber of adjoint sensitivities to be calculated [1]casadi::FmuFunction
never_inlineOT_BOOLForbid inlining.casadi::FunctionInternal
new_forwardOT_BOOLUse forward AD implementation in class (conversion option, to be removed)casadi::FmuFunction
new_hessianOT_BOOLUse Hessian implementation in class (conversion option, to be removed)casadi::FmuFunction
new_jacobianOT_BOOLUse Jacobian implementation in class (conversion option, to be removed)casadi::FmuFunction
nfwdOT_INTNumber of forward sensitivities to be calculated [1]casadi::FmuFunction
parallelizationOT_STRINGParallelization [SERIAL|openmp|thread]casadi::FmuFunction
post_expandOT_BOOLAfter construction, expand this Function. Default: Falsecasadi::FunctionInternal
post_expand_optionsOT_DICTOptions to be passed to post-construction expansion. Default: emptycasadi::FunctionInternal
print_canonicalOT_BOOLWhen printing numerical matrices, use a format that is exact and reproducible in generated C code.casadi::FunctionInternal
print_inOT_BOOLPrint numerical values of inputs [default: false]casadi::FunctionInternal
print_outOT_BOOLPrint numerical values of outputs [default: false]casadi::FunctionInternal
print_progressOT_BOOLPrint progress during Jacobian/Hessian evaluationcasadi::FmuFunction
print_timeOT_BOOLprint information about execution time. Implies record_time.casadi::ProtoFunction
record_timeOT_BOOLrecord information about execution time, for retrieval with stats().casadi::ProtoFunction
regularity_checkOT_BOOLThrow exceptions when NaN or Inf appears during evaluationcasadi::ProtoFunction
reltolOT_DOUBLERelative error tolerancecasadi::FmuFunction
reverse_optionsOT_DICTOptions to be passed to a reverse mode constructorcasadi::FunctionInternal
schemeOT_DICTDefinitions of the scheme variablescasadi::FmuFunction
scheme_inOT_STRINGVECTORNames of the inputs in the schemecasadi::FmuFunction
scheme_outOT_STRINGVECTORNames of the outputs in the schemecasadi::FmuFunction
stepOT_DOUBLEStep size, scaled by nominal valuecasadi::FmuFunction
user_dataOT_VOIDPTRA user-defined field that can be used to identify the function or pass additional informationcasadi::FunctionInternal
uses_adjoint_derivativesOT_BOOLUse the analytic adjoint derivative support in the FMUcasadi::FmuFunction
uses_directional_derivativesOT_BOOLUse the analytic forward directional derivative support in the FMUcasadi::FmuFunction
validate_adOT_BOOL[DEPRECATED] Renamed 'validate_forward'casadi::FmuFunction
validate_ad_fileOT_STRINGRedirect results of Hessian validation to a file instead of generating a warningcasadi::FmuFunction
validate_forwardOT_BOOLCompare forward derivatives with finite differences for validationcasadi::FmuFunction
validate_hessianOT_BOOLValidate entries of the Hessian for self-consistencycasadi::FmuFunction
verboseOT_BOOLVerbose evaluation – for debuggingcasadi::ProtoFunction

Definition at line 135 of file fmu_function.hpp.

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

Public Types

using weak_ref_type = WeakRefInternal
 

Public Member Functions

 FmuFunction (const std::string &name, const Fmu &fmu, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out)
 Constructor. More...
 
 ~FmuFunction () override
 Destructor. More...
 
std::string class_name () const override
 Get type name. More...
 
void init (const Dict &opts) override
 Initialize. More...
 
int eval (const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
 Evaluate numerically. More...
 
int eval_all (FmuMemory *m, casadi_int n_task, bool need_nondiff, bool need_jac, bool need_fwd, bool need_adj, bool need_hess) const
 
int eval_task (FmuMemory *m, casadi_int task, casadi_int n_task, bool need_nondiff, bool need_jac, bool need_fwd, bool need_adj, bool need_hess) const
 
void finalize_hessian (FmuMemory *m, double *hess_nz, casadi_int *iw) const
 
bool all_regular () const
 
bool all_vectors () const
 
Function 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 override
 
void check_mem_count (casadi_int n) const override
 Check for validatity of memory object count. More...
 
void * alloc_mem () const override
 Create memory block. More...
 
int init_mem (void *mem) const override
 Initalize memory block. More...
 
void free_mem (void *mem) const override
 Free memory block. More...
 
Dict get_stats (void *mem) const override
 Get all statistics. More...
 
void serialize_body (SerializingStream &s) const override
 Serialize an object without type information. More...
 
void change_option (const std::string &option_name, const GenericType &option_value) override
 Change option after object creation for debugging. More...
 
virtual std::string getAdaptorSolverName () const
 Obtain solver name from Adaptor. More...
 
Dict generate_options (const std::string &target) const override
 Reconstruct options dict. More...
 
void reset_dump_count ()
 Reset the counter used to name dump files. More...
 
void finalize () override
 Finalize the object creation. More...
 
Function self () const
 Get a public class instance. More...
 
virtual std::vector< std::string > get_function () const
 
virtual const Function & get_function (const std::string &name) const
 
virtual bool has_function (const std::string &fname) const
 
void add_embedded (std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, const Function &dep, casadi_int max_depth) const
 
virtual void find (std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, casadi_int max_depth) const
 
virtual std::vector< bool > which_depends (const std::string &s_in, const std::vector< std::string > &s_out, casadi_int order, bool tr=false) const
 Which variables enter with some order. More...
 
virtual Function simplify_passes (const std::vector< std::pair< std::string, casadi_int > > &tasks) const
 Apply an ordered list of simplify passes (used by transform) More...
 
virtual int eval_sx (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate with symbolic scalars. More...
 
virtual void eval_mx (const MXVector &arg, MXVector &res, bool always_inline, bool never_inline) const
 Evaluate with symbolic matrices. More...
 
template<typename M >
void call (const std::vector< M > &arg, std::vector< M > &res, bool always_inline, bool never_inline) const
 Call a function, templated. More...
 
template<typename M >
bool matching_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments that needs to be replaced. More...
 
template<typename M >
bool matching_res (const std::vector< M > &arg, casadi_int &npar) const
 Check if output arguments that needs to be replaced. More...
 
template<typename M >
std::vector< M > replace_arg (const std::vector< M > &arg, casadi_int npar) const
 Replace 0-by-0 inputs. More...
 
template<typename M >
std::vector< M > project_arg (const std::vector< M > &arg, casadi_int npar) const
 Project sparsities. More...
 
template<typename M >
std::vector< M > project_res (const std::vector< M > &arg, casadi_int npar) const
 Project sparsities. More...
 
template<typename M >
std::vector< M > replace_res (const std::vector< M > &res, casadi_int npar) const
 Replace 0-by-0 outputs. More...
 
template<typename M >
std::vector< std::vector< M > > replace_fseed (const std::vector< std::vector< M >> &fseed, casadi_int npar) const
 Replace 0-by-0 forward seeds. More...
 
template<typename M >
std::vector< std::vector< M > > replace_fseed (const std::vector< std::vector< M > > &fseed, casadi_int npar) const
 
template<typename M >
std::vector< std::vector< M > > replace_aseed (const std::vector< std::vector< M >> &aseed, casadi_int npar) const
 Replace 0-by-0 reverse seeds. More...
 
template<typename M >
std::vector< std::vector< M > > replace_aseed (const std::vector< std::vector< M > > &aseed, casadi_int npar) const
 
std::vector< MX > mapsum_mx (const std::vector< MX > &arg, const std::string &parallelization)
 Parallel evaluation. More...
 
virtual bool uses_output () const
 Do the derivative functions need nondifferentiated outputs? More...
 
std::string diff_prefix (const std::string &prefix) const
 Determine prefix for differentiated functions. More...
 
virtual Function slice (const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts) const
 returns a new function with a selection of inputs/outputs of the original More...
 
virtual const Function & oracle () const
 Get oracle. More...
 
bool has_derivative () const
 Can derivatives be calculated in any way? More...
 
virtual double ad_weight () const
 Weighting factor for chosing forward/reverse mode. More...
 
virtual double sp_weight () const
 Weighting factor for chosing forward/reverse mode,. More...
 
virtual std::vector< MX > free_mx () const
 Get free variables (MX) More...
 
virtual std::vector< SX > free_sx () const
 Get free variables (SX) More...
 
virtual bool has_free () const
 Does the function have free variables. More...
 
virtual void generate_lifted (Function &vdef_fcn, Function &vinit_fcn) const
 Extract the functions needed for the Lifted Newton method. More...
 
virtual casadi_int n_instructions () const
 Get the number of atomic operations. More...
 
virtual casadi_int instruction_id (casadi_int k) const
 Get an atomic operation operator index. More...
 
virtual std::vector< casadi_int > instruction_input (casadi_int k) const
 Get the (integer) input arguments of an atomic operation. More...
 
virtual double instruction_constant (casadi_int k) const
 Get the floating point output argument of an atomic operation. More...
 
virtual std::vector< casadi_int > instruction_output (casadi_int k) const
 Get the (integer) output argument of an atomic operation. More...
 
virtual casadi_int n_nodes () const
 Number of nodes in the algorithm. More...
 
virtual MX instruction_MX (casadi_int k) const
 get MX expression associated with instruction More...
 
virtual SX instructions_sx () const
 get SX expression associated with instructions More...
 
Dict cache () const
 Get all functions in the cache. More...
 
bool incache (const std::string &fname, Function &f, const std::string &suffix="") const
 Get function in cache. More...
 
void tocache (const Function &f, const std::string &suffix="") const
 Save function to cache. More...
 
void tocache_if_missing (Function &f, const std::string &suffix="") const
 Save function to cache, only if missing. More...
 
void codegen (CodeGenerator &g, const std::string &fname) const
 Generate code the function. More...
 
void codegen_meta (CodeGenerator &g) const
 Generate meta-information allowing a user to evaluate a generated function. More...
 
void codegen_sparsities (CodeGenerator &g) const
 Codegen sparsities. More...
 
virtual std::string codegen_name (const CodeGenerator &g, bool ns=true) const
 Get name in codegen. More...
 
std::string codegen_mem (CodeGenerator &g, const std::string &index="mem") const
 Get thread-local memory object. More...
 
virtual void codegen_incref (CodeGenerator &g) const
 Codegen incref for dependencies. More...
 
virtual void codegen_decref (CodeGenerator &g) const
 Codegen decref for dependencies. More...
 
virtual void codegen_alloc_mem (CodeGenerator &g) const
 Codegen decref for alloc_mem. More...
 
virtual void codegen_init_mem (CodeGenerator &g) const
 Codegen decref for init_mem. More...
 
virtual void codegen_free_mem (CodeGenerator &g) const
 Codegen for free_mem. More...
 
virtual void codegen_checkout (CodeGenerator &g) const
 Codegen for checkout. More...
 
virtual void codegen_release (CodeGenerator &g) const
 Codegen for release. More...
 
std::string signature (const std::string &fname) const
 Code generate the function. More...
 
std::string signature_unrolled (const std::string &fname) const
 Code generate the function. More...
 
virtual void codegen_declarations (CodeGenerator &g) const
 Generate code for the declarations of the C function. More...
 
virtual void codegen_body (CodeGenerator &g) const
 Generate code for the function body. More...
 
virtual std::string codegen_mem_type () const
 Thread-local memory object type. More...
 
virtual bool codegen_needs_mem () const
 Is thread-local memory object needed? More...
 
virtual bool codegen_mem_is_opaque () const
 Is thread-local memory object managed by checkout/release. More...
 
virtual std::string generate_dependencies (const std::string &fname, const Dict &opts) const
 Export / Generate C code for the dependency function. More...
 
virtual bool has_codegen () const
 Is codegen supported? More...
 
virtual void jit_dependencies (const std::string &fname)
 Jit dependencies. More...
 
virtual void export_code (const std::string &lang, std::ostream &stream, const Dict &options) const
 Export function in a specific language. More...
 
void serialize_type (SerializingStream &s) const override
 Serialize type information. More...
 
void disp (std::ostream &stream, bool more) const override
 Display object. More...
 
virtual void disp_more (std::ostream &stream) const
 Print more. More...
 
std::string definition () const
 Get function signature: name:(inputs)->(outputs) More...
 
void print_dimensions (std::ostream &stream) const
 Print dimensions of inputs and outputs. More...
 
virtual std::vector< std::string > get_free () const
 Print free variables. More...
 
void get_partition (casadi_int iind, casadi_int oind, Sparsity &D1, Sparsity &D2, bool compact, bool symmetric, bool allow_forward, bool allow_reverse) const
 Get the unidirectional or bidirectional partition. More...
 
virtual double get_default_in (casadi_int ind) const
 Get default input value. More...
 
virtual double get_max_in (casadi_int ind) const
 Get largest input value. More...
 
virtual double get_min_in (casadi_int ind) const
 Get smallest input value. More...
 
virtual double get_reltol () const
 Get relative tolerance. More...
 
virtual double get_abstol () const
 Get absolute tolerance. More...
 
virtual bool get_diff_in (casadi_int i)
 Which inputs are differentiable. More...
 
virtual bool get_diff_out (casadi_int i)
 Which outputs are differentiable. More...
 
casadi_int index_in (const std::string &name) const
 Get input scheme index by name. More...
 
casadi_int index_out (const std::string &name) const
 Get output scheme index by name. More...
 
virtual int sp_forward (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
 Propagate sparsity forward. More...
 
virtual int eval_activity (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
 Propagate signal activity forward. More...
 
virtual int sp_forward_block (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, casadi_int oind, casadi_int iind) const
 Propagate sparsity forward, specific block. More...
 
virtual int sp_reverse (bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
 Propagate sparsity backwards. 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...
 
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 alloc_arg (size_t sz_arg, bool persistent=false)
 Ensure required length of arg field. More...
 
void alloc_res (size_t sz_res, bool persistent=false)
 Ensure required length of res field. More...
 
void alloc_iw (size_t sz_iw, bool persistent=false)
 Ensure required length of iw field. More...
 
void alloc_w (size_t sz_w, bool persistent=false)
 Ensure required length of w field. More...
 
void alloc (const Function &f, bool persistent=false, int num_threads=1)
 Ensure work vectors long enough to evaluate function. More...
 
virtual void set_work (void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const
 Set the (persistent) work vectors. More...
 
virtual void set_temp (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
 Set the (temporary) work vectors. More...
 
void setup (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
 Set the (persistent and temporary) work vectors. More...
 
virtual Dict info () const
 
Function map (casadi_int n, const std::string &parallelization) const
 Generate/retrieve cached serial map. More...
 
void generate_in (const std::string &fname, const double **arg) const
 Export an input file that can be passed to generate C code with a main. More...
 
void generate_out (const std::string &fname, double **res) const
 
virtual bool is_a (const std::string &type, bool recursive) const
 Check if the function is of a particular type. More...
 
virtual void merge (const std::vector< MX > &arg, std::vector< MX > &subs_from, std::vector< MX > &subs_to) const
 List merge opportunitities. More...
 
template<typename MatType >
std::vector< std::vector< MatType > > fwd_seed (casadi_int nfwd) const
 Symbolic expressions for the forward seeds. More...
 
template<typename MatType >
std::vector< std::vector< MatType > > symbolicAdjSeed (casadi_int nadj, const std::vector< MatType > &v) const
 Symbolic expressions for the adjoint seeds. More...
 
void print_in (std::ostream &stream, const double **arg, bool truncate) const
 Print inputs. More...
 
void print_out (std::ostream &stream, double **res, bool truncate) const
 Print outputs. More...
 
void construct (const Dict &opts)
 Construct. More...
 
void print_options (std::ostream &stream) const
 Print list of options. More...
 
void print_option (const std::string &name, std::ostream &stream) 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...
 
int checkout () const
 Checkout a memory object. More...
 
void release (int mem) const
 Release a memory object. More...
 
void * memory (int ind) const
 Memory objects. More...
 
bool has_memory (int ind) const
 Check for existance of memory object. More...
 
void clear_mem ()
 Clear all memory (called from destructor) More...
 
void print (const char *fmt,...) const
 C-style formatted printing during evaluation. More...
 
void sprint (char *buf, size_t buf_sz, const char *fmt,...) const
 C-style formatted printing to string. More...
 
void format_time (char *buffer, double time) const
 Format time in a fixed width 8 format. More...
 
void print_time (const std::map< std::string, FStats > &fstats) const
 Print timing statistics. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
virtual std::string serialize_base_function () const
 String used to identify the immediate FunctionInternal subclass. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
std::string debug_repr (const SharedObjectInternal *) const
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
size_t get_n_in () override
 Number of function inputs and outputs. More...
 
size_t get_n_out () override
 Number of function inputs and outputs. More...
 
Sparsity get_sparsity_in (casadi_int i) override
 Retreive sparsities. More...
 
Sparsity get_sparsity_out (casadi_int i) override
 Retreive sparsities. More...
 
std::vector< double > get_nominal_in (casadi_int i) const override
 Retreive nominal values. More...
 
std::vector< double > get_nominal_out (casadi_int i) const override
 Retreive nominal values. More...
 
bool has_jac_sparsity (casadi_int oind, casadi_int iind) const override
 Return sparsity of Jacobian of an output respect to an input. More...
 
Sparsity get_jac_sparsity (casadi_int oind, casadi_int iind, bool symmetric) const override
 Return sparsity of Jacobian of an output respect to an input. More...
 
bool has_jacobian () const override
 Full Jacobian. More...
 
Function get_jacobian (const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
 Full Jacobian. More...
 
bool has_forward (casadi_int nfwd) const override
 Return function that calculates forward derivatives. More...
 
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 override
 Return function that calculates forward derivatives. More...
 
bool has_reverse (casadi_int nadj) const override
 Reverse mode AD. More...
 
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 override
 Reverse mode AD. More...
 
virtual bool has_spfwd () const
 Is the class able to propagate seeds through the algorithm? More...
 
virtual bool has_sprev () const
 Is the class able to propagate seeds through the algorithm? More...
 
int eval_gen (const double **arg, double **res, casadi_int *iw, double *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate numerically. More...
 
int eval_gen (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate a function, overloaded. More...
 
int eval_gen (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate a function, overloaded. More...
 
virtual std::vector< DM > eval_dm (const std::vector< DM > &arg) const
 Evaluate with DM matrices. More...
 
virtual bool has_eval_dm () const
 Evaluate with DM matrices. More...
 
void call_gen (const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename D >
void call_gen (const std::vector< Matrix< D > > &arg, std::vector< Matrix< D > > &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename M >
void check_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments have correct length and dimensions. More...
 
template<typename M >
void check_res (const std::vector< M > &res, casadi_int &npar) const
 Check if output arguments have correct length and dimensions. More...
 
template<typename M >
std::map< std::string, M > convert_arg (const std::vector< M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_arg (const std::map< std::string, M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::map< std::string, M > convert_res (const std::vector< M > &res) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_res (const std::map< std::string, M > &res) const
 Convert from/to input/output lists/map. More...
 
std::vector< double > nz_in (const std::vector< DM > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DM > nz_in (const std::vector< double > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< double > nz_out (const std::vector< DM > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DM > nz_out (const std::vector< double > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
virtual void call_forward (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_forward (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &fseed, std::vector< std::vector< SX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &aseed, std::vector< std::vector< SX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
Function jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
Sparsity & jac_sparsity (casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
 Get Jacobian sparsity. More...
 
Function forward (casadi_int nfwd) const
 Return function that calculates forward derivatives. More...
 
Function reverse (casadi_int nadj) const
 Return function that calculates adjoint derivatives. More...
 
virtual const SX sx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SX > sx_in () const
 Get function input(s) and output(s) More...
 
virtual const SX sx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SX > sx_out () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MX > mx_in () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MX > mx_out () const
 Get function input(s) and output(s) More...
 
const DM dm_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DM > dm_in () const
 Get function input(s) and output(s) More...
 
const DM dm_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DM > dm_out () const
 Get function input(s) and output(s) More...
 
Function wrap (const std::string &name) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap () const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const std::string &name, const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
casadi_int nnz_in () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_in (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int numel_in () const
 Number of input/output elements. More...
 
casadi_int numel_in (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out () const
 Number of input/output elements. More...
 
casadi_int size1_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size1_out (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_out (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_in (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_out (casadi_int ind) const
 Input/output dimensions. More...
 
const Sparsity & sparsity_in (casadi_int ind) const
 Input/output sparsity. More...
 
const Sparsity & sparsity_out (casadi_int ind) const
 Input/output sparsity. More...
 
bool all_scalar () const
 Are all inputs and outputs scalar. More...
 
virtual bool jac_is_symm (casadi_int oind, casadi_int iind) const
 Is a Jacobian block known to be symmetric a priori? More...
 
Sparsity to_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert to compact Jacobian sparsity pattern. More...
 
Sparsity from_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert from compact Jacobian sparsity pattern. More...
 
template<bool fwd>
Sparsity get_jac_sparsity_gen (casadi_int oind, casadi_int iind) const
 Get the sparsity pattern via sparsity seed propagation. More...
 
Sparsity get_jac_sparsity_hierarchical (casadi_int oind, casadi_int iind) const
 A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition. More...
 
Sparsity get_jac_sparsity_hierarchical_symm (casadi_int oind, casadi_int iind) const
 
virtual std::vector< MX > symbolic_output (const std::vector< MX > &arg) const
 Get a vector of symbolic variables corresponding to the outputs. More...
 
virtual std::string get_name_in (casadi_int i)
 Names of function input and outputs. More...
 
virtual std::string get_name_out (casadi_int i)
 Names of function input and outputs. More...
 
virtual size_t codegen_sz_arg (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_res (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_iw (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_w (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual bool fwdViaJac (casadi_int nfwd) const
 Calculate derivatives by multiplying the full Jacobian and multiplying. More...
 
virtual bool adjViaJac (casadi_int nadj) const
 Calculate derivatives by multiplying the full Jacobian and multiplying. More...
 

Static Public Member Functions

static void identify_io (std::vector< std::string > *scheme_in, std::vector< std::string > *scheme_out, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out)
 
static ProtoFunction * deserialize (DeserializingStream &s)
 Deserialize without type information. More...
 
static std::string forward_name (const std::string &fcn, casadi_int nfwd)
 Helper function: Get name of forward derivative function. More...
 
static std::string reverse_name (const std::string &fcn, casadi_int nadj)
 Helper function: Get name of adjoint derivative function. More...
 
template<typename MatType >
static MatType ensure_stacked (const MatType &v, const Sparsity &sp, casadi_int n)
 Ensure that a matrix's sparsity is a horizontal multiple of another, or empty. More...
 
static std::string get_jit_directory (const Dict &jit_options)
 Get JIT directory from options. More...
 
template<typename MatType >
static bool purgable (const std::vector< MatType > &seed)
 Can a derivative direction be skipped. More...
 
static std::string string_from_UnifiedReturnStatus (UnifiedReturnStatus status)
 
static void print_canonical (std::ostream &stream, const Sparsity &sp, const double *nz)
 Print canonical representation of a numeric matrix. More...
 
static void print_canonical (std::ostream &stream, casadi_int sz, const double *nz)
 Print canonical representation of a numeric vector. More...
 
static void print_canonical (std::ostream &stream, double a)
 Print canonical representation of a number. More...
 
static bool check_mat (const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
 

Public Attributes

Fmu fmu_
 
std::vector< InputStruct > in_
 
std::vector< OutputStruct > out_
 
std::vector< size_t > jac_in_
 
std::vector< size_t > jac_out_
 
std::vector< double > jac_nom_in_
 
std::vector< Sparsity > sp_trans_
 
std::vector< casadi_int > sp_trans_map_
 
bool has_jac_
 
bool has_fwd_
 
bool has_adj_
 
bool has_hess_
 
bool uses_directional_derivatives_
 
bool uses_adjoint_derivatives_
 
casadi_int nfwd_
 Number of sensitivities. More...
 
casadi_int nadj_
 
bool validate_forward_
 
bool validate_hessian_
 
double step_
 
double abstol_
 
double reltol_
 
bool print_progress_
 
bool new_jacobian_
 
bool new_forward_
 
bool new_hessian_
 
bool fd_flip_
 
bool make_symmetric_
 
bool hessian_coloring_
 
bool asymmetric_hessian_coloring_
 
bool enable_forward_jacobian_
 
bool enable_adjoint_jacobian_
 
bool enable_adjoint_hessian_
 
std::string validate_ad_file_
 
FdMode fd_
 
Parallelization parallelization_
 
Dict init_stats_
 
Sparsity jac_sp_
 
Sparsity hess_sp_
 
Sparsity adj_sp_
 
Sparsity jac_colors_
 
Sparsity adj_colors_
 
Sparsity hess_colors_
 
Sparsity hess_uni_colors_
 
std::vector< casadi_int > which_hess_color_
 
std::vector< casadi_int > nonlin_
 
casadi_jac_prob< double > jac_prob_
 
casadi_jac_prob< double > adj_prob_
 
casadi_int max_jac_tasks_
 
casadi_int max_hess_tasks_
 
casadi_int max_adj_tasks_
 
casadi_int max_n_tasks_
 
bool always_inline_
 
bool never_inline_
 
size_t n_in_
 Number of inputs and outputs. More...
 
size_t n_out_
 
std::vector< bool > is_diff_in_
 Are inputs and outputs differentiable? More...
 
std::vector< bool > is_diff_out_
 
std::vector< Sparsity > sparsity_in_
 Input and output sparsity. More...
 
std::vector< Sparsity > sparsity_out_
 
std::vector< std::string > name_in_
 Input and output scheme. More...
 
std::vector< std::string > name_out_
 
bool jit_
 Use just-in-time compiler. More...
 
bool jit_cleanup_
 Cleanup jit source file. More...
 
std::string jit_serialize_
 Serialize behaviour. More...
 
std::string jit_name_
 Name if jit source file. More...
 
std::string jit_directory_
 
std::string jit_base_name_
 
bool jit_temp_suffix_
 Use a temporary name. More...
 
eval_t eval_
 Numerical evaluation redirected to a C function. More...
 
casadi_checkout_t checkout_
 Checkout redirected to a C function. More...
 
casadi_release_t release_
 Release redirected to a C function. More...
 
signal_t incref_
 Incref/decref redirected to C functions. More...
 
signal_t decref_
 
Dict stats_
 Dict of statistics (resulting from evaluate) More...
 
bool has_refcount_
 Reference counting in codegen? More...
 
bool has_refcount_in_deps_
 Reference counting in dependent functions. More...
 
Dict cache_init_
 Values to prepopulate the function cache with. More...
 
WeakCache< std::string, Function > cache_
 Function cache. More...
 
std::vector< Sparsity > jac_sparsity_ [2]
 Cache for sparsities of the Jacobian blocks. More...
 
Function derivative_of_
 If the function is the derivative of another function. More...
 
void * user_data_
 User-set field. More...
 
std::string compiler_plugin_
 Just-in-time compiler. More...
 
Importer compiler_
 
Dict jit_options_
 
double jac_penalty_
 Penalty factor for using a complete Jacobian to calculate directional derivatives. More...
 
bool enable_forward_
 
bool enable_reverse_
 
bool enable_jacobian_
 
bool enable_fd_
 
bool enable_forward_op_
 
bool enable_reverse_op_
 
bool enable_jacobian_op_
 
bool enable_fd_op_
 
double ad_weight_
 Weighting factor for derivative calculation and sparsity pattern calculation. More...
 
double ad_weight_sp_
 
casadi_int max_num_dir_
 Maximum number of sensitivity directions. More...
 
bool inputs_check_
 Errors are thrown if numerical values of inputs look bad. More...
 
Dict fd_options_
 
double fd_step_
 
std::string fd_method_
 
bool print_in_
 
bool print_out_
 
bool print_canonical_
 
casadi_int max_io_
 
bool dump_in_
 
bool dump_out_
 
bool dump_
 
std::string dump_dir_
 
std::string dump_format_
 
Dict forward_options_
 
Dict reverse_options_
 
Dict jacobian_options_
 
Dict der_options_
 
Function custom_jacobian_
 
std::vector< Function > registered_functions_
 
casadi_int dump_count_
 
std::string name_
 Name. More...
 
bool verbose_
 Verbose printout. More...
 
bool print_time_
 
bool record_time_
 
bool regularity_check_
 Errors are thrown when NaN is produced. More...
 
bool error_on_fail_
 Throw an exception on failure? More...
 

Static Public Attributes

static std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> deserialize_map
 

Protected Member Functions

 FmuFunction (DeserializingStream &s)
 Deserializing constructor. More...
 
void set_jac_sparsity (casadi_int oind, casadi_int iind, const Sparsity &sp)
 Populate jac_sparsity_ and jac_sparsity_compact_ during initialization. More...
 
std::unique_ptr< std::ostream > open_trace (const double **arg, casadi_int dump_id) const
 
void finish_trace (std::ostream &trace, double **res, int ret) const
 
void initSingleton ()
 
void destroySingleton ()
 
B shared_from_this ()
 Get a shared object from the current internal object. More...
 
const B shared_from_this () const
 Get a shared object from the current internal object. More...
 

Static Protected Member Functions

static void trace_values (std::ostream &trace, const double *values, casadi_int nnz)
 
static const Options options_
 Options. More...
 
const Options & get_options () const override
 Options. More...
 

Member Typedef Documentation

◆ weak_ref_type

Definition at line 152 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ FmuFunction() [1/2]

casadi::FmuFunction::FmuFunction ( const std::string &  name,
const Fmu &  fmu,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out 
)

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

Definition at line 115 of file fmu_function.cpp.

118  : FunctionInternal(name), fmu_(fmu) {
119  // Parse input IDs
120  in_.resize(name_in.size());
121  for (size_t k = 0; k < name_in.size(); ++k) {
122  try {
123  in_[k] = InputStruct::parse(name_in[k], &fmu);
124  } catch (std::exception& e) {
125  casadi_error("Cannot process input " + name_in[k] + ": " + std::string(e.what()));
126  }
127  }
128  // Parse output IDs
129  out_.resize(name_out.size());
130  for (size_t k = 0; k < name_out.size(); ++k) {
131  try {
132  out_[k] = OutputStruct::parse(name_out[k], &fmu);
133  } catch (std::exception& e) {
134  casadi_error("Cannot process output " + name_out[k] + ": " + std::string(e.what()));
135  }
136  }
137  // Which inputs and outputs exist
138  has_fwd_ = has_adj_ = has_jac_ = has_hess_ = false;
139  for (auto&& i : out_) {
140  switch (i.type) {
141  case OutputType::JAC:
143  has_jac_ = true;
144  break;
145  case OutputType::FWD:
146  has_fwd_ = true;
147  break;
148  case OutputType::ADJ:
149  has_adj_ = true;
150  break;
151  case OutputType::HESS:
152  has_adj_ = true;
153  has_hess_ = true;
154  default:
155  break;
156  }
157  }
158  // Set input/output names
159  name_in_ = name_in;
160  name_out_ = name_out;
161  // Default options
162  uses_directional_derivatives_ = fmu.provides_directional_derivatives();
163  uses_adjoint_derivatives_ = fmu.provides_adjoint_derivatives();
164  validate_forward_ = false;
165  validate_hessian_ = false;
166  validate_ad_file_ = "";
167  make_symmetric_ = true;
168  nfwd_ = has_fwd_ ? 1 : 0;
169  nadj_ = has_adj_ ? 1 : 0;
170  // Use FD for second and higher order derivatives
171  enable_fd_op_ = fmu.provides_directional_derivatives() && !all_regular();
172  step_ = 1e-6;
173  fd_flip_ = true;
174  abstol_ = 1e-3;
175  reltol_ = 1e-3;
176  print_progress_ = false;
177  new_jacobian_ = true;
178  new_forward_ = true;
179  new_hessian_ = true;
181  enable_adjoint_jacobian_ = false;
182  enable_adjoint_hessian_ = false; // change to true when tested and adjoints are available
183  hessian_coloring_ = true;
186  // Number of parallel tasks, by default
187  max_n_tasks_ = 1;
189 }
std::vector< InputStruct > in_
Parallelization parallelization_
casadi_int nfwd_
Number of sensitivities.
std::string validate_ad_file_
bool all_regular() const
std::vector< OutputStruct > out_
casadi_int max_jac_tasks_
casadi_int max_hess_tasks_
FunctionInternal(const std::string &name)
Constructor.
std::vector< std::string > name_out_
std::vector< std::string > name_in_
Input and output scheme.
static InputStruct parse(const std::string &n, const Fmu *fmu, std::vector< std::string > *name_in=nullptr, std::vector< std::string > *name_out=nullptr)
static OutputStruct parse(const std::string &n, const Fmu *fmu, std::vector< std::string > *name_in=nullptr, std::vector< std::string > *name_out=nullptr)

References abstol_, casadi::ADJ, all_regular(), asymmetric_hessian_coloring_, enable_adjoint_hessian_, enable_adjoint_jacobian_, casadi::FunctionInternal::enable_fd_op_, enable_forward_jacobian_, fd_flip_, casadi::FWD, has_adj_, has_fwd_, has_hess_, has_jac_, casadi::HESS, hessian_coloring_, in_, casadi::JAC, casadi::JAC_TRANS, make_symmetric_, max_hess_tasks_, max_jac_tasks_, max_n_tasks_, nadj_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, new_forward_, new_hessian_, new_jacobian_, nfwd_, out_, parallelization_, casadi::InputStruct::parse(), casadi::OutputStruct::parse(), print_progress_, casadi::Fmu::provides_adjoint_derivatives(), casadi::Fmu::provides_directional_derivatives(), reltol_, casadi::SERIAL, step_, uses_adjoint_derivatives_, uses_directional_derivatives_, validate_ad_file_, validate_forward_, and validate_hessian_.

Referenced by factory(), get_forward(), get_jacobian(), and get_reverse().

◆ ~FmuFunction()

casadi::FmuFunction::~FmuFunction ( )
override

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

Definition at line 236 of file fmu_function.cpp.

236  {
237  // Free memory
238  clear_mem();
239 }
void clear_mem()
Clear all memory (called from destructor)

References casadi::ProtoFunction::clear_mem().

◆ FmuFunction() [2/2]

casadi::FmuFunction::FmuFunction ( DeserializingStream &  s)
explicitprotected

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

Definition at line 1778 of file fmu_function.cpp.

1778  : FunctionInternal(s) {
1779  s.version("FmuFunction", 6, 6);
1780 
1781  s.unpack("FmuFunction::Fmu", fmu_);
1782 
1783  in_.resize(n_in_);
1784  for (InputStruct& e : in_) {
1785  int t = 0;
1786  s.unpack("FmuFunction::in::type", t);
1787  e.type = static_cast<InputType>(t);
1788  s.unpack("FmuFunction::in::ind", e.ind);
1789  }
1790  out_.resize(n_out_);
1791  for (OutputStruct& e : out_) {
1792  int t = 0;
1793  s.unpack("FmuFunction::out::type", t);
1794  e.type = static_cast<OutputType>(t);
1795  s.unpack("FmuFunction::out::ind", e.ind);
1796  s.unpack("FmuFunction::out::wrt", e.wrt);
1797  s.unpack("FmuFunction::out::rbegin", e.rbegin);
1798  s.unpack("FmuFunction::out::rend", e.rend);
1799  s.unpack("FmuFunction::out::cbegin", e.cbegin);
1800  s.unpack("FmuFunction::out::cend", e.cend);
1801  }
1802 
1803  s.unpack("FmuFunction::jac_in", jac_in_);
1804  s.unpack("FmuFunction::jac_out", jac_out_);
1805 
1806  s.unpack("FmuFunction::jac_nom_in", jac_nom_in_);
1807  s.unpack("FmuFunction::sp_trans", sp_trans_);
1808  s.unpack("FmuFunction::sp_trans_map", sp_trans_map_);
1809 
1810  s.unpack("FmuFunction::has_jac", has_jac_);
1811  s.unpack("FmuFunction::has_fwd", has_fwd_);
1812  s.unpack("FmuFunction::has_adj", has_adj_);
1813  s.unpack("FmuFunction::has_hess", has_hess_);
1814 
1815  s.unpack("FmuFunction::uses_directional_derivatives", uses_directional_derivatives_);
1816  s.unpack("FmuFunction::uses_adjoint_derivatives", uses_adjoint_derivatives_);
1817  s.unpack("FmuFunction::nfwd", nfwd_);
1818  s.unpack("FmuFunction::nadj", nadj_);
1819  s.unpack("FmuFunction::validate_forward", validate_forward_);
1820  s.unpack("FmuFunction::validate_hessian", validate_hessian_);
1821  s.unpack("FmuFunction::make_symmetric", make_symmetric_);
1822  s.unpack("FmuFunction::step", step_);
1823  s.unpack("FmuFunction::fd_flip", fd_flip_);
1824  s.unpack("FmuFunction::abstol", abstol_);
1825  s.unpack("FmuFunction::reltol", reltol_);
1826  s.unpack("FmuFunction::print_progress", print_progress_);
1827  s.unpack("FmuFunction::new_jacobian", new_jacobian_);
1828  s.unpack("FmuFunction::new_forward", new_forward_);
1829  s.unpack("FmuFunction::new_hessian", new_hessian_);
1830  s.unpack("FmuFunction::hessian_coloring", hessian_coloring_);
1831  s.unpack("FmuFunction::asymmetric_hessian_coloring", asymmetric_hessian_coloring_);
1832  s.unpack("FmuFunction::enable_forward_jacobian", enable_forward_jacobian_);
1833  s.unpack("FmuFunction::enable_adjoint_jacobian", enable_adjoint_jacobian_);
1834  s.unpack("FmuFunction::enable_adjoint_hessian", enable_adjoint_hessian_);
1835  s.unpack("FmuFunction::validate_ad_file", validate_ad_file_);
1836 
1837  int fd = 0;
1838  s.unpack("FmuFunction::fd", fd);
1839  fd_ = static_cast<FdMode>(fd);
1840  int parallelization = 0;
1841  s.unpack("FmuFunction::parallelization", parallelization);
1842  parallelization_ = static_cast<Parallelization>(parallelization);
1843 
1844  s.unpack("FmuFunction::init_stats", init_stats_);
1845 
1846  s.unpack("FmuFunction::jac_sp", jac_sp_);
1847  s.unpack("FmuFunction::hess_sp", hess_sp_);
1848  s.unpack("FmuFunction::adj_sp", adj_sp_);
1849  s.unpack("FmuFunction::jac_colors", jac_colors_);
1850  s.unpack("FmuFunction::adj_colors", adj_colors_);
1851  s.unpack("FmuFunction::hess_colors", hess_colors_);
1852  s.unpack("FmuFunction::hess_uni_colors", hess_uni_colors_);
1853  s.unpack("FmuFunction::which_hess_color", which_hess_color_);
1854  s.unpack("FmuFunction::nonlin", nonlin_);
1855 
1856  s.unpack("FmuFunction::max_jac_tasks", max_jac_tasks_);
1857  s.unpack("FmuFunction::max_hess_tasks", max_hess_tasks_);
1858  s.unpack("FmuFunction::max_n_tasks", max_n_tasks_);
1859 
1860  if (has_jac_ || has_adj_ || has_hess_) {
1861  // Setup Jacobian memory (via forward mode)
1862  casadi_jac_setup(&jac_prob_, jac_sp_, jac_colors_);
1866  }
1868  // Setup adjoint Jacobian memory (via reverse mode)
1869  casadi_jac_setup(&adj_prob_, adj_sp_, adj_colors_);
1870  adj_prob_.nom_in = nullptr;
1873  }
1874 }
casadi_jac_prob< double > jac_prob_
casadi_jac_prob< double > adj_prob_
std::vector< casadi_int > sp_trans_map_
std::vector< casadi_int > nonlin_
std::vector< Sparsity > sp_trans_
std::vector< casadi_int > which_hess_color_
std::vector< size_t > jac_in_
std::vector< size_t > jac_out_
std::vector< double > jac_nom_in_
size_t n_in_
Number of inputs and outputs.
FdMode
Variable type.
Parallelization
Type of parallelization.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
const size_t * map_in
Definition: casadi_jac.hpp:39
const T1 * nom_in
Definition: casadi_jac.hpp:35
const size_t * map_out
Definition: casadi_jac.hpp:37

References abstol_, adj_colors_, adj_prob_, adj_sp_, asymmetric_hessian_coloring_, enable_adjoint_hessian_, enable_adjoint_jacobian_, enable_forward_jacobian_, fd_, fd_flip_, fmu_, casadi::get_ptr(), has_adj_, has_fwd_, has_hess_, has_jac_, hess_colors_, hess_sp_, hess_uni_colors_, hessian_coloring_, in_, init_stats_, jac_colors_, jac_in_, jac_nom_in_, jac_out_, jac_prob_, jac_sp_, make_symmetric_, casadi_jac_prob< T1 >::map_in, casadi_jac_prob< T1 >::map_out, max_hess_tasks_, max_jac_tasks_, max_n_tasks_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, nadj_, new_forward_, new_hessian_, new_jacobian_, nfwd_, casadi_jac_prob< T1 >::nom_in, nonlin_, out_, parallelization_, print_progress_, reltol_, sp_trans_, sp_trans_map_, step_, casadi::DeserializingStream::unpack(), uses_adjoint_derivatives_, uses_directional_derivatives_, validate_ad_file_, validate_forward_, validate_hessian_, casadi::DeserializingStream::version(), and which_hess_color_.

Member Function Documentation

◆ ad_weight()

double casadi::FunctionInternal::ad_weight ( ) const
virtualinherited

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

Definition at line 3522 of file function_internal.cpp.

3522  {
3523  // If reverse mode derivatives unavailable, use forward
3524  if (!enable_reverse_) return 0;
3525 
3526  // If forward mode derivatives unavailable, use reverse
3527  if (!enable_forward_ && !enable_fd_) return 1;
3528 
3529  // Use the (potentially user set) option
3530  return ad_weight_;
3531  }
double ad_weight_
Weighting factor for derivative calculation and sparsity pattern calculation.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, and casadi::FunctionInternal::enable_reverse_.

Referenced by casadi::FunctionInternal::adjViaJac(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ add_embedded()

void casadi::FunctionInternal::add_embedded ( std::map< FunctionInternal *, std::pair< Function, size_t > > &  all_fun,
const Function &  dep,
casadi_int  max_depth 
) const
inherited

Definition at line 3964 of file function_internal.cpp.

3966  {
3967  // Add, if not already in graph and not null
3968  if (!dep.is_null() && all_fun.find(dep.get()) == all_fun.end()) {
3969  size_t index = all_fun.size();
3970  all_fun[dep.get()] = std::make_pair(dep, index);
3971  // Also add its dependencies
3972  if (max_depth > 0) dep->find(all_fun, max_depth - 1);
3973  }
3974  }

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

Referenced by casadi::FunctionInternal::find(), casadi::Map::find(), casadi::MapSum::find(), casadi::MXFunction::find(), casadi::OracleFunction::find(), casadi::Switch::find(), casadi::SXFunction::find(), and casadi::BSplineInterpolant::find().

◆ adjViaJac()

bool casadi::FunctionInternal::adjViaJac ( casadi_int  nadj) const
virtualinherited

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

Definition at line 3255 of file function_internal.cpp.

3255  {
3256  if (!enable_reverse_) return true;
3257  if (jac_penalty_==-1) return false;
3258 
3259  // Heuristic 1: Jac calculated via reverse mode likely cheaper
3260  if (jac_penalty_*static_cast<double>(nnz_out())<nadj) return true;
3261 
3262  // Heuristic 2: Jac calculated via forward mode likely cheaper
3263  double w = ad_weight();
3264  if ((enable_forward_ || enable_fd_) &&
3265  jac_penalty_*w*static_cast<double>(nnz_in())<(1-w)*static_cast<double>(nadj))
3266  return true; // NOLINT
3267 
3268  return false;
3269  }
double jac_penalty_
Penalty factor for using a complete Jacobian to calculate directional derivatives.
virtual double ad_weight() const
Weighting factor for chosing forward/reverse mode.
casadi_int nnz_in() const
Number of input/output nonzeros.
casadi_int nnz_out() const
Number of input/output nonzeros.

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::nnz_in(), and casadi::FunctionInternal::nnz_out().

Referenced by casadi::FunctionInternal::call_reverse().

◆ all_regular()

bool casadi::FmuFunction::all_regular ( ) const

Definition at line 1513 of file fmu_function.cpp.

1513  {
1514  // Look for any non-regular input
1515  for (auto&& e : in_) if (e.type != InputType::REG) return false;
1516  // Look for any non-regular output
1517  for (auto&& e : out_) if (e.type != OutputType::REG) return false;
1518  // Only regular inputs and outputs
1519  return true;
1520 }

References in_, out_, and casadi::REG.

Referenced by FmuFunction(), has_forward(), has_jacobian(), and has_reverse().

◆ all_scalar()

bool casadi::FunctionInternal::all_scalar ( ) const
inherited

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

Definition at line 4009 of file function_internal.cpp.

4009  {
4010  // Check inputs
4011  for (casadi_int i=0; i<n_in_; ++i) {
4012  if (!sparsity_in_[i].is_scalar()) return false;
4013  }
4014  // Check outputs
4015  for (casadi_int i=0; i<n_out_; ++i) {
4016  if (!sparsity_out_[i].is_scalar()) return false;
4017  }
4018  // All are scalar
4019  return true;
4020  }
std::vector< Sparsity > sparsity_in_
Input and output sparsity.
std::vector< Sparsity > sparsity_out_

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::call().

◆ all_vectors()

bool casadi::FmuFunction::all_vectors ( ) const

Definition at line 1522 of file fmu_function.cpp.

1522  {
1523  // Check inputs
1524  for (auto&& e : in_) {
1525  switch (e.type) {
1526  // Supported for derivative calculations
1527  case InputType::REG:
1528  case InputType::OUT:
1529  break;
1530  // Supported if one derivative
1531  case InputType::FWD:
1532  if (nfwd_ > 1) return false;
1533  break;
1534  case InputType::ADJ:
1535  if (nadj_ > 1) return false;
1536  break;
1537  // Not supported
1538  default:
1539  return false;
1540  }
1541  }
1542  // Check outputs
1543  for (auto&& e : out_) {
1544  // Supported for derivative calculations
1545  switch (e.type) {
1546  case OutputType::REG:
1547  case OutputType::ADJ:
1548  break;
1549  // Not supported
1550  default:
1551  return false;
1552  }
1553  }
1554  // OK if reached this point
1555  return true;
1556 }

References casadi::ADJ, casadi::FWD, in_, nadj_, nfwd_, casadi::OUT, out_, and casadi::REG.

Referenced by has_jacobian().

◆ alloc()

void casadi::FunctionInternal::alloc ( const Function &  f,
bool  persistent = false,
int  num_threads = 1 
)
inherited

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

Definition at line 3203 of file function_internal.cpp.

3203  {
3204  if (f.is_null()) return;
3205  size_t sz_arg, sz_res, sz_iw, sz_w;
3206  f.sz_work(sz_arg, sz_res, sz_iw, sz_w);
3207  alloc_arg(sz_arg*num_threads, persistent);
3208  alloc_res(sz_res*num_threads, persistent);
3209  alloc_iw(sz_iw*num_threads, persistent);
3210  alloc_w(sz_w*num_threads, persistent);
3211  registered_functions_.push_back(f);
3212  }
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
void alloc_res(size_t sz_res, bool persistent=false)
Ensure required length of res field.
void alloc_arg(size_t sz_arg, bool persistent=false)
Ensure required length of arg field.
std::vector< Function > registered_functions_
size_t sz_res() const
Get required length of res field.
size_t sz_w() const
Get required length of w field.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
size_t sz_arg() const
Get required length of arg field.
size_t sz_iw() const
Get required length of iw field.

References casadi::FunctionInternal::alloc_arg(), casadi::FunctionInternal::alloc_iw(), casadi::FunctionInternal::alloc_res(), casadi::FunctionInternal::alloc_w(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::registered_functions_, casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::Function::sz_work().

Referenced by casadi::OracleFunction::finalize(), casadi::KinsolInterface::get_jtimes(), casadi::FiniteDiff::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), casadi::Feasiblesqpmethod::init(), casadi::ImplicitToNlp::init(), casadi::QpToNlp::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), and casadi::Sqpmethod::init().

◆ alloc_arg()

void casadi::FunctionInternal::alloc_arg ( size_t  sz_arg,
bool  persistent = false 
)
inherited

◆ alloc_iw()

void casadi::FunctionInternal::alloc_iw ( size_t  sz_iw,
bool  persistent = false 
)
inherited

◆ alloc_mem()

void * casadi::FmuFunction::alloc_mem ( ) const
overridevirtual

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

Reimplemented from casadi::ProtoFunction.

Definition at line 81 of file fmu_function.cpp.

81  {
82  // Create (master) memory object
83  FmuMemory* m = fmu_.alloc_mem(*this);
84  // Attach additional (slave) memory objects
85  for (casadi_int i = 1; i < max_jac_tasks_; ++i) {
86  m->slaves.push_back(fmu_.alloc_mem(*this));
87  }
88  return m;
89 }
FmuMemory * alloc_mem(const FmuFunction &f) const
Create memory block.
Definition: fmu.cpp:95
std::vector< FmuMemory * > slaves

References casadi::Fmu::alloc_mem(), fmu_, max_jac_tasks_, and casadi::FmuMemory::slaves.

◆ alloc_res()

void casadi::FunctionInternal::alloc_res ( size_t  sz_res,
bool  persistent = false 
)
inherited

◆ alloc_w()

void casadi::FunctionInternal::alloc_w ( size_t  sz_w,
bool  persistent = false 
)
inherited

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

Definition at line 3195 of file function_internal.cpp.

3195  {
3196  if (persistent) {
3197  sz_w_per_ += sz_w;
3198  } else {
3199  sz_w_tmp_ = std::max(sz_w_tmp_, sz_w);
3200  }
3201  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::alloc(), casadi::BlazingSplineFunction::init(), casadi::External::init(), casadi::FiniteDiff::init(), init(), casadi::Integrator::init(), casadi::FixedStepIntegrator::init(), casadi::Interpolant::init(), casadi::JitFunction::init(), casadi::Map::init(), casadi::OmpMap::init(), casadi::ThreadMap::init(), casadi::MapSum::init(), casadi::MXFunction::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), casadi::SXFunction::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::CbcInterface::init(), casadi::MadmpecInterface::init(), casadi::ClarabelInterface::init(), casadi::ClpInterface::init(), casadi::CplexInterface::init(), casadi::DaqpInterface::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::GurobiInterface::init(), casadi::HighsInterface::init(), casadi::HpipmInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::MadnlpInterface::init(), casadi::MosekInterface::init(), casadi::OoqpInterface::init(), casadi::OsqpInterface::init(), casadi::PiqpInterface::init(), casadi::ProxqpInterface::init(), casadi::QpoasesInterface::init(), casadi::SLEQPInterface::init(), casadi::SlicotDple::init(), casadi::SlicotExpm::init(), casadi::SnoptInterface::init(), casadi::CvodesInterface::init(), casadi::IdasInterface::init(), casadi::KinsolInterface::init(), casadi::SundialsInterface::init(), casadi::SuperscsInterface::init(), casadi::WorhpInterface::init(), casadi::XpressInterface::init(), casadi::BSplineInterpolant::init(), casadi::FastNewton::init(), casadi::Feasiblesqpmethod::init(), casadi::ImplicitToNlp::init(), casadi::Ipqp::init(), casadi::LinearInterpolant::init(), casadi::LinearInterpolantJac::init(), casadi::Newton::init(), casadi::QpToNlp::init(), casadi::Qrqp::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), and casadi::Sqpmethod::init().

◆ cache()

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

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

Definition at line 1163 of file function_internal.cpp.

1163  {
1164  // Return value
1165  Dict ret;
1166 
1167  // Retrieve all Function instances that haven't been deleted
1168  std::vector<std::string> keys;
1169  std::vector<Function> entries;
1170  cache_.cache(keys, entries);
1171 
1172  for (size_t i=0; i<keys.size(); ++i) {
1173  // Get the name of the key
1174  std::string s = keys[i];
1175  casadi_assert_dev(s.size() > 0);
1176  // Replace ':' with '_'
1177  std::replace(s.begin(), s.end(), ':', '_');
1178  // Remove trailing underscore, if any
1179  if (s.back() == '_') s.resize(s.size() - 1);
1180  // Add entry to function return
1181  ret[s] = entries[i];
1182  }
1183 
1184  return ret;
1185  }
WeakCache< std::string, Function > cache_
Function cache.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

References casadi::FunctionInternal::cache_.

◆ call()

template<typename M >
void casadi::FunctionInternal::call ( const std::vector< M > &  arg,
std::vector< M > &  res,
bool  always_inline,
bool  never_inline 
) const
inherited

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

Definition at line 1622 of file function_internal.hpp.

1623  {
1624  // If all inputs are scalar ...
1625  if (all_scalar()) {
1626  // ... and some arguments are matrix-valued with matching dimensions ...
1627  bool matrix_call = false;
1628  std::pair<casadi_int, casadi_int> sz;
1629  for (auto&& a : arg) {
1630  if (!a.is_scalar() && !a.is_empty()) {
1631  if (!matrix_call) {
1632  // Matrix call
1633  matrix_call = true;
1634  sz = a.size();
1635  } else if (a.size()!=sz) {
1636  // Not same dimensions
1637  matrix_call = false;
1638  break;
1639  }
1640  }
1641  }
1642 
1643  // ... then, call multiple times
1644  if (matrix_call) {
1645  // Start with zeros
1646  res.resize(n_out_);
1647  M z = M::zeros(sz);
1648  for (auto&& a : res) a = z;
1649  // Call multiple times
1650  std::vector<M> arg1 = arg, res1;
1651  for (casadi_int c=0; c<sz.second; ++c) {
1652  for (casadi_int r=0; r<sz.first; ++r) {
1653  // Get scalar arguments
1654  for (casadi_int i=0; i<arg.size(); ++i) {
1655  if (arg[i].size()==sz) arg1[i] = arg[i](r, c);
1656  }
1657  // Call recursively with scalar arguments
1658  call(arg1, res1, always_inline, never_inline);
1659  // Get results
1660  casadi_assert_dev(res.size() == res1.size());
1661  for (casadi_int i=0; i<res.size(); ++i) res[i](r, c) = res1[i];
1662  }
1663  }
1664  // All elements assigned
1665  return;
1666  }
1667  }
1668 
1669  // Check if inputs need to be replaced
1670  casadi_int npar = 1;
1671  if (!matching_arg(arg, npar)) {
1672  return call(replace_arg(arg, npar), res, always_inline, never_inline);
1673  }
1674 
1675  // Call the type-specific method
1676  call_gen(arg, res, npar, always_inline, never_inline);
1677  }
void call_gen(const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
Call a function, overloaded.
std::vector< M > replace_arg(const std::vector< M > &arg, casadi_int npar) const
Replace 0-by-0 inputs.
bool matching_arg(const std::vector< M > &arg, casadi_int &npar) const
Check if input arguments that needs to be replaced.
void call(const std::vector< M > &arg, std::vector< M > &res, bool always_inline, bool never_inline) const
Call a function, templated.
bool all_scalar() const
Are all inputs and outputs scalar.

References casadi::FunctionInternal::all_scalar(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::replace_arg().

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

◆ call_forward() [1/2]

void casadi::FunctionInternal::call_forward ( const std::vector< MX > &  arg,
const std::vector< MX > &  res,
const std::vector< std::vector< MX > > &  fseed,
std::vector< std::vector< MX > > &  fsens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

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

Definition at line 3275 of file function_internal.cpp.

3279  {
3280  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3281  casadi_assert(!always_inline, "Class " + class_name() +
3282  " cannot be inlined in an MX expression");
3283 
3284  // Derivative information must be available
3285  casadi_assert(has_derivative(),
3286  "Derivatives cannot be calculated for " + name_);
3287 
3288  // Number of directional derivatives
3289  casadi_int nfwd = fseed.size();
3290  fsens.resize(nfwd);
3291 
3292  // Quick return if no seeds
3293  if (nfwd==0) return;
3294 
3295  // Check if seeds need to have dimensions corrected
3296  casadi_int npar = 1;
3297  for (auto&& r : fseed) {
3298  if (!matching_arg(r, npar)) {
3299  FunctionInternal::call_forward(arg, res, replace_fseed(fseed, npar),
3300  fsens, always_inline, never_inline);
3301  return;
3302  }
3303  }
3304 
3305  // Calculating full Jacobian and then multiplying
3306  if (fwdViaJac(nfwd)) {
3307  // Multiply the Jacobian from the right
3308  std::vector<MX> darg = arg;
3309  darg.insert(darg.end(), res.begin(), res.end());
3310  std::vector<MX> J = jacobian()(darg);
3311  // Join forward seeds
3312  std::vector<MX> v(nfwd), all_fseed(n_in_);
3313  for (size_t i = 0; i < n_in_; ++i) {
3314  for (size_t d = 0; d < nfwd; ++d) v[d] = vec(fseed.at(d).at(i));
3315  all_fseed[i] = horzcat(v);
3316  }
3317  // Calculate forward sensitivities
3318  std::vector<MX> all_fsens(n_out_);
3319  std::vector<MX>::const_iterator J_it = J.begin();
3320  for (size_t oind = 0; oind < n_out_; ++oind) {
3321  for (size_t iind = 0; iind < n_in_; ++iind) {
3322  // Add contribution
3323  MX a = mtimes(*J_it++, all_fseed[iind]);
3324  all_fsens[oind] = all_fsens[oind].is_empty(true) ? a : all_fsens[oind] + a;
3325  }
3326  }
3327  // Split forward sensitivities
3328  for (size_t d = 0; d < nfwd; ++d) fsens[d].resize(n_out_);
3329  for (size_t i = 0; i < n_out_; ++i) {
3330  v = horzsplit(all_fsens[i]);
3331  casadi_assert_dev(v.size() == nfwd);
3332  for (size_t d = 0; d < nfwd; ++d) fsens[d][i] = reshape(v[d], size_out(i));
3333  }
3334  } else {
3335  // Evaluate in batches
3336  casadi_assert_dev(enable_forward_ || enable_fd_);
3337  casadi_int max_nfwd = max_num_dir_;
3338  if (!enable_fd_) {
3339  while (!has_forward(max_nfwd)) max_nfwd/=2;
3340  }
3341  casadi_int offset = 0;
3342  while (offset<nfwd) {
3343  // Number of derivatives, in this batch
3344  casadi_int nfwd_batch = std::min(nfwd-offset, max_nfwd);
3345 
3346  // All inputs and seeds
3347  std::vector<MX> darg;
3348  darg.reserve(n_in_ + n_out_ + n_in_);
3349  darg.insert(darg.end(), arg.begin(), arg.end());
3350  darg.insert(darg.end(), res.begin(), res.end());
3351  std::vector<MX> v(nfwd_batch);
3352  for (casadi_int i=0; i<n_in_; ++i) {
3353  for (casadi_int d=0; d<nfwd_batch; ++d) v[d] = fseed[offset+d][i];
3354  darg.push_back(horzcat(v));
3355  }
3356 
3357  // Create the evaluation node
3358  Function dfcn = self().forward(nfwd_batch);
3359  std::vector<MX> x = dfcn(darg);
3360 
3361  casadi_assert_dev(x.size()==n_out_);
3362 
3363  // Retrieve sensitivities
3364  for (casadi_int d=0; d<nfwd_batch; ++d) fsens[offset+d].resize(n_out_);
3365  for (casadi_int i=0; i<n_out_; ++i) {
3366  if (size2_out(i)>0) {
3367  v = horzsplit(x[i], size2_out(i));
3368  casadi_assert_dev(v.size()==nfwd_batch);
3369  } else {
3370  v = std::vector<MX>(nfwd_batch, MX(size_out(i)));
3371  }
3372  for (casadi_int d=0; d<nfwd_batch; ++d) fsens[offset+d][i] = v[d];
3373  }
3374 
3375  // Update offset
3376  offset += nfwd_batch;
3377  }
3378  }
3379  }
virtual void call_forward(const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens, bool always_inline, bool never_inline) const
Forward mode AD, virtual functions overloaded in derived classes.
Function forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
virtual bool has_forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
std::vector< std::vector< M > > replace_fseed(const std::vector< std::vector< M >> &fseed, casadi_int npar) const
Replace 0-by-0 forward seeds.
bool has_derivative() const
Can derivatives be calculated in any way?
casadi_int size2_out(casadi_int ind) const
Input/output dimensions.
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Input/output dimensions.
casadi_int max_num_dir_
Maximum number of sensitivity directions.
virtual bool fwdViaJac(casadi_int nfwd) const
Calculate derivatives by multiplying the full Jacobian and multiplying.
Function jacobian() const
Return Jacobian of all input elements with respect to all output elements.
virtual std::string class_name() const =0
Readable name of the internal class.

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::forward(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_forward(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::replace_fseed(), casadi::FunctionInternal::size2_out(), and casadi::FunctionInternal::size_out().

Referenced by casadi::Rootfinder::ad_forward(), casadi::Call::ad_forward(), casadi::MXFunction::ad_forward(), casadi::XFunction< DerivedType, MatType, NodeType >::call_forward(), casadi::MX::forward(), casadi::Integrator::get_forward_dae(), and casadi::Scpgen::init().

◆ call_forward() [2/2]

void casadi::FunctionInternal::call_forward ( const std::vector< SX > &  arg,
const std::vector< SX > &  res,
const std::vector< std::vector< SX > > &  fseed,
std::vector< std::vector< SX > > &  fsens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

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

Definition at line 3496 of file function_internal.cpp.

3500  {
3501  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3502  if (fseed.empty()) { // Quick return if no seeds
3503  fsens.clear();
3504  return;
3505  }
3506  casadi_error("'forward' (SX) not defined for " + class_name());
3507  }

References casadi::SharedObjectInternal::class_name().

◆ call_gen() [1/2]

void casadi::FunctionInternal::call_gen ( const MXVector &  arg,
MXVector &  res,
casadi_int  npar,
bool  always_inline,
bool  never_inline 
) const
inherited

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

Definition at line 4183 of file function_internal.cpp.

4185  {
4186  if (npar==1) {
4187  eval_mx(arg, res, always_inline, never_inline);
4188  } else {
4189  // Split it up arguments
4190  std::vector<std::vector<MX>> v(npar, arg);
4191  std::vector<MX> t;
4192  for (int i=0; i<n_in_; ++i) {
4193  if (arg[i].size2()!=size2_in(i)) {
4194  t = horzsplit(arg[i], size2_in(i));
4195  casadi_assert_dev(t.size()==npar);
4196  for (int p=0; p<npar; ++p) v[p][i] = t[p];
4197  }
4198  }
4199  // Unroll the loop
4200  for (int p=0; p<npar; ++p) {
4201  eval_mx(v[p], t, always_inline, never_inline);
4202  v[p] = t;
4203  }
4204  // Concatenate results
4205  t.resize(npar);
4206  res.resize(n_out_);
4207  for (int i=0; i<n_out_; ++i) {
4208  for (int p=0; p<npar; ++p) t[p] = v[p][i];
4209  res[i] = horzcat(t);
4210  }
4211  }
4212  }
virtual void eval_mx(const MXVector &arg, MXVector &res, bool always_inline, bool never_inline) const
Evaluate with symbolic matrices.
casadi_int size2_in(casadi_int ind) const
Input/output dimensions.

References casadi::FunctionInternal::eval_mx(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::size2_in().

Referenced by casadi::FunctionInternal::call().

◆ call_gen() [2/2]

template<typename D >
void casadi::FunctionInternal::call_gen ( const std::vector< Matrix< D > > &  arg,
std::vector< Matrix< D > > &  res,
casadi_int  npar,
bool  always_inline,
bool  never_inline 
) const
inherited

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

Definition at line 1726 of file function_internal.hpp.

1728  {
1729  std::vector< Matrix<D> > arg2 = project_arg(arg, npar);
1730 
1731  // Which arguments require mapped evaluation
1732  std::vector<bool> mapped(n_in_);
1733  for (casadi_int i=0; i<n_in_; ++i) {
1734  mapped[i] = arg[i].size2()!=size2_in(i);
1735  }
1736 
1737  // Allocate results
1738  res.resize(n_out_);
1739  for (casadi_int i=0; i<n_out_; ++i) {
1740  if (!res[i].sparsity().is_stacked(sparsity_out(i), npar)) {
1741  res[i] = Matrix<D>::zeros(repmat(sparsity_out(i), 1, npar));
1742  }
1743  }
1744 
1745  // Allocate temporary memory if needed
1746  std::vector<casadi_int> iw_tmp(sz_iw());
1747  std::vector<D> w_tmp(sz_w());
1748 
1749  // Get pointers to input arguments
1750  std::vector<const D*> argp(sz_arg());
1751  for (casadi_int i=0; i<n_in_; ++i) argp[i]=get_ptr(arg2[i]);
1752 
1753  // Get pointers to output arguments
1754  std::vector<D*> resp(sz_res());
1755  for (casadi_int i=0; i<n_out_; ++i) resp[i]=get_ptr(res[i]);
1756 
1757  // For all parallel calls
1758  for (casadi_int p=0; p<npar; ++p) {
1759  // Call memory-less
1760  if (eval_gen(get_ptr(argp), get_ptr(resp),
1761  get_ptr(iw_tmp), get_ptr(w_tmp), memory(0),
1762  always_inline, never_inline)) {
1763  if (error_on_fail_) casadi_error("Evaluation failed");
1764  }
1765  // Update offsets
1766  if (p==npar-1) break;
1767  for (casadi_int i=0; i<n_in_; ++i) if (mapped[i]) argp[i] += nnz_in(i);
1768  for (casadi_int i=0; i<n_out_; ++i) resp[i] += nnz_out(i);
1769  }
1770  }
std::vector< M > project_arg(const std::vector< M > &arg, casadi_int npar) const
Project sparsities.
const Sparsity & sparsity_out(casadi_int ind) const
Input/output sparsity.
int eval_gen(const double **arg, double **res, casadi_int *iw, double *w, void *mem, bool always_inline, bool never_inline) const
Evaluate numerically.
static Matrix< Scalar > zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
bool error_on_fail_
Throw an exception on failure?
void * memory(int ind) const
Memory objects.

References casadi::ProtoFunction::error_on_fail_, casadi::FunctionInternal::eval_gen(), casadi::get_ptr(), casadi::ProtoFunction::memory(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::project_arg(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::sparsity_out(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::GenericMatrix< Matrix< Scalar > >::zeros().

◆ call_reverse() [1/2]

void casadi::FunctionInternal::call_reverse ( const std::vector< MX > &  arg,
const std::vector< MX > &  res,
const std::vector< std::vector< MX > > &  aseed,
std::vector< std::vector< MX > > &  asens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

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

Definition at line 3381 of file function_internal.cpp.

3385  {
3386  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3387  casadi_assert(!always_inline, "Class " + class_name() +
3388  " cannot be inlined in an MX expression");
3389 
3390  // Derivative information must be available
3391  casadi_assert(has_derivative(),
3392  "Derivatives cannot be calculated for " + name_);
3393 
3394  // Number of directional derivatives
3395  casadi_int nadj = aseed.size();
3396  asens.resize(nadj);
3397 
3398  // Quick return if no seeds
3399  if (nadj==0) return;
3400 
3401  // Check if seeds need to have dimensions corrected
3402  casadi_int npar = 1;
3403  for (auto&& r : aseed) {
3404  if (!matching_res(r, npar)) {
3405  FunctionInternal::call_reverse(arg, res, replace_aseed(aseed, npar),
3406  asens, always_inline, never_inline);
3407  return;
3408  }
3409  }
3410 
3411  // Calculating full Jacobian and then multiplying likely cheaper
3412  if (adjViaJac(nadj)) {
3413  // Multiply the transposed Jacobian from the right
3414  std::vector<MX> darg = arg;
3415  darg.insert(darg.end(), res.begin(), res.end());
3416  std::vector<MX> J = jacobian()(darg);
3417  // Join adjoint seeds
3418  std::vector<MX> v(nadj), all_aseed(n_out_);
3419  for (size_t i = 0; i < n_out_; ++i) {
3420  for (size_t d = 0; d < nadj; ++d) v[d] = vec(aseed.at(d).at(i));
3421  all_aseed[i] = horzcat(v);
3422  }
3423  // Calculate adjoint sensitivities
3424  std::vector<MX> all_asens(n_in_);
3425  std::vector<MX>::const_iterator J_it = J.begin();
3426  for (size_t oind = 0; oind < n_out_; ++oind) {
3427  for (size_t iind = 0; iind < n_in_; ++iind) {
3428  // Add contribution
3429  MX a = mtimes((*J_it++).T(), all_aseed[oind]);
3430  all_asens[iind] = all_asens[iind].is_empty(true) ? a : all_asens[iind] + a;
3431  }
3432  }
3433  // Split adjoint sensitivities
3434  for (size_t d = 0; d < nadj; ++d) asens[d].resize(n_in_);
3435  for (size_t i = 0; i < n_in_; ++i) {
3436  v = horzsplit(all_asens[i]);
3437  casadi_assert_dev(v.size() == nadj);
3438  for (size_t d = 0; d < nadj; ++d) {
3439  if (asens[d][i].is_empty(true)) {
3440  asens[d][i] = reshape(v[d], size_in(i));
3441  } else {
3442  asens[d][i] += reshape(v[d], size_in(i));
3443  }
3444  }
3445  }
3446  } else {
3447  // Evaluate in batches
3448  casadi_assert_dev(enable_reverse_);
3449  casadi_int max_nadj = max_num_dir_;
3450 
3451  while (!has_reverse(max_nadj)) max_nadj/=2;
3452  casadi_int offset = 0;
3453  while (offset<nadj) {
3454  // Number of derivatives, in this batch
3455  casadi_int nadj_batch = std::min(nadj-offset, max_nadj);
3456 
3457  // All inputs and seeds
3458  std::vector<MX> darg;
3459  darg.reserve(n_in_ + n_out_ + n_out_);
3460  darg.insert(darg.end(), arg.begin(), arg.end());
3461  darg.insert(darg.end(), res.begin(), res.end());
3462  std::vector<MX> v(nadj_batch);
3463  for (casadi_int i=0; i<n_out_; ++i) {
3464  for (casadi_int d=0; d<nadj_batch; ++d) v[d] = aseed[offset+d][i];
3465  darg.push_back(horzcat(v));
3466  }
3467 
3468  // Create the evaluation node
3469  Function dfcn = self().reverse(nadj_batch);
3470  std::vector<MX> x = dfcn(darg);
3471  casadi_assert_dev(x.size()==n_in_);
3472 
3473  // Retrieve sensitivities
3474  for (casadi_int d=0; d<nadj_batch; ++d) asens[offset+d].resize(n_in_);
3475  for (casadi_int i=0; i<n_in_; ++i) {
3476  if (size2_in(i)>0) {
3477  v = horzsplit(x[i], size2_in(i));
3478  casadi_assert_dev(v.size()==nadj_batch);
3479  } else {
3480  v = std::vector<MX>(nadj_batch, MX(size_in(i)));
3481  }
3482  for (casadi_int d=0; d<nadj_batch; ++d) {
3483  if (asens[offset+d][i].is_empty(true)) {
3484  asens[offset+d][i] = v[d];
3485  } else {
3486  asens[offset+d][i] += v[d];
3487  }
3488  }
3489  }
3490  // Update offset
3491  offset += nadj_batch;
3492  }
3493  }
3494  }
virtual bool adjViaJac(casadi_int nadj) const
Calculate derivatives by multiplying the full Jacobian and multiplying.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Input/output dimensions.
virtual void call_reverse(const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
Reverse mode, virtual functions overloaded in derived classes.
Function reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
bool matching_res(const std::vector< M > &arg, casadi_int &npar) const
Check if output arguments that needs to be replaced.
virtual bool has_reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
std::vector< std::vector< M > > replace_aseed(const std::vector< std::vector< M >> &aseed, casadi_int npar) const
Replace 0-by-0 reverse seeds.

References casadi::FunctionInternal::adjViaJac(), casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_reverse(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::replace_aseed(), casadi::FunctionInternal::reverse(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size_in(), and casadi::T.

Referenced by casadi::Rootfinder::ad_reverse(), casadi::MXFunction::ad_reverse(), casadi::Call::ad_reverse(), casadi::XFunction< DerivedType, MatType, NodeType >::call_reverse(), casadi::Scpgen::init(), and casadi::MX::reverse().

◆ call_reverse() [2/2]

void casadi::FunctionInternal::call_reverse ( const std::vector< SX > &  arg,
const std::vector< SX > &  res,
const std::vector< std::vector< SX > > &  aseed,
std::vector< std::vector< SX > > &  asens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

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

Definition at line 3509 of file function_internal.cpp.

3513  {
3514  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3515  if (aseed.empty()) { // Quick return if no seeds
3516  asens.clear();
3517  return;
3518  }
3519  casadi_error("'reverse' (SX) not defined for " + class_name());
3520  }

References casadi::SharedObjectInternal::class_name().

◆ change_option()

void casadi::FmuFunction::change_option ( const std::string &  option_name,
const GenericType &  option_value 
)
overridevirtual

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

Reimplemented from casadi::ProtoFunction.

Definition at line 191 of file fmu_function.cpp.

192  {
193  if (option_name == "print_progress") {
194  print_progress_ = option_value;
195  } else if (option_name == "step") {
196  step_ = option_value;
197  } else if (option_name == "fd_method") {
198  fd_method_ = option_value.to_string();
199  fd_ = to_enum<FdMode>(fd_method_, "forward");
200  } else if (option_name == "uses_directional_derivatives") {
201  // Set, if permitted
202  bool v = option_value;
203  if (v) casadi_assert(fmu_.provides_directional_derivatives(),
204  "FMU does not provide support for analytic derivatives");
206  } else if (option_name == "uses_adjoint_derivatives") {
207  // Set, if permitted
208  bool v = option_value;
209  if (v) casadi_assert(fmu_.provides_adjoint_derivatives(),
210  "FMU does not provide support for adjoint derivatives");
212  } else if (option_name == "enable_forward_jacobian") {
213  enable_forward_jacobian_ = option_value;
214  } else if (option_name == "enable_adjoint_hessian") {
215  bool v = option_value;
216  if (v) casadi_assert(fmu_.provides_adjoint_derivatives(),
217  "FMU does not provide support for adjoint derivatives");
219  } else if (option_name == "fd_flip") {
220  fd_flip_ = option_value;
221  } else if (option_name == "make_symmetric") {
222  make_symmetric_ = option_value;
223  } else if (option_name == "hessian_coloring") {
224  bool v = option_value;
225  if (v != hessian_coloring_) {
226  casadi_assert(!hess_colors_.is_null() && !hess_uni_colors_.is_null(),
227  "Can only change Hessian coloring if both colorings are available");
228  }
229  hessian_coloring_ = v;
230  } else {
231  // Option not found - continue to base classes
232  FunctionInternal::change_option(option_name, option_value);
233  }
234 }
bool provides_adjoint_derivatives() const
Does the FMU provide support for adjoint directional derivatives.
Definition: fmu.cpp:237
bool provides_directional_derivatives() const
Does the FMU provide support for forward directional derivatives.
Definition: fmu.cpp:229
void change_option(const std::string &option_name, const GenericType &option_value) override
Change option after object creation for debugging.
bool is_null() const
Is a null pointer?

References casadi::FunctionInternal::change_option(), enable_adjoint_hessian_, enable_forward_jacobian_, fd_, fd_flip_, casadi::FunctionInternal::fd_method_, fmu_, hess_colors_, hess_uni_colors_, hessian_coloring_, casadi::GenericShared< Shared, Internal >::is_null(), make_symmetric_, print_progress_, casadi::Fmu::provides_adjoint_derivatives(), casadi::Fmu::provides_directional_derivatives(), step_, casadi::GenericType::to_string(), uses_adjoint_derivatives_, and uses_directional_derivatives_.

◆ check_arg()

template<typename M >
void casadi::FunctionInternal::check_arg ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors.

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

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

Definition at line 1773 of file function_internal.hpp.

1773  {
1774  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1775  + str(n_in_) + ", got " + str(arg.size()));
1776  for (casadi_int i=0; i<n_in_; ++i) {
1777  if (!check_mat(arg[i].sparsity(), sparsity_in(i), npar)) {
1778  // Dimensions
1779  std::string d_arg = str(arg[i].size1()) + "-by-" + str(arg[i].size2());
1780  std::string d_in = str(size1_in(i)) + "-by-" + str(size2_in(i));
1781  std::string e = "Input " + str(i) + " (" + name_in_[i] + ") has mismatching shape. "
1782  "Got " + d_arg + ". Allowed dimensions, in general, are:\n"
1783  " - The input dimension N-by-M (here " + d_in + ")\n"
1784  " - A scalar, i.e. 1-by-1\n"
1785  " - M-by-N if N=1 or M=1 (i.e. a transposed vector)\n"
1786  " - N-by-M1 if K*M1=M for some K (argument repeated horizontally)\n";
1787  if (npar!=-1) {
1788  e += " - N-by-P*M, indicating evaluation with multiple arguments (P must be a "
1789  "multiple of " + str(npar) + " for consistency with previous inputs)";
1790  }
1791  casadi_error(e);
1792  }
1793  }
1794  }
casadi_int size1_in(casadi_int ind) const
Input/output dimensions.
const Sparsity & sparsity_in(casadi_int ind) const
Input/output sparsity.
static bool check_mat(const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
std::string str(const T &v)
String representation, any type.

References casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::sparsity_in(), and casadi::str().

Referenced by casadi::FunctionInternal::mapsum_mx(), and casadi::FunctionInternal::matching_arg().

◆ check_mat()

bool casadi::FunctionInternal::check_mat ( const Sparsity &  arg,
const Sparsity &  inp,
casadi_int &  npar 
)
staticinherited

Helper function

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
npar[out]required number of parallel calls (or -1)

Definition at line 3707 of file function_internal.cpp.

3707  {
3708  // Matching dimensions
3709  if (arg.size()==inp.size()) return true;
3710  // Calling with a scalar - set all
3711  if (arg.is_scalar()) return true;
3712  // Vectors that are transposes of each other
3713  if (arg.is_vector() && inp.size()==std::make_pair(arg.size2(), arg.size1())) return true;
3714  // Horizontal repmat
3715  if (arg.size1()==inp.size1() && arg.size2()>0 && inp.size2()>0
3716  && inp.size2()%arg.size2()==0) return true;
3717  // Evaluate with multiple arguments
3718  if (npar!=-1 && arg.size1()==inp.size1() && arg.size2()>0 && inp.size2()>0
3719  && arg.size2()%(npar*inp.size2())==0) {
3720  npar *= arg.size2()/(npar*inp.size2());
3721  return true;
3722  }
3723  // Calling with empty matrix - set all to zero (after the structured branches above,
3724  // so that a 0-by-N argument can still be recognised as a parallel/repmat call)
3725  if (arg.is_empty()) return true;
3726  // No match
3727  return false;
3728  }

References casadi::Sparsity::is_empty(), casadi::Sparsity::is_scalar(), casadi::Sparsity::is_vector(), casadi::Sparsity::size(), casadi::Sparsity::size1(), and casadi::Sparsity::size2().

Referenced by casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::check_res(), and casadi::FunctionInternal::mapsum_mx().

◆ check_mem_count()

void casadi::FmuFunction::check_mem_count ( casadi_int  n) const
overridevirtual

Purpose if to allow more helpful error messages

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

Reimplemented from casadi::ProtoFunction.

Definition at line 51 of file fmu_function.cpp.

51  {
53  casadi_error("FMU '" + fmu_.instance_name() + "' [" + fmu_.class_name() + "] "
54  "declares 'canBeInstantiatedOnlyOncePerProcess' to be true. "
55  "Regenerate your FMU with this option set to false.");
56  }
57 }
bool can_be_instantiated_only_once_per_process() const
Does the FMU declare restrictions on instantiation?
Definition: fmu.cpp:245
const std::string & instance_name() const
Name of the FMU.
Definition: fmu.cpp:116
std::string class_name() const
Get class name.

References casadi::Fmu::can_be_instantiated_only_once_per_process(), casadi::SharedObject::class_name(), fmu_, and casadi::Fmu::instance_name().

◆ check_res()

template<typename M >
void casadi::FunctionInternal::check_res ( const std::vector< M > &  res,
casadi_int &  npar 
) const
inherited

Raises errors.

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

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

Definition at line 1797 of file function_internal.hpp.

1797  {
1798  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1799  + str(n_out_) + ", got " + str(res.size()));
1800  for (casadi_int i=0; i<n_out_; ++i) {
1801  casadi_assert(check_mat(res[i].sparsity(), sparsity_out(i), npar),
1802  "Output " + str(i) + " (" + name_out_[i] + ") has mismatching shape. "
1803  "Expected " + str(size_out(i)) + ", got " + str(res[i].size()));
1804  }
1805  }

References casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::size_out(), casadi::FunctionInternal::sparsity_out(), and casadi::str().

Referenced by casadi::FunctionInternal::matching_res().

◆ checkout()

int casadi::ProtoFunction::checkout ( ) const
inherited

Definition at line 3916 of file function_internal.cpp.

3916  {
3917 #ifdef CASADI_WITH_THREAD
3918  std::lock_guard<std::mutex> lock(mtx_);
3919 #endif //CASADI_WITH_THREAD
3920  if (unused_.empty()) {
3921  check_mem_count(mem_.size()+1);
3922  // Allocate a new memory object
3923  void* m = alloc_mem();
3924  mem_.push_back(m);
3925  if (init_mem(m)) {
3926  casadi_error("Failed to create or initialize memory object");
3927  }
3928  return static_cast<int>(mem_.size()) - 1;
3929  } else {
3930  // Use an unused memory object
3931  int m = unused_.top();
3932  unused_.pop();
3933  return m;
3934  }
3935  }
virtual int init_mem(void *mem) const
Initalize memory block.
virtual void * alloc_mem() const
Create memory block.
virtual void check_mem_count(casadi_int n) const
Check for validatity of memory object count.

References casadi::ProtoFunction::alloc_mem(), casadi::ProtoFunction::check_mem_count(), and casadi::ProtoFunction::init_mem().

Referenced by casadi::FunctionInternal::codegen_meta(), casadi::ProtoFunction::finalize(), and casadi::Sqpmethod::init_mem().

◆ class_name()

std::string casadi::FmuFunction::class_name ( ) const
inlineoverridevirtual

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

Implements casadi::SharedObjectInternal.

Definition at line 199 of file fmu_function.hpp.

199 { return "FmuFunction";}

◆ clear_mem()

void casadi::ProtoFunction::clear_mem ( )
inherited

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

Definition at line 3804 of file function_internal.cpp.

3804  {
3805  for (auto&& i : mem_) {
3806  if (i!=nullptr) free_mem(i);
3807  }
3808  mem_.clear();
3809  }
virtual void free_mem(void *mem) const
Free memory block.

References casadi::ProtoFunction::free_mem().

Referenced by casadi::AlpaqaInterface::~AlpaqaInterface(), casadi::AmplInterface::~AmplInterface(), casadi::BlazingSplineFunction::~BlazingSplineFunction(), casadi::Blocksqp::~Blocksqp(), casadi::BonminInterface::~BonminInterface(), casadi::BSplineInterpolant::~BSplineInterpolant(), casadi::CallbackInternal::~CallbackInternal(), casadi::CbcInterface::~CbcInterface(), casadi::ClarabelInterface::~ClarabelInterface(), casadi::ClpInterface::~ClpInterface(), casadi::ConoptInterface::~ConoptInterface(), casadi::CplexInterface::~CplexInterface(), casadi::CsparseInterface::~CsparseInterface(), casadi::CvodesInterface::~CvodesInterface(), casadi::DaqpInterface::~DaqpInterface(), casadi::External::~External(), casadi::FastNewton::~FastNewton(), casadi::FatropConicInterface::~FatropConicInterface(), casadi::FatropInterface::~FatropInterface(), casadi::Feasiblesqpmethod::~Feasiblesqpmethod(), casadi::FiniteDiff::~FiniteDiff(), casadi::FixedStepIntegrator::~FixedStepIntegrator(), ~FmuFunction(), casadi::GurobiInterface::~GurobiInterface(), casadi::HighsInterface::~HighsInterface(), casadi::HpipmInterface::~HpipmInterface(), casadi::HpmpcInterface::~HpmpcInterface(), casadi::IdasInterface::~IdasInterface(), casadi::ImplicitToNlp::~ImplicitToNlp(), casadi::IpoptInterface::~IpoptInterface(), casadi::Ipqp::~Ipqp(), casadi::JitFunction::~JitFunction(), casadi::KinsolInterface::~KinsolInterface(), casadi::KnitroInterface::~KnitroInterface(), casadi::LapackLu::~LapackLu(), casadi::LapackQr::~LapackQr(), casadi::LinearInterpolant::~LinearInterpolant(), casadi::LinearInterpolantJac::~LinearInterpolantJac(), casadi::LinsolLdl::~LinsolLdl(), casadi::LinsolQr::~LinsolQr(), casadi::LinsolTridiag::~LinsolTridiag(), casadi::Lsqr::~Lsqr(), casadi::Ma27Interface::~Ma27Interface(), casadi::MadmpecInterface::~MadmpecInterface(), casadi::MadnlpInterface::~MadnlpInterface(), casadi::Map::~Map(), casadi::MapSum::~MapSum(), casadi::MosekInterface::~MosekInterface(), casadi::MumpsInterface::~MumpsInterface(), casadi::MXFunction::~MXFunction(), casadi::Newton::~Newton(), casadi::Nlpsol::~Nlpsol(), casadi::OmpMap::~OmpMap(), casadi::OnnxFunction::~OnnxFunction(), casadi::OnnxRuntimeInterface::~OnnxRuntimeInterface(), casadi::OoqpInterface::~OoqpInterface(), casadi::OsqpInterface::~OsqpInterface(), casadi::PiqpInterface::~PiqpInterface(), casadi::ProxqpInterface::~ProxqpInterface(), casadi::QpoasesInterface::~QpoasesInterface(), casadi::QpToNlp::~QpToNlp(), casadi::Qrqp::~Qrqp(), casadi::Qrsqp::~Qrsqp(), casadi::Scpgen::~Scpgen(), casadi::SLEQPInterface::~SLEQPInterface(), casadi::SlicotDple::~SlicotDple(), casadi::SlicotExpm::~SlicotExpm(), casadi::SnoptInterface::~SnoptInterface(), casadi::Sqpmethod::~Sqpmethod(), casadi::SuperscsInterface::~SuperscsInterface(), casadi::Switch::~Switch(), casadi::SXFunction::~SXFunction(), casadi::SymbolicQr::~SymbolicQr(), casadi::ThreadMap::~ThreadMap(), casadi::UnoInterface::~UnoInterface(), casadi::WorhpInterface::~WorhpInterface(), and casadi::XpressInterface::~XpressInterface().

◆ codegen()

void casadi::FunctionInternal::codegen ( CodeGenerator &  g,
const std::string &  fname 
) const
inherited

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

Definition at line 2510 of file function_internal.cpp.

2510  {
2511  // Define function
2512  g << "/* " << definition() << " */\n";
2513  g << "static " << signature(fname) << " {\n";
2514 
2515  // Reset local variables, flush buffer
2516  g.flush(g.body);
2517 
2518  g.scope_enter();
2519 
2520  if (dump_in_ || dump_out_) {
2521  Function F = shared_from_this<Function>();
2522  std::string cg_name = codegen_name(g, false);
2523  std::string dump_counter = g.shorthand(cg_name + "_dump_counter");
2524  g.auxiliaries << "static int " << dump_counter << " = 0;\n";
2525  if (g.thread_safe()) {
2526  g.define_local_mutex(F, cg_name + "_dump_mutex");
2527  std::string dump_mutex = g.local_mutex(F, cg_name + "_dump_mutex");
2528  g << "CASADI_MUTEX_LOCK(&" << dump_mutex << ");\n";
2529  g << "int dump_id_local = " << dump_counter << "++;\n";
2530  g << "CASADI_MUTEX_UNLOCK(&" << dump_mutex << ");\n";
2531  } else {
2532  g << "int dump_id_local = " << dump_counter << "++;\n";
2533  }
2534  }
2535 
2536  if (dump_in_) g.generate_dump(shared_from_this<Function>(), "arg", true);
2537  if (print_in_) g.generate_print(shared_from_this<Function>(), "arg", true);
2538 
2539  // Generate function body (to buffer)
2540  codegen_body(g);
2541 
2542  if (dump_out_) g.generate_dump(shared_from_this<Function>(), "res", false);
2543  if (print_out_) g.generate_print(shared_from_this<Function>(), "res", false);
2544 
2545  g.scope_exit();
2546 
2547  // Finalize the function
2548  g << "return 0;\n";
2549  g << "}\n\n";
2550 
2551  // Flush to function body
2552  g.flush(g.body);
2553  }
std::string definition() const
Get function signature: name:(inputs)->(outputs)
virtual std::string codegen_name(const CodeGenerator &g, bool ns=true) const
Get name in codegen.
virtual void codegen_body(CodeGenerator &g) const
Generate code for the function body.
std::string signature(const std::string &fname) const
Code generate the function.

References casadi::CodeGenerator::auxiliaries, casadi::CodeGenerator::body, casadi::FunctionInternal::codegen_body(), casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::define_local_mutex(), casadi::FunctionInternal::definition(), casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::CodeGenerator::flush(), casadi::CodeGenerator::generate_dump(), casadi::CodeGenerator::generate_print(), casadi::CodeGenerator::local_mutex(), casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, casadi::CodeGenerator::scope_enter(), casadi::CodeGenerator::scope_exit(), casadi::CodeGenerator::shorthand(), casadi::FunctionInternal::signature(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_alloc_mem()

void casadi::FunctionInternal::codegen_alloc_mem ( CodeGenerator &  g) const
virtualinherited

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

Reimplemented in casadi::External.

Definition at line 2654 of file function_internal.cpp.

2654  {
2655  bool needs_mem = codegen_needs_mem();
2656  if (needs_mem) {
2657  std::string name = codegen_name(g, false);
2658  std::string mem_counter = g.shorthand(name + "_mem_counter");
2659  g << "return " + mem_counter + "++;\n";
2660  }
2661  }
virtual bool codegen_needs_mem() const
Is thread-local memory object needed?

References casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_needs_mem(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_body()

void casadi::FunctionInternal::codegen_body ( CodeGenerator &  g) const
virtualinherited

◆ codegen_checkout()

void casadi::FunctionInternal::codegen_checkout ( CodeGenerator &  g) const
virtualinherited

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

Reimplemented in casadi::External.

Definition at line 2663 of file function_internal.cpp.

2663  {
2664  std::string name = codegen_name(g, false);
2665  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2666  std::string stack = g.shorthand(name + "_unused_stack");
2667  std::string mem_counter = g.shorthand(name + "_mem_counter");
2668  std::string mem_array = g.shorthand(name + "_mem");
2669  std::string alloc_mem = g.shorthand(name + "_alloc_mem");
2670  std::string init_mem = g.shorthand(name + "_init_mem");
2671 
2672 
2673  g.auxiliaries << "static int " << mem_counter << " = 0;\n";
2674  g.auxiliaries << "static int " << stack_counter << " = -1;\n";
2675  g.auxiliaries << "static int " << stack << "[CASADI_MAX_NUM_THREADS];\n";
2676  g.auxiliaries << "static " << codegen_mem_type() <<
2677  " " << mem_array << "[CASADI_MAX_NUM_THREADS];\n\n";
2678 
2679  if (g.thread_safe()) {
2680  Function F = shared_from_this<Function>();
2681  g.define_local_mutex(F, name + "_mem_mutex");
2682  std::string mem_mutex = g.local_mutex(F, name + "_mem_mutex");
2683  g << "CASADI_MUTEX_LOCK(&" << mem_mutex << ");\n";
2684  g.scope_add_cleanup("CASADI_MUTEX_UNLOCK(&" + mem_mutex + ");\n");
2685  }
2686 
2687  g.local("mid", "int");
2688 
2689  g << "if (" << stack_counter << ">=0) {\n";
2690  g.scope_return(stack + "[" + stack_counter + "--]");
2691  g << "} else {\n";
2692  g << "if (" << mem_counter << "==CASADI_MAX_NUM_THREADS) {\n";
2693  g.scope_return("-1");
2694  g << "}\n";
2695  g << "mid = " << alloc_mem << "();\n";
2696  g << "if (mid<0) {\n";
2697  g.scope_return("-1");
2698  g << "}\n";
2699  g << "if (" << init_mem << "(mid)) {\n";
2700  g.scope_return("-1");
2701  g << "}\n";
2702  g.scope_return("mid");
2703  g << "}\n";
2704  }
virtual std::string codegen_mem_type() const
Thread-local memory object type.
void * alloc_mem() const override
Create memory block.

References casadi::FunctionInternal::alloc_mem(), casadi::CodeGenerator::auxiliaries, casadi::FunctionInternal::codegen_mem_type(), casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::define_local_mutex(), casadi::ProtoFunction::init_mem(), casadi::CodeGenerator::local(), casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::scope_add_cleanup(), casadi::CodeGenerator::scope_return(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_declarations()

void casadi::FunctionInternal::codegen_declarations ( CodeGenerator &  g) const
virtualinherited

◆ codegen_decref()

void casadi::FunctionInternal::codegen_decref ( CodeGenerator &  g) const
virtualinherited

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

Reimplemented in casadi::MXFunction, and casadi::External.

Definition at line 2609 of file function_internal.cpp.

2609  {
2610 
2611  // Treat dependent functions
2612  std::set<void*> added;
2613  Function F = shared_from_this<Function>();
2614  for (const Function& f : F.find_functions(0)) {
2615  if (f->has_refcount_in_deps_) {
2616  std::string cg_name = f->codegen_name(g, false);
2617  auto i = added.insert(f.get());
2618  if (i.second) { // prevent duplicate calls
2619  std::string decref = g.shorthand(cg_name + "_decref");
2620  g << decref << "();\n";
2621  }
2622  }
2623  }
2624 
2625  if (has_refcount_) {
2626  std::string name = codegen_name(g, false);
2627  std::string ref_counter = g.shorthand(name + "_ref_counter");
2628  std::string mem_counter = g.shorthand(name + "_mem_counter");
2629  std::string free_mem = g.shorthand(name + "_free_mem");
2630  g << ref_counter << "--;\n";
2631  g << "if (" << ref_counter << "==0) {\n";
2632  if (codegen_needs_mem()) {
2633  g << "while (" << mem_counter << ">0) {\n";
2634  g << free_mem << "(--" << mem_counter << ");\n";
2635  g << "}\n";
2636  }
2637  if (g.thread_safe()) {
2638  Function F = shared_from_this<Function>();
2639  for (const auto& m : g.local_mutexes(F)) {
2640  std::string mtx = g.local_mutex(F, m);
2641  g << "#if CASADI_MUTEX_USE_STATIC_INIT == 0\n";
2642  g << "CASADI_MUTEX_DESTROY(&" << mtx << ");\n";
2643  g << "#endif\n";
2644  }
2645  }
2646  g << "}\n";
2647  }
2648  }
bool has_refcount_
Reference counting in codegen?
void free_mem(void *mem) const override
Free memory block.

References casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_needs_mem(), casadi::Function::find_functions(), casadi::FunctionInternal::free_mem(), casadi::FunctionInternal::has_refcount_, casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::local_mutexes(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency(), and casadi::MXFunction::codegen_decref().

◆ codegen_free_mem()

virtual void casadi::FunctionInternal::codegen_free_mem ( CodeGenerator &  g) const
inlinevirtualinherited

◆ codegen_incref()

void casadi::FunctionInternal::codegen_incref ( CodeGenerator &  g) const
virtualinherited

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

Reimplemented in casadi::MXFunction, and casadi::External.

Definition at line 2576 of file function_internal.cpp.

2576  {
2577  if (has_refcount_) {
2578  std::string name = codegen_name(g, false);
2579  std::string ref_counter = g.shorthand(name + "_ref_counter");
2580  g.auxiliaries << "static int " << ref_counter << " = 0;\n";
2581 
2582  Function F = shared_from_this<Function>();
2583  if (g.thread_safe()) {
2584  for (const auto& m : g.local_mutexes(F)) {
2585  std::string mtx = g.local_mutex(F, m);
2586  g << "#if CASADI_MUTEX_USE_STATIC_INIT == 0\n";
2587  g << "if (" << ref_counter << "==0) CASADI_MUTEX_INIT(&" << mtx << ");\n";
2588  g << "#endif\n";
2589  }
2590  }
2591  g << ref_counter << "++;\n";
2592  }
2593 
2594  // Treat dependent functions
2595  std::set<void*> added;
2596  Function F = shared_from_this<Function>();
2597  for (const Function& f : F.find_functions(0)) {
2598  if (f->has_refcount_in_deps_) {
2599  std::string cg_name = f->codegen_name(g, false);
2600  auto i = added.insert(f.get());
2601  if (i.second) { // prevent duplicate calls
2602  std::string incref = g.shorthand(cg_name + "_incref");
2603  g << incref << "();\n";
2604  }
2605  }
2606  }
2607  }

References casadi::CodeGenerator::auxiliaries, casadi::FunctionInternal::codegen_name(), casadi::Function::find_functions(), casadi::FunctionInternal::has_refcount_, casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::local_mutexes(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency(), and casadi::MXFunction::codegen_incref().

◆ codegen_init_mem()

void casadi::FunctionInternal::codegen_init_mem ( CodeGenerator &  g) const
virtualinherited

◆ codegen_mem()

std::string casadi::FunctionInternal::codegen_mem ( CodeGenerator &  g,
const std::string &  index = "mem" 
) const
inherited

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

Definition at line 3051 of file function_internal.cpp.

3051  {
3052  std::string name = codegen_name(g, false);
3053  std::string mem_array = g.shorthand(name + "_mem");
3054  return mem_array+"[" + index + "]";
3055  }

References casadi::FunctionInternal::codegen_name(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::MadmpecInterface::codegen_body(), casadi::ClarabelInterface::codegen_body(), casadi::DaqpInterface::codegen_body(), casadi::FatropInterface::codegen_body(), casadi::HighsInterface::codegen_body(), casadi::IpoptInterface::codegen_body(), casadi::MadnlpInterface::codegen_body(), casadi::MosekInterface::codegen_body(), casadi::OsqpInterface::codegen_body(), casadi::UnoInterface::codegen_body(), casadi::XpressInterface::codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::MadmpecInterface::codegen_free_mem(), casadi::ClarabelInterface::codegen_free_mem(), casadi::DaqpInterface::codegen_free_mem(), casadi::FatropInterface::codegen_free_mem(), casadi::HighsInterface::codegen_free_mem(), casadi::IpoptInterface::codegen_free_mem(), casadi::MadnlpInterface::codegen_free_mem(), casadi::MosekInterface::codegen_free_mem(), casadi::OsqpInterface::codegen_free_mem(), casadi::UnoInterface::codegen_free_mem(), casadi::XpressInterface::codegen_free_mem(), casadi::MadmpecInterface::codegen_init_mem(), casadi::ClarabelInterface::codegen_init_mem(), casadi::DaqpInterface::codegen_init_mem(), casadi::FatropInterface::codegen_init_mem(), casadi::HighsInterface::codegen_init_mem(), casadi::IpoptInterface::codegen_init_mem(), casadi::MadnlpInterface::codegen_init_mem(), casadi::MosekInterface::codegen_init_mem(), casadi::OsqpInterface::codegen_init_mem(), casadi::UnoInterface::codegen_init_mem(), casadi::XpressInterface::codegen_init_mem(), and casadi::MadmpecInterface::codegen_options().

◆ codegen_mem_is_opaque()

virtual bool casadi::FunctionInternal::codegen_mem_is_opaque ( ) const
inlinevirtualinherited

without a need for alloc_mem, init_mem, free_mem?

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

Reimplemented in casadi::External.

Definition at line 935 of file function_internal.hpp.

935 { return false; }

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_mem_type()

virtual std::string casadi::FunctionInternal::codegen_mem_type ( ) const
inlinevirtualinherited

◆ codegen_meta()

void casadi::FunctionInternal::codegen_meta ( CodeGenerator &  g) const
inherited

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

Definition at line 2726 of file function_internal.cpp.

2726  {
2727  bool needs_mem = codegen_needs_mem();
2728  std::string name = codegen_name(g, false);
2729 
2730  // Checkout/release routines
2731  g << g.declare("int " + name_ + "_checkout(void)") << " {\n";
2732  if (needs_mem) {
2733  std::string checkout = g.shorthand(name + "_checkout");
2734  g << "return " << checkout << "();\n";
2735  } else {
2736  g << "return 0;\n";
2737  }
2738  g << "}\n\n";
2739 
2740  if (needs_mem) {
2741  g << g.declare("void " + name_ + "_release(int mem)") << " {\n";
2742  std::string release = g.shorthand(name + "_release");
2743  g << release << "(mem);\n";
2744  } else {
2745  g << g.declare("void " + name_ + "_release(int mem)") << " {\n";
2746  }
2747  g << "}\n\n";
2748 
2749  // Reference counter routines
2750  g << g.declare("void " + name_ + "_incref(void)") << " {\n";
2751  if (has_refcount_in_deps_) {
2752  std::string incref = g.shorthand(name + "_incref");
2753  g << incref << "();\n";
2754  }
2755  g << "}\n\n"
2756  << g.declare("void " + name_ + "_decref(void)") << " {\n";
2757  if (has_refcount_in_deps_) {
2758  std::string decref = g.shorthand(name + "_decref");
2759  g << decref << "();\n";
2760  }
2761  g << "}\n\n";
2762 
2763  // Number of inputs and outptus
2764  g << g.declare("casadi_int " + name_ + "_n_in(void)")
2765  << " { return " << n_in_ << ";}\n\n"
2766  << g.declare("casadi_int " + name_ + "_n_out(void)")
2767  << " { return " << n_out_ << ";}\n\n";
2768 
2769  // Default inputs
2770  g << g.declare("casadi_real " + name_ + "_default_in(casadi_int i)") << " {\n"
2771  << "switch (i) {\n";
2772  for (casadi_int i=0; i<n_in_; ++i) {
2773  double def = get_default_in(i);
2774  if (def!=0) g << "case " << i << ": return " << g.constant(def) << ";\n";
2775  }
2776  g << "default: return 0;\n}\n"
2777  << "}\n\n";
2778 
2779  // Input names
2780  g << g.declare("const char* " + name_ + "_name_in(casadi_int i)") << " {\n"
2781  << "switch (i) {\n";
2782  for (casadi_int i=0; i<n_in_; ++i) {
2783  g << "case " << i << ": return \"" << name_in_[i] << "\";\n";
2784  }
2785  g << "default: return 0;\n}\n"
2786  << "}\n\n";
2787 
2788  // Output names
2789  g << g.declare("const char* " + name_ + "_name_out(casadi_int i)") << " {\n"
2790  << "switch (i) {\n";
2791  for (casadi_int i=0; i<n_out_; ++i) {
2792  g << "case " << i << ": return \"" << name_out_[i] << "\";\n";
2793  }
2794  g << "default: return 0;\n}\n"
2795  << "}\n\n";
2796 
2797  // Codegen sparsities
2798  codegen_sparsities(g);
2799 
2800  // Function that returns work vector lengths
2801  g << g.declare(
2802  "int " + name_ + "_work(casadi_int *sz_arg, casadi_int* sz_res, "
2803  "casadi_int *sz_iw, casadi_int *sz_w)")
2804  << " {\n"
2805  << "if (sz_arg) *sz_arg = " << codegen_sz_arg(g) << ";\n"
2806  << "if (sz_res) *sz_res = " << codegen_sz_res(g) << ";\n"
2807  << "if (sz_iw) *sz_iw = " << codegen_sz_iw(g) << ";\n"
2808  << "if (sz_w) *sz_w = " << codegen_sz_w(g) << ";\n"
2809  << "return 0;\n"
2810  << "}\n\n";
2811 
2812  // Function that returns work vector lengths in bytes
2813  g << g.declare(
2814  "int " + name_ + "_work_bytes(casadi_int *sz_arg, casadi_int* sz_res, "
2815  "casadi_int *sz_iw, casadi_int *sz_w)")
2816  << " {\n"
2817  << "if (sz_arg) *sz_arg = " << codegen_sz_arg(g) << "*sizeof(const casadi_real*);\n"
2818  << "if (sz_res) *sz_res = " << codegen_sz_res(g) << "*sizeof(casadi_real*);\n"
2819  << "if (sz_iw) *sz_iw = " << codegen_sz_iw(g) << "*sizeof(casadi_int);\n"
2820  << "if (sz_w) *sz_w = " << codegen_sz_w(g) << "*sizeof(casadi_real);\n"
2821  << "return 0;\n"
2822  << "}\n\n";
2823 
2824  // Also add to header file to allow getting
2825  if (g.with_header) {
2826  g.header
2827  << "#define " << name_ << "_SZ_ARG " << codegen_sz_arg(g) << "\n"
2828  << "#define " << name_ << "_SZ_RES " << codegen_sz_res(g) << "\n"
2829  << "#define " << name_ << "_SZ_IW " << codegen_sz_iw(g) << "\n"
2830  << "#define " << name_ << "_SZ_W " << codegen_sz_w(g) << "\n";
2831  }
2832 
2833  // Which inputs are differentiable
2834  if (!all(is_diff_in_)) {
2835  g << g.declare("int " + name_ + "_diff_in(casadi_int i)") << " {\n"
2836  << "switch (i) {\n";
2837  for (casadi_int i=0; i<n_in_; ++i) {
2838  g << "case " << i << ": return " << is_diff_in_[i] << ";\n";
2839  }
2840  g << "default: return -1;\n}\n"
2841  << "}\n\n";
2842  }
2843 
2844  // Which outputs are differentiable
2845  if (!all(is_diff_out_)) {
2846  g << g.declare("int " + name_ + "_diff_out(casadi_int i)") << " {\n"
2847  << "switch (i) {\n";
2848  for (casadi_int i=0; i<n_out_; ++i) {
2849  g << "case " << i << ": return " << is_diff_out_[i] << ";\n";
2850  }
2851  g << "default: return -1;\n}\n"
2852  << "}\n\n";
2853  }
2854 
2855  // Generate mex gateway for the function
2856  if (g.mex) {
2857  // Begin conditional compilation
2858  g << "#ifdef MATLAB_MEX_FILE\n";
2859 
2860  // Declare wrapper
2861  g << "void mex_" << name_
2862  << "(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {\n"
2863  << "casadi_int i;\n";
2864  g << "int mem;\n";
2865  // Work vectors, including input and output buffers
2866  casadi_int i_nnz = nnz_in(), o_nnz = nnz_out();
2867  size_t sz_w = this->sz_w();
2868  for (casadi_int i=0; i<n_in_; ++i) {
2869  const Sparsity& s = sparsity_in_[i];
2870  sz_w = std::max(sz_w, static_cast<size_t>(s.size1())); // To be able to copy a column
2871  sz_w = std::max(sz_w, static_cast<size_t>(s.size2())); // To be able to copy a row
2872  }
2873  sz_w += i_nnz + o_nnz;
2874  g << CodeGenerator::array("casadi_real", "w", sz_w);
2875  g << CodeGenerator::array("casadi_int", "iw", sz_iw());
2876  std::string fw = "w+" + str(i_nnz + o_nnz);
2877 
2878  // Copy inputs to buffers
2879  casadi_int offset=0;
2880  g << CodeGenerator::array("const casadi_real*", "arg", sz_arg(), "{0}");
2881 
2882  // Allocate output buffers
2883  g << "casadi_real* res[" << sz_res() << "] = {0};\n";
2884 
2885  // Check arguments
2886  g << "if (argc>" << n_in_ << ") mexErrMsgIdAndTxt(\"Casadi:RuntimeError\","
2887  << "\"Evaluation of \\\"" << name_ << "\\\" failed. Too many input arguments "
2888  << "(%d, max " << n_in_ << ")\", argc);\n";
2889 
2890  g << "if (resc>" << n_out_ << ") mexErrMsgIdAndTxt(\"Casadi:RuntimeError\","
2891  << "\"Evaluation of \\\"" << name_ << "\\\" failed. "
2892  << "Too many output arguments (%d, max " << n_out_ << ")\", resc);\n";
2893 
2894  for (casadi_int i=0; i<n_in_; ++i) {
2895  std::string p = "argv[" + str(i) + "]";
2896  g << "if (--argc>=0) arg[" << i << "] = "
2897  << g.from_mex(p, "w", offset, sparsity_in_[i], fw) << "\n";
2898  offset += nnz_in(i);
2899  }
2900 
2901  for (casadi_int i=0; i<n_out_; ++i) {
2902  if (i==0) {
2903  // if i==0, always store output (possibly ans output)
2904  g << "--resc;\n";
2905  } else {
2906  // Store output, if it exists
2907  g << "if (--resc>=0) ";
2908  }
2909  // Create and get pointer
2910  g << g.res(i) << " = w+" << str(offset) << ";\n";
2911  offset += nnz_out(i);
2912  }
2913  g << name_ << "_incref();\n";
2914  g << "mem = " << name_ << "_checkout();\n";
2915 
2916  // Call the function
2917  g << "i = " << name_ << "(arg, res, iw, " << fw << ", mem);\n"
2918  << "if (i) mexErrMsgIdAndTxt(\"Casadi:RuntimeError\",\"Evaluation of \\\"" << name_
2919  << "\\\" failed.\");\n";
2920  g << name_ << "_release(mem);\n";
2921  g << name_ << "_decref();\n";
2922 
2923  // Save results
2924  for (casadi_int i=0; i<n_out_; ++i) {
2925  g << "if (" << g.res(i) << ") resv[" << i << "] = "
2926  << g.to_mex(sparsity_out_[i], g.res(i)) << "\n";
2927  }
2928 
2929  // End conditional compilation and function
2930  g << "}\n"
2931  << "#endif\n\n";
2932  }
2933 
2934  if (g.main) {
2935  // Declare wrapper
2936  g << "casadi_int main_" << name_ << "(casadi_int argc, char* argv[]) {\n";
2937 
2938  g << "casadi_int j;\n";
2939  g << "casadi_real* a;\n";
2940  g << "const casadi_real* r;\n";
2941  g << "casadi_int flag;\n";
2942  if (needs_mem) g << "int mem;\n";
2943 
2944 
2945 
2946  // Work vectors and input and output buffers
2947  size_t nr = sz_w() + nnz_in() + nnz_out();
2948  g << CodeGenerator::array("casadi_int", "iw", sz_iw())
2949  << CodeGenerator::array("casadi_real", "w", nr);
2950 
2951  // Input buffers
2952  g << "const casadi_real* arg[" << sz_arg() << "];\n";
2953 
2954  // Output buffers
2955  g << "casadi_real* res[" << sz_res() << "];\n";
2956 
2957  casadi_int off=0;
2958  for (casadi_int i=0; i<n_in_; ++i) {
2959  g << "arg[" << i << "] = w+" << off << ";\n";
2960  off += nnz_in(i);
2961  }
2962  for (casadi_int i=0; i<n_out_; ++i) {
2963  g << "res[" << i << "] = w+" << off << ";\n";
2964  off += nnz_out(i);
2965  }
2966 
2967  // TODO(@jaeandersson): Read inputs from file. For now; read from stdin
2968  g << "a = w;\n"
2969  << "for (j=0; j<" << nnz_in() << "; ++j) "
2970  << "if (scanf(\"%lg\", a++)<=0) return 2;\n";
2971 
2972  if (has_refcount_in_deps_) {
2973  g << name_ << "_incref();\n";
2974  }
2975 
2976  if (needs_mem) {
2977  g << "mem = " << name_ << "_checkout();\n";
2978  }
2979 
2980  // Call the function
2981  g << "flag = " << name_ << "(arg, res, iw, w+" << off << ", ";
2982  if (needs_mem) {
2983  g << "mem";
2984  } else {
2985  g << "0";
2986  }
2987  g << ");\n";
2988  if (needs_mem) {
2989  g << name_ << "_release(mem);\n";
2990  }
2991 
2992  if (has_refcount_in_deps_) {
2993  g << name_ << "_decref();\n";
2994  }
2995 
2996  g << "if (flag) return flag;\n";
2997 
2998  // TODO(@jaeandersson): Write outputs to file. For now: print to stdout
2999  g << "r = w+" << nnz_in() << ";\n"
3000  << "for (j=0; j<" << nnz_out() << "; ++j) "
3001  << g.printf("%.16e ", "*r++") << "\n";
3002 
3003  // End with newline
3004  g << g.printf("\\n") << "\n";
3005 
3006  // Finalize function
3007  g << "return 0;\n"
3008  << "}\n\n";
3009  }
3010 
3011  if (g.with_mem) {
3012  // Allocate memory
3013  g << g.declare("casadi_functions* " + name_ + "_functions(void)") << " {\n"
3014  << "static casadi_functions fun = {\n"
3015  << name_ << "_incref,\n"
3016  << name_ << "_decref,\n"
3017  << name_ << "_checkout,\n"
3018  << name_ << "_release,\n"
3019  << name_ << "_default_in,\n"
3020  << name_ << "_n_in,\n"
3021  << name_ << "_n_out,\n"
3022  << name_ << "_name_in,\n"
3023  << name_ << "_name_out,\n"
3024  << name_ << "_sparsity_in,\n"
3025  << name_ << "_sparsity_out,\n"
3026  << name_ << "_work,\n"
3027  << name_ << "\n"
3028  << "};\n"
3029  << "return &fun;\n"
3030  << "}\n";
3031  }
3032  // Flush
3033  g.flush(g.body);
3034  }
static std::string array(const std::string &type, const std::string &name, casadi_int len, const std::string &def=std::string())
virtual size_t codegen_sz_res(const CodeGenerator &g) const
Get required lengths, for codegen.
virtual size_t codegen_sz_arg(const CodeGenerator &g) const
Get required lengths, for codegen.
std::vector< bool > is_diff_out_
virtual size_t codegen_sz_iw(const CodeGenerator &g) const
Get required lengths, for codegen.
virtual size_t codegen_sz_w(const CodeGenerator &g) const
Get required lengths, for codegen.
bool has_refcount_in_deps_
Reference counting in dependent functions.
std::vector< bool > is_diff_in_
Are inputs and outputs differentiable?
void codegen_sparsities(CodeGenerator &g) const
Codegen sparsities.
virtual double get_default_in(casadi_int ind) const
Get default input value.
int checkout() const
Checkout a memory object.
void release(int mem) const
Release a memory object.
bool all(const std::vector< bool > &v)
Check if all arguments are true.
Definition: casadi_misc.cpp:81

References casadi::all(), casadi::CodeGenerator::array(), casadi::CodeGenerator::body, casadi::ProtoFunction::checkout(), casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_needs_mem(), casadi::FunctionInternal::codegen_sparsities(), casadi::FunctionInternal::codegen_sz_arg(), casadi::FunctionInternal::codegen_sz_iw(), casadi::FunctionInternal::codegen_sz_res(), casadi::FunctionInternal::codegen_sz_w(), casadi::CodeGenerator::constant(), casadi::CodeGenerator::declare(), casadi::CodeGenerator::flush(), casadi::CodeGenerator::from_mex(), casadi::FunctionInternal::get_default_in(), casadi::FunctionInternal::has_refcount_in_deps_, casadi::CodeGenerator::header, casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::CodeGenerator::main, casadi::CodeGenerator::mex, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::CodeGenerator::printf(), casadi::ProtoFunction::release(), casadi::CodeGenerator::res(), casadi::CodeGenerator::shorthand(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sparsity_in_, casadi::FunctionInternal::sparsity_out_, casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::CodeGenerator::to_mex(), casadi::CodeGenerator::with_header, and casadi::CodeGenerator::with_mem.

Referenced by casadi::CodeGenerator::add().

◆ codegen_name()

std::string casadi::FunctionInternal::codegen_name ( const CodeGenerator &  g,
bool  ns = true 
) const
virtualinherited

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

Definition at line 3036 of file function_internal.cpp.

3036  {
3037  if (ns) {
3038  // Get the index of the function
3039  for (auto&& e : g.added_functions_) {
3040  if (e.f.get()==this) return e.codegen_name;
3041  }
3042  } else {
3043  for (casadi_int i=0;i<g.added_functions_.size();++i) {
3044  const auto & e = g.added_functions_[i];
3045  if (e.f.get()==this) return "f" + str(i);
3046  }
3047  }
3048  casadi_error("Function '" + name_ + "' not found");
3049  }

References casadi::CodeGenerator::added_functions_, casadi::ProtoFunction::name_, and casadi::str().

Referenced by casadi::FunctionInternal::codegen(), casadi::FunctionInternal::codegen_alloc_mem(), casadi::FatropInterface::codegen_body(), casadi::FunctionInternal::codegen_checkout(), casadi::FunctionInternal::codegen_decref(), casadi::FunctionInternal::codegen_incref(), casadi::FunctionInternal::codegen_mem(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_release(), casadi::CodeGenerator::mem(), and casadi::CodeGenerator::operator()().

◆ codegen_needs_mem()

virtual bool casadi::FunctionInternal::codegen_needs_mem ( ) const
inlinevirtualinherited

◆ codegen_release()

void casadi::FunctionInternal::codegen_release ( CodeGenerator &  g) const
virtualinherited

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

Reimplemented in casadi::External.

Definition at line 2706 of file function_internal.cpp.

2706  {
2707  std::string name = codegen_name(g, false);
2708  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2709  std::string stack = g.shorthand(name + "_unused_stack");
2710 
2711  if (g.thread_safe()) {
2712  Function F = shared_from_this<Function>();
2713  std::string mem_mutex = g.local_mutex(F, name + "_mem_mutex");
2714  g << "CASADI_MUTEX_LOCK(&" << mem_mutex << ");\n";
2715  g.scope_add_cleanup("CASADI_MUTEX_UNLOCK(&" + mem_mutex + ");\n");
2716  }
2717 
2718  g << stack << "[++" << stack_counter << "] = mem;\n";
2719  g.scope_return();
2720  }

References casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::scope_add_cleanup(), casadi::CodeGenerator::scope_return(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_sparsities()

void casadi::FunctionInternal::codegen_sparsities ( CodeGenerator &  g) const
inherited

◆ codegen_sz_arg()

size_t casadi::FunctionInternal::codegen_sz_arg ( const CodeGenerator &  g) const
virtualinherited

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

Definition at line 3158 of file function_internal.cpp.

3158  {
3159  return sz_arg();
3160  }

References casadi::FunctionInternal::sz_arg().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_iw()

size_t casadi::FunctionInternal::codegen_sz_iw ( const CodeGenerator &  g) const
virtualinherited

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

Definition at line 3164 of file function_internal.cpp.

3164  {
3165  return sz_iw();
3166  }

References casadi::FunctionInternal::sz_iw().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_res()

size_t casadi::FunctionInternal::codegen_sz_res ( const CodeGenerator &  g) const
virtualinherited

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

Definition at line 3161 of file function_internal.cpp.

3161  {
3162  return sz_res();
3163  }

References casadi::FunctionInternal::sz_res().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_w()

size_t casadi::FunctionInternal::codegen_sz_w ( const CodeGenerator &  g) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3167 of file function_internal.cpp.

3167  {
3168  return sz_w();
3169  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ construct()

void casadi::ProtoFunction::construct ( const Dict &  opts)
inherited

Prepares the function for evaluation

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

Definition at line 141 of file function_internal.cpp.

141  {
142  // Sanitize dictionary is needed
143  if (!Options::is_sane(opts)) {
144  // Call recursively
146  return;
147  }
148 
149  // Make sure all options exist
150  get_options().check(opts);
151 
152  // Initialize the class hierarchy
153  try {
154  init(opts);
155  } catch(std::exception& e) {
156  casadi_error("Error calling " + class_name() + "::init for '" + name_ + "':\n"
157  + std::string(e.what()));
158  }
159 
160  // Revisit class hierarchy in reverse order
161  try {
162  finalize();
163  } catch(std::exception& e) {
164  casadi_error("Error calling " + class_name() + "::finalize for '" + name_ + "':\n"
165  + std::string(e.what()));
166  }
167  }
void construct(const Dict &opts)
Construct.
virtual const Options & get_options() const
Options.
virtual void init(const Dict &opts)
Initialize.
virtual void finalize()
Finalize the object creation.
static bool is_sane(const Dict &opts)
Is the dictionary sane.
Definition: options.cpp:169
static Dict sanitize(const Dict &opts, bool top_level=true)
Sanitize a options dictionary.
Definition: options.cpp:173
void check(const Dict &opts) const
Check if options exist.
Definition: options.cpp:240

References casadi::Options::check(), casadi::SharedObjectInternal::class_name(), casadi::ProtoFunction::finalize(), casadi::ProtoFunction::get_options(), casadi::ProtoFunction::init(), casadi::Options::is_sane(), casadi::ProtoFunction::name_, and casadi::Options::sanitize().

Referenced by casadi::Function::create(), factory(), get_forward(), get_jacobian(), casadi::LinearInterpolant::get_jacobian(), and get_reverse().

◆ convert_arg() [1/2]

template<typename M >
std::vector< M > casadi::FunctionInternal::convert_arg ( const std::map< std::string, M > &  arg) const
inherited

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

Definition at line 1899 of file function_internal.hpp.

1900  {
1901  // Get default inputs
1902  std::vector<M> arg_v(n_in_);
1903  for (casadi_int i=0; i<arg_v.size(); ++i) {
1904  arg_v[i] = get_default_in(i);
1905  }
1906 
1907  // Assign provided inputs
1908  for (auto&& e : arg) {
1909  arg_v.at(index_in(e.first)) = e.second;
1910  }
1911 
1912  return arg_v;
1913  }
casadi_int index_in(const std::string &name) const
Get input scheme index by name.

References casadi::FunctionInternal::get_default_in(), casadi::FunctionInternal::index_in(), and casadi::FunctionInternal::n_in_.

◆ convert_arg() [2/2]

template<typename M >
std::map< std::string, M > casadi::FunctionInternal::convert_arg ( const std::vector< M > &  arg) const
inherited

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

Definition at line 1887 of file function_internal.hpp.

1888  {
1889  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1890  + str(n_in_) + ", got " + str(arg.size()));
1891  std::map<std::string, M> ret;
1892  for (casadi_int i=0;i<n_in_;++i) {
1893  ret[name_in_[i]] = arg[i];
1894  }
1895  return ret;
1896  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, and casadi::str().

◆ convert_res() [1/2]

template<typename M >
std::vector< M > casadi::FunctionInternal::convert_res ( const std::map< std::string, M > &  res) const
inherited

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

Definition at line 1928 of file function_internal.hpp.

1929  {
1930  // Get default inputs
1931  std::vector<M> res_v(n_out_);
1932  for (casadi_int i=0; i<res_v.size(); ++i) {
1933  res_v[i] = std::numeric_limits<double>::quiet_NaN();
1934  }
1935 
1936  // Assign provided inputs
1937  for (auto&& e : res) {
1938  M a = e.second;
1939  res_v.at(index_out(e.first)) = a;
1940  }
1941  return res_v;
1942  }
casadi_int index_out(const std::string &name) const
Get output scheme index by name.

References casadi::FunctionInternal::index_out(), and casadi::FunctionInternal::n_out_.

◆ convert_res() [2/2]

template<typename M >
std::map< std::string, M > casadi::FunctionInternal::convert_res ( const std::vector< M > &  res) const
inherited

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

Definition at line 1916 of file function_internal.hpp.

1917  {
1918  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1919  + str(n_out_) + ", got " + str(res.size()));
1920  std::map<std::string, M> ret;
1921  for (casadi_int i=0;i<n_out_;++i) {
1922  ret[name_out_[i]] = res[i];
1923  }
1924  return ret;
1925  }

References casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_out_, and casadi::str().

◆ debug_repr()

std::string casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::debug_repr ( const Internal *  i) const
inherited

Definition at line 62 of file generic_shared_internal.hpp.

180  {
181  // Note: i != this because of something something multiple inheritance
182  return str( (casadi_int)(i)) + "/" + static_cast<const Internal*>(this)->class_name();
183  }

◆ definition()

std::string casadi::FunctionInternal::definition ( ) const
inherited

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

Definition at line 1134 of file function_internal.cpp.

1134  {
1135  std::stringstream s;
1136 
1137  // Print name
1138  s << name_ << ":(";
1139  // Print input arguments
1140  for (casadi_int i=0; i<n_in_; ++i) {
1141  if (!is_diff_in_.empty() && !is_diff_in_[i]) s << "#";
1142  s << name_in_[i] << sparsity_in_[i].postfix_dim() << (i==n_in_-1 ? "" : ",");
1143  }
1144  s << ")->(";
1145  // Print output arguments
1146  for (casadi_int i=0; i<n_out_; ++i) {
1147  if (!is_diff_out_.empty() && !is_diff_out_[i]) s << "#";
1148  s << name_out_[i] << sparsity_out_[i].postfix_dim() << (i==n_out_-1 ? "" : ",");
1149  }
1150  s << ")";
1151 
1152  return s.str();
1153  }

References casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::codegen(), casadi::FunctionInternal::disp(), casadi::MXFunction::should_inline(), and casadi::SXFunction::should_inline().

◆ deserialize()

static ProtoFunction* casadi::FmuFunction::deserialize ( DeserializingStream &  s)
inlinestatic

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

Definition at line 362 of file fmu_function.hpp.

362 { return new FmuFunction(s); }
FmuFunction(const std::string &name, const Fmu &fmu, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out)
Constructor.

◆ destroySingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::destroySingleton ( )
inlineprotectedinherited

Called in the destructor of singletons

Definition at line 77 of file generic_shared_internal.hpp.

77  {
78  static_cast<Internal*>(this)->count--;
79  }

◆ diff_prefix()

std::string casadi::FunctionInternal::diff_prefix ( const std::string &  prefix) const
inherited

Definition at line 2242 of file function_internal.cpp.

2242  {
2243  // Highest index found in current inputs and outputs
2244  casadi_int highest_index = 0;
2245  // Loop over both input names and output names
2246  for (const std::vector<std::string>& name_io : {name_in_, name_out_}) {
2247  for (const std::string& n : name_io) {
2248  // Find end of prefix, skip if no prefix
2249  size_t end = n.find('_');
2250  if (end >= n.size()) continue;
2251  // Skip if too short
2252  if (end < prefix.size()) continue;
2253  // Skip if wrong prefix
2254  if (n.compare(0, prefix.size(), prefix) != 0) continue;
2255  // Beginning of index
2256  size_t begin = prefix.size();
2257  // Check if any index
2258  casadi_int this_index;
2259  if (begin == end) {
2260  // No prefix, implicitly 1
2261  this_index = 1;
2262  } else {
2263  // Read index from string
2264  this_index = std::stoi(n.substr(begin, end - begin));
2265  }
2266  // Find the highest index
2267  if (this_index > highest_index) highest_index = this_index;
2268  }
2269  }
2270  // Return one higher index
2271  if (highest_index == 0) {
2272  return prefix + "_";
2273  } else {
2274  return prefix + std::to_string(highest_index + 1) + "_";
2275  }
2276  }

References casadi::FunctionInternal::name_in_, and casadi::FunctionInternal::name_out_.

Referenced by casadi::FunctionInternal::forward(), casadi::OnnxFunction::get_forward(), casadi::OnnxFunction::get_reverse(), casadi::OnnxFunction::has_derivative(), and casadi::FunctionInternal::reverse().

◆ disp()

void casadi::FunctionInternal::disp ( std::ostream &  stream,
bool  more 
) const
overridevirtualinherited

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

Implements casadi::SharedObjectInternal.

Definition at line 1155 of file function_internal.cpp.

1155  {
1156  stream << definition() << " " << class_name();
1157  if (more) {
1158  stream << std::endl;
1159  disp_more(stream);
1160  }
1161  }
virtual void disp_more(std::ostream &stream) const
Print more.

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::definition(), and casadi::FunctionInternal::disp_more().

Referenced by casadi::MXFunction::eval(), and casadi::SXFunction::eval().

◆ disp_more()

virtual void casadi::FunctionInternal::disp_more ( std::ostream &  stream) const
inlinevirtualinherited

◆ dm_in() [1/2]

const std::vector< DM > casadi::FunctionInternal::dm_in ( ) const
inherited

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

Definition at line 3576 of file function_internal.cpp.

3576  {
3577  std::vector<DM> ret(n_in_);
3578  for (casadi_int i=0; i<ret.size(); ++i) {
3579  ret[i] = dm_in(i);
3580  }
3581  return ret;
3582  }
const std::vector< DM > dm_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::nz_in().

◆ dm_in() [2/2]

const DM casadi::FunctionInternal::dm_in ( casadi_int  ind) const
inherited

◆ dm_out() [1/2]

const std::vector< DM > casadi::FunctionInternal::dm_out ( ) const
inherited

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

Definition at line 3584 of file function_internal.cpp.

3584  {
3585  std::vector<DM> ret(n_out_);
3586  for (casadi_int i=0; i<ret.size(); ++i) {
3587  ret[i] = dm_out(i);
3588  }
3589  return ret;
3590  }
const std::vector< DM > dm_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

Referenced by casadi::FunctionInternal::nz_out().

◆ dm_out() [2/2]

const DM casadi::FunctionInternal::dm_out ( casadi_int  ind) const
inherited

◆ ensure_stacked()

template<typename MatType >
MatType casadi::FunctionInternal::ensure_stacked ( const MatType &  v,
const Sparsity &  sp,
casadi_int  n 
)
staticinherited

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

Definition at line 1945 of file function_internal.hpp.

1945  {
1946  // Check dimensions
1947  if (v.size1() == sp.size1() && v.size2() == n * sp.size2()) {
1948  // Ensure that sparsity is a horizontal multiple of original input, or has no entries
1949  if (v.nnz() != 0 && !v.sparsity().is_stacked(sp, n)) {
1950  return project(v, repmat(sp, 1, n));
1951  }
1952  } else {
1953  // Correct empty sparsity
1954  casadi_assert_dev(v.is_empty());
1955  return MatType(sp.size1(), sp.size2() * n);
1956  }
1957  // No correction needed
1958  return v;
1959  }

References casadi::Sparsity::size1(), and casadi::Sparsity::size2().

◆ eval()

int casadi::FmuFunction::eval ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem 
) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 944 of file fmu_function.cpp.

945  {
946  // Get memory struct
947  FmuMemory* m = static_cast<FmuMemory*>(mem);
948  casadi_assert(m != nullptr, "Memory is null");
949  setup(mem, arg, res, iw, w);
950  // Reset timers
951  m->n_get_all = m->n_get_directional = m->n_get_adjoint = 0;
952  m->t_get_all = m->t_get_directional = m->t_get_adjoint = 0;
953  // What blocks are there?
954  bool need_jac = false, need_fwd = false, need_adj = false, need_hess = false;
955  for (size_t k = 0; k < out_.size(); ++k) {
956  if (res[k]) {
957  switch (out_[k].type) {
958  case OutputType::JAC:
960  need_jac = true;
961  break;
962  case OutputType::FWD:
963  need_fwd = true;
964  break;
965  case OutputType::ADJ:
966  need_adj = true;
967  break;
968  case OutputType::HESS:
969  need_adj = true;
970  need_hess = true;
971  break;
972  default:
973  break;
974  }
975  }
976  }
977  // Work vectors, shared between threads
978  double *aseed = nullptr, *asens = nullptr, *jac_nz = nullptr, *hess_nz = nullptr;
979  if (need_jac) {
980  // Jacobian nonzeros, initialize to NaN
981  jac_nz = w; w += jac_sp_.nnz();
982  std::fill(jac_nz, jac_nz + jac_sp_.nnz(), casadi::nan);
983  }
984  if (need_adj) {
985  // Set up vectors
986  aseed = w; w += nadj_ * fmu_.n_out();
987  asens = w; w += nadj_ * fmu_.n_in();
988  // Clear seed/sensitivity vectors
989  std::fill(aseed, aseed + nadj_ * fmu_.n_out(), 0);
990  std::fill(asens, asens + nadj_ * fmu_.n_in(), 0);
991  // Copy adjoint seeds to aseed
992  for (size_t i = 0; i < in_.size(); ++i) {
993  if (arg[i] && in_[i].type == InputType::ADJ) {
994  const std::vector<size_t>& oind = fmu_.ored(in_[i].ind);
995  for (casadi_int d = 0; d < nadj_; ++d) {
996  size_t aseed_off = d * fmu_.n_out();
997  size_t off = d * size1_in(i);
998  for (size_t k = 0; k < oind.size(); ++k) aseed[oind[k] + aseed_off] = arg[i][k + off];
999  }
1000  }
1001  }
1002  }
1003  if (need_hess) {
1004  // Hessian nonzeros, initialize to NaN
1005  hess_nz = w; w += hess_sp_.nnz();
1006  std::fill(hess_nz, hess_nz + hess_sp_.nnz(), casadi::nan);
1007  }
1008  // Setup memory for threads
1009  for (casadi_int task = 0; task < max_n_tasks_; ++task) {
1010  FmuMemory* s = task == 0 ? m : m->slaves.at(task - 1);
1011  // Shared memory
1012  s->arg = arg;
1013  s->res = res;
1014  s->aseed = aseed;
1015  s->asens = asens;
1016  s->jac_nz = jac_nz;
1017  s->hess_nz = hess_nz;
1018  // Thread specific memory
1019  casadi_jac_init(&jac_prob_, &s->jac_data, &iw, &w);
1020  if (task < max_hess_tasks_) {
1021  // Perturbed adjoint sensitivities
1022  s->pert_asens = w;
1023  w += fmu_.n_in();
1024  }
1026  // Memory for Jacobian calculation via adjoint mode AD
1027  casadi_jac_init(&adj_prob_, &s->adj_data, &iw, &w);
1028  }
1029  }
1030  // Evaluate everything except Hessian, possibly in parallel
1031  if (print_progress_) {
1032  casadi_message("Evaluating regular outputs, forward sens, extended Jacobian");
1033  }
1034  if (eval_all(m, max_jac_tasks_, true, need_jac, need_fwd, need_adj, false)) return 1;
1035  // Post-process Jacobian
1036  if (need_jac && !enable_forward_jacobian_) {
1037  // Copy transpose nonzeros to work vector
1038  casadi_copy(jac_nz, adj_sp_.nnz(), w);
1039  // Calculate transpose, store in jac_nz
1040  casadi_trans(w, adj_sp_, jac_nz, jac_sp_, iw);
1041  }
1042  // Evaluate Hessian
1043  if (need_hess) {
1044  if (print_progress_) casadi_message("Evaluating extended Hessian");
1045  if (eval_all(m, max_hess_tasks_, false, false, false, false, true)) return 1;
1046  // Post-process Hessian
1047  finalize_hessian(m, hess_nz, iw);
1048  }
1049  // Fetch calculated blocks
1050  for (size_t k = 0; k < out_.size(); ++k) {
1051  // Get nonzeros, skip if not needed
1052  double* r = res[k];
1053  if (!r) continue;
1054  // Get by type
1055  switch (out_[k].type) {
1056  case OutputType::JAC:
1057  casadi_get_sub(r, jac_sp_, jac_nz,
1058  out_[k].rbegin, out_[k].rend, out_[k].cbegin, out_[k].cend);
1059  break;
1060  case OutputType::JAC_TRANS:
1061  casadi_get_sub(w, jac_sp_, jac_nz,
1062  out_[k].rbegin, out_[k].rend, out_[k].cbegin, out_[k].cend);
1063  casadi_trans(w, sp_trans_[sp_trans_map_[k]], r, sparsity_out(k), iw);
1064  break;
1065  case OutputType::ADJ:
1066  // If adjoint sensitivities have not already been set
1067  for (casadi_int d = 0; d < nadj_; ++d) {
1068  size_t asens_off = d * fmu_.n_in();
1069  for (size_t id : fmu_.ired(out_[k].wrt)) *r++ = asens[id + asens_off];
1070  }
1071  break;
1072  case OutputType::HESS:
1073  casadi_get_sub(r, hess_sp_, hess_nz,
1074  out_[k].rbegin, out_[k].rend, out_[k].cbegin, out_[k].cend);
1075  break;
1076  default:
1077  break;
1078  }
1079  }
1080  // Successful return
1081  return 0;
1082 }
void finalize_hessian(FmuMemory *m, double *hess_nz, casadi_int *iw) const
int eval_all(FmuMemory *m, casadi_int n_task, bool need_nondiff, bool need_jac, bool need_fwd, bool need_adj, bool need_hess) const
const std::vector< size_t > & ored(size_t ind) const
Definition: fmu.cpp:165
size_t n_out() const
Get the number of scheme outputs.
Definition: fmu.cpp:133
const std::vector< size_t > & ired(size_t ind) const
Definition: fmu.cpp:157
size_t n_in() const
Get the number of scheme inputs.
Definition: fmu.cpp:125
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
const double nan
Not a number.
Definition: calculus.hpp:53
void casadi_trans(const T1 *x, const casadi_int *sp_x, T1 *y, const casadi_int *sp_y, casadi_int *tmp)
TRANS: y <- trans(x) , w work vector (length >= rows x)

References casadi::ADJ, casadi::FmuMemory::adj_data, adj_prob_, adj_sp_, casadi::FmuMemory::arg, casadi::FmuMemory::aseed, casadi::FmuMemory::asens, casadi::casadi_copy(), casadi::casadi_trans(), enable_adjoint_jacobian_, enable_forward_jacobian_, eval_all(), finalize_hessian(), fmu_, casadi::FWD, casadi::HESS, casadi::FmuMemory::hess_nz, hess_sp_, in_, casadi::Fmu::ired(), casadi::JAC, casadi::FmuMemory::jac_data, casadi::FmuMemory::jac_nz, jac_prob_, jac_sp_, casadi::JAC_TRANS, max_hess_tasks_, max_jac_tasks_, max_n_tasks_, casadi::FmuMemory::n_get_adjoint, casadi::FmuMemory::n_get_all, casadi::FmuMemory::n_get_directional, casadi::Fmu::n_in(), casadi::Fmu::n_out(), nadj_, casadi::nan, casadi::Sparsity::nnz(), casadi::Fmu::ored(), out_, casadi::FmuMemory::pert_asens, print_progress_, casadi::FmuMemory::res, casadi::FunctionInternal::setup(), casadi::FunctionInternal::size1_in(), casadi::FmuMemory::slaves, sp_trans_, sp_trans_map_, casadi::FunctionInternal::sparsity_out(), casadi::FmuMemory::t_get_adjoint, casadi::FmuMemory::t_get_all, and casadi::FmuMemory::t_get_directional.

◆ eval_activity()

int casadi::FunctionInternal::eval_activity ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t *  w,
void *  mem 
) const
virtualinherited

bvec bit set = active (possibly nonzero), clear = inactive (definitely zero). Unlike sp_forward (a dependency analysis), this respects multiplicative annihilation and nonzero constants. Default is the sound fallback: all active.

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3073 of file function_internal.cpp.

3074  {
3075  // Sound fallback: we cannot prove any output zero, so mark everything active
3076  for (casadi_int oind=0; oind<n_out_; ++oind) {
3077  if (res[oind]==nullptr) continue;
3078  std::fill_n(res[oind], nnz_out(oind), ~static_cast<bvec_t>(0));
3079  }
3080  return 0;
3081  }
unsigned long long bvec_t

References casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::nnz_out().

◆ eval_all()

int casadi::FmuFunction::eval_all ( FmuMemory *  m,
casadi_int  n_task,
bool  need_nondiff,
bool  need_jac,
bool  need_fwd,
bool  need_adj,
bool  need_hess 
) const

Definition at line 1084 of file fmu_function.cpp.

1085  {
1086  // Return flag
1087  int flag = 0;
1088  // Evaluate, serially or in parallel
1089  if (parallelization_ == Parallelization::SERIAL || n_task == 1
1090  || (!need_jac && !need_adj && !need_hess)) {
1091  // Evaluate serially
1092  flag = eval_task(m, 0, 1, need_nondiff, need_jac, need_fwd, need_adj, need_hess);
1093  } else if (parallelization_ == Parallelization::OPENMP) {
1094  #ifdef WITH_OPENMP
1095  // Parallel region
1096  #pragma omp parallel reduction(||:flag)
1097  {
1098  // Get thread number
1099  casadi_int task = omp_get_thread_num();
1100  // Get number of threads in region
1101  casadi_int num_threads = omp_get_num_threads();
1102  // Number of threads that are actually used
1103  casadi_int num_used_threads = std::min(num_threads, n_task);
1104  // Evaluate in parallel
1105  if (task < num_used_threads) {
1106  FmuMemory* s = task == 0 ? m : m->slaves.at(task - 1);
1107  flag = eval_task(s, task, num_used_threads, need_nondiff && task == 0,
1108  need_jac, need_fwd && task < nfwd_, need_adj, need_hess);
1109  } else {
1110  // Nothing to do for thread
1111  flag = 0;
1112  }
1113  }
1114  #else // WITH_OPENMP
1115  flag = 1;
1116  #endif // WITH_OPENMP
1117  } else if (parallelization_ == Parallelization::THREAD) {
1118  #ifdef CASADI_WITH_THREAD
1119  // Return value for each thread
1120  std::vector<int> flag_task(n_task);
1121  // Spawn threads
1122  std::vector<std::thread> threads;
1123  for (casadi_int task = 0; task < n_task; ++task) {
1124  threads.emplace_back(
1125  [&, task](int* fl) {
1126  FmuMemory* s = task == 0 ? m : m->slaves.at(task - 1);
1127  *fl = eval_task(s, task, n_task, need_nondiff && task == 0,
1128  need_jac, need_fwd && task < nfwd_, need_adj, need_hess);
1129  }, &flag_task[task]);
1130  }
1131  // Join threads
1132  for (auto&& th : threads) th.join();
1133  // Join return flags
1134  for (int fl : flag_task) flag = flag || fl;
1135  #else // CASADI_WITH_THREAD
1136  flag = 1;
1137  #endif // CASADI_WITH_THREAD
1138  } else {
1139  casadi_error("Unknown parallelization: " + to_string(parallelization_));
1140  }
1141  // Return combined error flag
1142  return flag;
1143 }
int eval_task(FmuMemory *m, casadi_int task, casadi_int n_task, bool need_nondiff, bool need_jac, bool need_fwd, bool need_adj, bool need_hess) const
std::string to_string(TypeFmi2 v)

References eval_task(), nfwd_, casadi::OPENMP, parallelization_, casadi::SERIAL, casadi::FmuMemory::slaves, casadi::THREAD, and casadi::to_string().

Referenced by eval().

◆ eval_dm()

std::vector< DM > casadi::FunctionInternal::eval_dm ( const std::vector< DM > &  arg) const
virtualinherited

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

Reimplemented in casadi::CallbackInternal.

Definition at line 2225 of file function_internal.cpp.

2225  {
2226  casadi_error("'eval_dm' not defined for " + class_name());
2227  }

References casadi::SharedObjectInternal::class_name().

Referenced by casadi::FunctionInternal::eval().

◆ eval_gen() [1/3]

int casadi::FunctionInternal::eval_gen ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t *  w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inlineinherited

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

Definition at line 448 of file function_internal.hpp.

449  {
450  return sp_forward(arg, res, iw, w, mem);
451  }
virtual int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
Propagate sparsity forward.

◆ eval_gen() [2/3]

int casadi::FunctionInternal::eval_gen ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inherited

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

Definition at line 1022 of file function_internal.cpp.

1024  {
1025  casadi_int dump_id = (dump_in_ || dump_out_ || dump_) ? get_dump_id() : -1;
1026  if (dump_in_) dump_in(dump_id, arg);
1027  if (dump_ && dump_id==0) dump();
1028  if (print_in_) print_in(uout(), arg, false);
1029  auto *m = static_cast<FunctionMemory*>(mem);
1030 
1031  // Avoid memory corruption
1032  for (casadi_int i=0;i<n_in_;++i) {
1033  casadi_assert(arg[i]==nullptr || arg[i]+nnz_in(i)<=w || arg[i]>=w+sz_w(),
1034  "Memory corruption detected for input " + name_in_[i] + ".\n"+
1035  "arg[" + str(i) + "] " + str(arg[i]) + "-" + str(arg[i]+nnz_in(i)) +
1036  " intersects with w " + str(w)+"-"+str(w+sz_w())+".");
1037  }
1038  for (casadi_int i=0;i<n_out_;++i) {
1039  casadi_assert(res[i]==nullptr || res[i]+nnz_out(i)<=w || res[i]>=w+sz_w(),
1040  "Memory corruption detected for output " + name_out_[i]);
1041  }
1042  // Reset statistics
1043  for (auto&& s : m->fstats) s.second.reset();
1044  if (m->t_total) m->t_total->tic();
1045  m->dump_id = dump_id;
1046  int ret;
1047  if (eval_) {
1048  auto *m = static_cast<FunctionMemory*>(mem);
1049  m->stats_available = true;
1050  int mem_ = 0;
1051  if (checkout_) {
1052 #ifdef CASADI_WITH_THREAD
1053  std::lock_guard<std::mutex> lock(mtx_);
1054 #endif //CASADI_WITH_THREAD
1055  mem_ = checkout_();
1056  }
1057  ret = eval_(arg, res, iw, w, mem_);
1058  if (release_) {
1059 #ifdef CASADI_WITH_THREAD
1060  std::lock_guard<std::mutex> lock(mtx_);
1061 #endif //CASADI_WITH_THREAD
1062  release_(mem_);
1063  }
1064  } else {
1065  ret = eval(arg, res, iw, w, mem);
1066  }
1067  if (m->t_total) m->t_total->toc();
1068  // Show statistics
1069  print_time(m->fstats);
1070 
1071  if (dump_out_) dump_out(dump_id, res);
1072  if (print_out_) print_out(uout(), res, false);
1073  // Check all outputs for NaNs
1074  if (regularity_check_) {
1075  for (casadi_int i = 0; i < n_out_; ++i) {
1076  // Skip of not calculated
1077  if (!res[i]) continue;
1078  // Loop over nonzeros
1079  casadi_int nnz = this->nnz_out(i);
1080  for (casadi_int nz = 0; nz < nnz; ++nz) {
1081  if (isnan(res[i][nz]) || isinf(res[i][nz])) {
1082  // Throw readable error message
1083  casadi_error(str(res[i][nz]) + " detected for output " + name_out_[i] + " at "
1084  + sparsity_out(i).repr_el(nz));
1085  }
1086  }
1087  }
1088  }
1089  return ret;
1090  }
void print_in(std::ostream &stream, const double **arg, bool truncate) const
Print inputs.
casadi_release_t release_
Release redirected to a C function.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const
Evaluate numerically.
eval_t eval_
Numerical evaluation redirected to a C function.
casadi_checkout_t checkout_
Checkout redirected to a C function.
void print_out(std::ostream &stream, double **res, bool truncate) const
Print outputs.
bool regularity_check_
Errors are thrown when NaN is produced.
void print_time(const std::map< std::string, FStats > &fstats) const
Print timing statistics.
std::ostream & uout()

References casadi::FunctionInternal::checkout_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::eval(), casadi::FunctionInternal::eval_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out(), casadi::FunctionInternal::print_out_, casadi::ProtoFunction::print_time(), casadi::ProtoFunction::regularity_check_, casadi::FunctionInternal::release_, casadi::FunctionInternal::sparsity_out(), casadi::FunctionMemory::stats_available, casadi::str(), casadi::FunctionInternal::sz_w(), and casadi::uout().

Referenced by casadi::FunctionInternal::call_gen().

◆ eval_gen() [3/3]

int casadi::FunctionInternal::eval_gen ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem *  w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inlineinherited

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

Definition at line 444 of file function_internal.hpp.

445  {
446  return eval_sx(arg, res, iw, w, mem, always_inline, never_inline);
447  }
virtual int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
Evaluate with symbolic scalars.

◆ eval_mx()

void casadi::FunctionInternal::eval_mx ( const MXVector &  arg,
MXVector &  res,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 2444 of file function_internal.cpp.

2445  {
2446 
2447  always_inline = always_inline || always_inline_;
2448  never_inline = never_inline || never_inline_;
2449 
2450  // The code below creates a call node, to inline, wrap in an MXFunction
2451  if (always_inline) {
2452  casadi_assert(!never_inline, "Inconsistent options for " + str(name_));
2453  wrap().call(arg, res, true);
2454  return;
2455  }
2456 
2457  // Create a call-node
2458  res = Call::create(self(), arg);
2459  }
static std::vector< MX > create(const Function &fcn, const std::vector< MX > &arg)
Create function call node.
Function wrap() const
Wrap in an Function instance consisting of only one MX call.
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::FunctionInternal::always_inline_, casadi::Function::call(), casadi::Call::create(), casadi::ProtoFunction::name_, casadi::FunctionInternal::never_inline_, casadi::str(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_gen(), casadi::MXFunction::eval_mx(), and casadi::SXFunction::eval_mx().

◆ eval_sx()

int casadi::FunctionInternal::eval_sx ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem *  w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

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

Reimplemented in casadi::SXFunction, casadi::Switch, casadi::MXFunction, casadi::MapSum, and casadi::Map.

Definition at line 2229 of file function_internal.cpp.

2231  {
2232 
2233  always_inline = always_inline || always_inline_;
2234  never_inline = never_inline || never_inline_;
2235 
2236  casadi_assert(!always_inline, "'eval_sx' not defined for " + class_name() +
2237  " in combination with always_inline true");
2238 
2239  return CallSX::eval_sx(self(), arg, res);
2240  }
static int eval_sx(const Function &f, const SXElem **arg, SXElem **res)
Definition: call_sx.hpp:63

References casadi::FunctionInternal::always_inline_, casadi::SharedObjectInternal::class_name(), casadi::CallSX::eval_sx(), and casadi::FunctionInternal::never_inline_.

Referenced by casadi::MXFunction::eval_sx(), and casadi::SXFunction::eval_sx().

◆ eval_task()

int casadi::FmuFunction::eval_task ( FmuMemory *  m,
casadi_int  task,
casadi_int  n_task,
bool  need_nondiff,
bool  need_jac,
bool  need_fwd,
bool  need_adj,
bool  need_hess 
) const

Definition at line 1145 of file fmu_function.cpp.

1146  {
1147  // Pass all regular inputs
1148  for (size_t k = 0; k < in_.size(); ++k) {
1149  if (in_[k].type == InputType::REG) {
1150  fmu_.set(m, in_[k].ind, m->arg[k]);
1151  }
1152  }
1153  // Request all regular outputs to be evaluated
1154  for (size_t k = 0; k < out_.size(); ++k) {
1155  if (m->res[k] && out_[k].type == OutputType::REG) {
1156  fmu_.request(m, out_[k].ind);
1157  }
1158  }
1159  // Evaluate
1160  if (fmu_.eval(m)) return 1;
1161  // Get regular outputs (master thread only)
1162  if (need_nondiff) {
1163  for (size_t k = 0; k < out_.size(); ++k) {
1164  if (m->res[k] && out_[k].type == OutputType::REG) {
1165  fmu_.get(m, out_[k].ind, m->res[k]);
1166  }
1167  }
1168  }
1169  // Forward derivatives
1170  if (need_fwd) {
1171  // Selection of forward derivatives to be evaluated for the thread
1172  casadi_int d_begin = (task * nfwd_) / n_task;
1173  casadi_int d_end = ((task + 1) * nfwd_) / n_task;
1174  // Loop over forward derivatives
1175  for (casadi_int d = d_begin; d < d_end; ++d) {
1176  // Print progress
1177  if (print_progress_) print("Forward sensitivities, thread %d/%d: Direction %d/%d\n",
1178  task + 1, n_task, d - d_begin + 1, d_end - d_begin);
1179  // Pass all forward seeds
1180  for (size_t k = 0; k < in_.size(); ++k) {
1181  if (m->arg[k] && in_[k].type == InputType::FWD) {
1182  fmu_.set_fwd(m, in_[k].ind, m->arg[k] + d * size1_in(k));
1183  }
1184  }
1185  // Request forward sensitivities
1186  for (size_t k = 0; k < out_.size(); ++k) {
1187  if (m->res[k] && out_[k].type == OutputType::FWD) {
1188  fmu_.request_fwd(m, out_[k].ind);
1189  }
1190  }
1191  // Calculate derivatives
1192  if (fmu_.eval_fwd(m, false)) return 1;
1193  // Collect forward sensitivities
1194  for (size_t k = 0; k < out_.size(); ++k) {
1195  if (m->res[k] && out_[k].type == OutputType::FWD) {
1196  fmu_.get_fwd(m, out_[k].ind, m->res[k] + d * size1_out(k));
1197  }
1198  }
1199  }
1200  }
1201  // Evalute extended Jacobian and/or adjoint derivatives
1202  if (need_jac || (need_adj && !uses_adjoint_derivatives_)) {
1204  // Forward Jacobian calculation, possibly with coloring
1205  // Selection of colors to be evaluated for the thread
1206  casadi_int c_begin = (task * jac_colors_.size2()) / n_task;
1207  casadi_int c_end = ((task + 1) * jac_colors_.size2()) / n_task;
1208  // Loop over colors
1209  for (casadi_int c = c_begin; c < c_end; ++c) {
1210  // Print progress
1211  if (print_progress_) print("Jacobian calculation, thread %d/%d: Seeding variable %d/%d\n",
1212  task + 1, n_task, c - c_begin + 1, c_end - c_begin);
1213  // Get derivative directions
1214  casadi_jac_pre(&jac_prob_, &m->jac_data, c);
1215  // Calculate derivatives
1216  fmu_.set_fwd(m, m->jac_data.nseed, m->jac_data.iseed, m->jac_data.seed);
1217  fmu_.request_fwd(m, m->jac_data.nsens, m->jac_data.isens, m->jac_data.wrt);
1218  if (fmu_.eval_fwd(m, true)) return 1;
1219  fmu_.get_fwd(m, m->jac_data.nsens, m->jac_data.isens, m->jac_data.sens);
1220  // Scale derivatives
1221  casadi_jac_scale(&jac_prob_, &m->jac_data);
1222  // Collect Jacobian nonzeros
1223  if (need_jac) {
1224  for (casadi_int i = 0; i < m->jac_data.nsens; ++i) {
1225  m->jac_nz[m->jac_data.nzind[i]] = m->jac_data.sens[i];
1226  }
1227  }
1228  // Propagate adjoint sensitivities
1229  if (need_adj) {
1230  for (casadi_int d = 0; d < nadj_; ++d) {
1231  size_t aseed_off = d * fmu_.n_out();
1232  size_t asens_off = d * fmu_.n_in();
1233  for (casadi_int i = 0; i < m->jac_data.nsens; ++i) {
1234  m->asens[m->jac_data.wrt[i] + asens_off] += m->aseed[m->jac_data.isens[i] + aseed_off]
1235  * m->jac_data.sens[i];
1236  }
1237  }
1238  }
1239  }
1240  } else {
1241  // Use adjoint mode
1242  casadi_assert(enable_adjoint_jacobian_, "Inconsistent options");
1243  casadi_assert(need_jac, "Inconsistent options");
1244  // Selection of colors to be evaluated for the thread
1245  casadi_int c_begin = (task * adj_colors_.size2()) / n_task;
1246  casadi_int c_end = ((task + 1) * adj_colors_.size2()) / n_task;
1247  // Loop over colors
1248  for (casadi_int c = c_begin; c < c_end; ++c) {
1249  // Print progress
1250  if (print_progress_) print("Jacobian calculation via adjoint mode, thread %d/%d: "
1251  "Seeding variable %d/%d\n", task + 1, n_task, c - c_begin + 1, c_end - c_begin);
1252  // Get derivative directions
1253  casadi_jac_pre(&adj_prob_, &m->adj_data, c);
1254  // Calculate derivatives
1255  fmu_.set_adj(m, m->adj_data.nseed, m->adj_data.iseed, m->adj_data.seed);
1256  fmu_.request_adj(m, m->adj_data.nsens, m->adj_data.isens, m->adj_data.wrt);
1257  if (fmu_.eval_adj(m)) return 1;
1258  fmu_.get_adj(m, m->adj_data.nsens, m->adj_data.isens, m->adj_data.sens);
1259  // Scale derivatives
1260  // casadi_jac_scale(&adj_prob_, &m->adj_data); // can be skipped since factors are 1
1261  // Collect Jacobian nonzeros
1262  for (casadi_int i = 0; i < m->adj_data.nsens; ++i) {
1263  m->jac_nz[m->adj_data.nzind[i]] = m->adj_data.sens[i];
1264  }
1265  }
1266  }
1267  } else if (need_adj) { // Adjoint derivatives, without forming the extended Jacobian
1268  // Selection of forward derivatives to be evaluated for the thread
1269  casadi_int d_begin = (task * nadj_) / n_task;
1270  casadi_int d_end = ((task + 1) * nadj_) / n_task;
1271  // Loop over forward derivatives
1272  for (casadi_int d = d_begin; d < d_end; ++d) {
1273  // Print progress
1274  if (print_progress_) print("Adjoint sensitivities, thread %d/%d: Direction %d/%d\n",
1275  task + 1, n_task, d - d_begin + 1, d_end - d_begin);
1276  // Pass all adjoint seeds
1277  for (size_t k = 0; k < in_.size(); ++k) {
1278  if (m->arg[k] && in_[k].type == InputType::ADJ) {
1279  fmu_.set_adj(m, in_[k].ind, m->arg[k] + d * size1_in(k));
1280  }
1281  }
1282  // Request adjoint sensitivities
1283  casadi_int wrt_id = -1;
1284  for (casadi_int id : jac_in_) {
1285  fmu_.request_adj(m, 1, &id, &wrt_id);
1286  }
1287  // Calculate derivatives
1288  if (fmu_.eval_adj(m)) return 1;
1289  // Collect adjoint sensitivities
1290  for (casadi_int id : jac_in_) {
1291  fmu_.get_adj(m, 1, &id, &m->asens[id]);
1292  }
1293  }
1294  }
1295  // Evaluate extended Hessian
1296  if (need_hess) {
1297  // Hessian coloring
1299  casadi_int n_hc = hc.size2();
1300  const casadi_int *hc_colind = hc.colind(), *hc_row = hc.row();
1301  // Hessian sparsity
1302  const casadi_int *hess_colind = hess_sp_.colind(), *hess_row = hess_sp_.row();
1303  // Selection of colors to be evaluated for the thread
1304  casadi_int c_begin = (task * n_hc) / n_task;
1305  casadi_int c_end = ((task + 1) * n_hc) / n_task;
1306  // Unperturbed values, step size
1307  std::vector<double> x, h;
1308  // Loop over colors
1309  for (casadi_int c = c_begin; c < c_end; ++c) {
1310  // Print progress
1311  if (print_progress_) print("Hessian calculation, thread %d/%d: Seeding variable %d/%d\n",
1312  task + 1, n_task, c - c_begin + 1, c_end - c_begin);
1313  // Variables being seeded
1314  casadi_int v_begin = hc_colind[c];
1315  casadi_int v_end = hc_colind[c + 1];
1316  casadi_int nv = v_end - v_begin;
1317  // Loop over variables being seeded for color
1318  x.resize(nv);
1319  h.resize(nv);
1320  for (casadi_int v = 0; v < nv; ++v) {
1321  // Corresponding input in Fmu
1322  casadi_int ind1 = hc_row[v_begin + v];
1323  casadi_int id = jac_in_.at(ind1);
1324  // Get unperturbed value
1325  x[v] = m->ibuf_.at(id);
1326  // Step size
1327  h[v] = m->self.step_ * fmu_.nominal_in(id);
1328  // Make sure that (forward) step remains in bounds
1329  if (x[v] + h[v] > fmu_.max_in(id)) {
1330  // Flip sign?
1331  if (fd_flip_ && x[v] - h[v] > fmu_.min_in(id)) {
1332  // Take reverse step instead?
1333  h[v] = -h[v];
1334  } else {
1335  // Perturbation not permitted
1336  h[v] = casadi::nan;
1337  }
1338  }
1339  // Perturb the input, unless not permitted
1340  if (!std::isnan(h[v])) {
1341  m->ibuf_.at(id) += h[v];
1342  m->imarked_.at(id) = true;
1343  // Inverse of step size
1344  h[v] = 1. / h[v];
1345  }
1346  }
1347  // Request all outputs
1348  for (size_t i : jac_out_) {
1349  m->omarked_.at(i) = true;
1350  m->wrt_.at(i) = -1;
1351  }
1352  // Calculate perturbed inputs
1353  if (fmu_.eval(m)) return 1;
1354  // Clear perturbed adjoint sensitivities
1355  std::fill(m->pert_asens, m->pert_asens + fmu_.n_in(), 0);
1356  // Calculate perturbed adjoints
1358  // Pass all adjoint seeds
1359  for (size_t k = 0; k < in_.size(); ++k) {
1360  if (m->arg[k] && in_[k].type == InputType::ADJ) {
1361  fmu_.set_adj(m, in_[k].ind, m->arg[k]);
1362  }
1363  }
1364  // Request adjoint sensitivities
1365  casadi_int wrt_id = -1;
1366  for (casadi_int id : jac_in_) {
1367  fmu_.request_adj(m, 1, &id, &wrt_id);
1368  }
1369  // Calculate derivatives
1370  if (fmu_.eval_adj(m)) return 1;
1371  // Collect adjoint sensitivities
1372  for (casadi_int id : jac_in_) {
1373  fmu_.get_adj(m, 1, &id, &m->pert_asens[id]);
1374  }
1375  } else {
1376  // Loop over colors of the Jacobian
1377  for (casadi_int c1 = 0; c1 < jac_colors_.size2(); ++c1) {
1378  // Get derivative directions
1379  casadi_jac_pre(&jac_prob_, &m->jac_data, c1);
1380  // Calculate derivatives
1381  fmu_.set_fwd(m, m->jac_data.nseed, m->jac_data.iseed, m->jac_data.seed);
1382  fmu_.request_fwd(m, m->jac_data.nsens, m->jac_data.isens, m->jac_data.wrt);
1383  if (fmu_.eval_fwd(m, true)) return 1;
1384  fmu_.get_fwd(m, m->jac_data.nsens, m->jac_data.isens, m->jac_data.sens);
1385  // Scale derivatives
1386  casadi_jac_scale(&jac_prob_, &m->jac_data);
1387  // Propagate adjoint sensitivities
1388  for (casadi_int i = 0; i < m->jac_data.nsens; ++i)
1389  m->pert_asens[m->jac_data.wrt[i]] += m->aseed[m->jac_data.isens[i]] * m->jac_data.sens[i];
1390  }
1391  }
1392  // Loop over variables being seeded for color
1393  for (casadi_int v = 0; v < nv; ++v) {
1394  // Corresponding input in Fmu
1395  casadi_int ind1 = hc_row[v_begin + v];
1396  casadi_int id = jac_in_.at(ind1);
1397  // Restore input
1398  m->ibuf_.at(id) = x[v];
1399  m->imarked_.at(id) = true;
1400  // Get column in Hessian
1401  for (casadi_int k = hess_colind[ind1]; k < hess_colind[ind1 + 1]; ++k) {
1402  // Save Hessian entry, unless not applicable to color
1403  if (!hessian_coloring_ || which_hess_color_[k] == c) {
1404  if (std::isnan(h[v])) {
1405  // Perturbation was not permitted
1406  m->hess_nz[k] = casadi::nan;
1407  } else {
1408  // Get Hessian nonzeros
1409  casadi_int id2 = jac_in_.at(hess_row[k]);
1410  m->hess_nz[k] = h[v] * (m->pert_asens[id2] - m->asens[id2]);
1411  }
1412  }
1413  }
1414  }
1415  }
1416  }
1417  // Successful return
1418  return 0;
1419 }
void set(FmuMemory *m, size_t ind, const double *value) const
Definition: fmu.cpp:287
void get_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
Definition: fmu.cpp:360
int eval_adj(FmuMemory *m) const
Definition: fmu.cpp:409
int eval_fwd(FmuMemory *m, bool independent_seeds) const
Definition: fmu.cpp:352
double nominal_in(size_t ind) const
Definition: fmu.cpp:173
void get_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
Definition: fmu.cpp:417
double max_in(size_t ind) const
Definition: fmu.cpp:197
void set_fwd(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
Definition: fmu.cpp:319
double min_in(size_t ind) const
Definition: fmu.cpp:189
FmuInternal * get() const
Definition: fmu.cpp:103
void set_adj(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
Definition: fmu.cpp:376
int eval(FmuMemory *m) const
Definition: fmu.cpp:303
void request_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
Definition: fmu.cpp:392
void request(FmuMemory *m, size_t ind) const
Definition: fmu.cpp:295
void request_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
Definition: fmu.cpp:335
casadi_int size1_out(casadi_int ind) const
Input/output dimensions.
void print(const char *fmt,...) const
C-style formatted printing during evaluation.
General sparsity class.
Definition: sparsity.hpp:106
casadi_int size2() const
Get the number of columns.
Definition: sparsity.cpp:128
const casadi_int * row() const
Get a reference to row-vector,.
Definition: sparsity.cpp:164
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
Definition: sparsity.cpp:168

References casadi::ADJ, adj_colors_, casadi::FmuMemory::adj_data, adj_prob_, casadi::FmuMemory::arg, casadi::FmuMemory::aseed, casadi::FmuMemory::asens, casadi::Sparsity::colind(), enable_adjoint_hessian_, enable_adjoint_jacobian_, enable_forward_jacobian_, casadi::Fmu::eval(), casadi::Fmu::eval_adj(), casadi::Fmu::eval_fwd(), fd_flip_, fmu_, casadi::FWD, casadi::Fmu::get(), casadi::Fmu::get_adj(), casadi::Fmu::get_fwd(), hess_colors_, casadi::FmuMemory::hess_nz, hess_sp_, hess_uni_colors_, hessian_coloring_, casadi::FmuMemory::ibuf_, casadi::FmuMemory::imarked_, in_, casadi_jac_data< T1 >::iseed, casadi_jac_data< T1 >::isens, jac_colors_, casadi::FmuMemory::jac_data, jac_in_, casadi::FmuMemory::jac_nz, jac_out_, jac_prob_, casadi::Fmu::max_in(), casadi::Fmu::min_in(), casadi::Fmu::n_in(), casadi::Fmu::n_out(), nadj_, casadi::nan, nfwd_, casadi::Fmu::nominal_in(), casadi_jac_data< T1 >::nseed, casadi_jac_data< T1 >::nsens, casadi_jac_data< T1 >::nzind, casadi::FmuMemory::omarked_, out_, casadi::FmuMemory::pert_asens, casadi::ProtoFunction::print(), print_progress_, casadi::REG, casadi::Fmu::request(), casadi::Fmu::request_adj(), casadi::Fmu::request_fwd(), casadi::FmuMemory::res, casadi::Sparsity::row(), casadi_jac_data< T1 >::seed, casadi::FmuMemory::self, casadi_jac_data< T1 >::sens, casadi::Fmu::set(), casadi::Fmu::set_adj(), casadi::Fmu::set_fwd(), casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::Sparsity::size2(), step_, uses_adjoint_derivatives_, which_hess_color_, casadi_jac_data< T1 >::wrt, and casadi::FmuMemory::wrt_.

Referenced by eval_all().

◆ export_code()

void casadi::FunctionInternal::export_code ( const std::string &  lang,
std::ostream &  stream,
const Dict &  options 
) const
virtualinherited

◆ factory()

Function casadi::FmuFunction::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
overridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 1558 of file fmu_function.cpp.

1562  {
1563  // Assume we can call constructor directly
1564  try {
1565  // Hack: Inherit parallelization, verbosity option
1566  Dict opts1 = opts;
1567  opts1["parallelization"] = to_string(parallelization_);
1568  opts1["verbose"] = verbose_;
1569  opts1["print_progress"] = print_progress_;
1570  // Replace ':' with '_' in s_in and s_out
1571  std::vector<std::string> s_in_mod = s_in, s_out_mod = s_out;
1572  for (std::string& s : s_in_mod) std::replace(s.begin(), s.end(), ':', '_');
1573  for (std::string& s : s_out_mod) std::replace(s.begin(), s.end(), ':', '_');
1574  // New instance of the same class, using the same Fmu instance
1575  Function ret;
1576  ret.own(new FmuFunction(name, fmu_, s_in_mod, s_out_mod));
1577  ret->construct(opts1);
1578  return ret;
1579  } catch (std::exception& e) {
1580  casadi_warning("FmuFunction::factory call for constructing " + name + " from " + name_
1581  + " failed:\n" + std::string(e.what()) + "\nFalling back to base class implementation");
1582  }
1583  // Fall back to base class
1584  return FunctionInternal::factory(name, s_in, s_out, aux, opts);
1585 }
virtual Function 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
bool verbose_
Verbose printout.

References casadi::ProtoFunction::construct(), casadi::FunctionInternal::factory(), fmu_, FmuFunction(), casadi::ProtoFunction::name_, casadi::GenericShared< Shared, Internal >::own(), parallelization_, print_progress_, casadi::to_string(), and casadi::ProtoFunction::verbose_.

◆ finalize()

void casadi::FunctionInternal::finalize ( )
overridevirtualinherited

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

Reimplemented from casadi::ProtoFunction.

Reimplemented in casadi::PiqpInterface, and casadi::OracleFunction.

Definition at line 732 of file function_internal.cpp.

732  {
733  if (codegen_needs_mem()) has_refcount_ = true;
734  if (dump_in_ || dump_out_) has_refcount_ = true;
735 
737 
738  // Does any embedded function have reference counting for codegen?
739  for (const Function& f : shared_from_this<Function>().find_functions(0)) {
740  if (f->has_refcount_in_deps_) {
741  has_refcount_in_deps_ = true;
742  break;
743  }
744  }
745 
746  if (jit_) {
749  if (jit_temp_suffix_) {
751  jit_name_ = std::string(jit_name_.begin()+jit_directory_.size(),
752  jit_name_.begin()+jit_name_.size()-2);
753  }
754  if (has_codegen()) {
755  if (compiler_.is_null()) {
756  if (verbose_) casadi_message("Codegenerating function '" + name_ + "'.");
757  // JIT everything
758  Dict opts;
759  // Override the default to avoid random strings in the generated code
760  opts["prefix"] = "jit";
761  CodeGenerator gen(jit_name_, opts);
762  gen.add(self());
763  if (verbose_) casadi_message("Compiling function '" + name_ + "'..");
764  compiler_ = Importer(gen.generate(jit_directory_), compiler_plugin_, jit_options_);
765  if (verbose_) casadi_message("Compiling function '" + name_ + "' done.");
766  }
767  // Try to load
771  incref_ = (signal_t) compiler_.get_function(name_ + "_incref");
772  decref_ = (signal_t) compiler_.get_function(name_ + "_decref");
773  casadi_assert(eval_!=nullptr, "Cannot load JIT'ed function.");
774  if (incref_) incref_();
775  } else {
776  // Just jit dependencies
778  }
779  }
780 
781  // Finalize base classes
783 
784  // Dump if requested
785  if (dump_) dump();
786  }
virtual void jit_dependencies(const std::string &fname)
Jit dependencies.
std::string jit_name_
Name if jit source file.
std::string compiler_plugin_
Just-in-time compiler.
static std::string get_jit_directory(const Dict &jit_options)
Get JIT directory from options.
bool jit_
Use just-in-time compiler.
bool jit_temp_suffix_
Use a temporary name.
signal_t incref_
Incref/decref redirected to C functions.
virtual bool has_codegen() const
Is codegen supported?
signal_t get_function(const std::string &symname)
Get a function pointer for numerical evaluation.
Definition: importer.cpp:84
int(* casadi_checkout_t)(void)
Function pointer types for the C API.
int(* eval_t)(const double **arg, double **res, casadi_int *iw, double *w, int)
Function pointer types for the C API.
void(* casadi_release_t)(int)
Function pointer types for the C API.
void(* signal_t)(void)
Function pointer types for the C API.
std::string temporary_file(const std::string &prefix, const std::string &suffix, const std::string &directory)

References casadi::CodeGenerator::add(), casadi::FunctionInternal::checkout_, casadi::FunctionInternal::codegen_needs_mem(), casadi::FunctionInternal::compiler_, casadi::FunctionInternal::compiler_plugin_, casadi::FunctionInternal::decref_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::eval_, casadi::ProtoFunction::finalize(), casadi::CodeGenerator::generate(), casadi::Importer::get_function(), casadi::FunctionInternal::get_jit_directory(), casadi::FunctionInternal::has_codegen(), casadi::FunctionInternal::has_refcount_, casadi::FunctionInternal::has_refcount_in_deps_, casadi::FunctionInternal::incref_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jit_, casadi::FunctionInternal::jit_base_name_, casadi::FunctionInternal::jit_dependencies(), casadi::FunctionInternal::jit_directory_, casadi::FunctionInternal::jit_name_, casadi::FunctionInternal::jit_options_, casadi::FunctionInternal::jit_temp_suffix_, casadi::ProtoFunction::name_, casadi::FunctionInternal::release_, casadi::temporary_file(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::deserialize(), casadi::CallbackInternal::finalize(), casadi::Conic::finalize(), and casadi::OracleFunction::finalize().

◆ finalize_hessian()

void casadi::FmuFunction::finalize_hessian ( FmuMemory *  m,
double *  hess_nz,
casadi_int *  iw 
) const

Definition at line 1421 of file fmu_function.cpp.

1421  {
1422  // Get Hessian sparsity pattern
1423  casadi_int n = hess_sp_.size1();
1424  const casadi_int *colind = hess_sp_.colind(), *row = hess_sp_.row();
1425  // Nonzero counters for transpose
1426  casadi_copy(colind, n, iw);
1427  // Loop over Hessian columns
1428  for (casadi_int c = 0; c < n; ++c) {
1429  // Loop over nonzeros for the column
1430  for (casadi_int k = colind[c]; k < colind[c + 1]; ++k) {
1431  // Get row of Hessian
1432  casadi_int r = row[k];
1433  // Get nonzero of transpose
1434  casadi_int k_tr = iw[r]++;
1435  // Only upper triangular part
1436  if (r < c) {
1437  if (hessian_coloring_) {
1438  // Star-coloring: Only half of the entries were calculated
1439  if (which_hess_color_[k] < 0) {
1440  // Use nonzero from lower triangular part
1441  hess_nz[k] = hess_nz[k_tr];
1442  } else {
1443  // Use nonzero from upper triangular part
1444  hess_nz[k_tr] = hess_nz[k];
1445  }
1446  } else {
1447  // An asymmetric Hessian was calculated, (optionally) make symmetric after (optionally)
1448  // checking symmetry
1449  if (validate_hessian_) {
1450  // Get indices
1451  casadi_int id_c = jac_in_[c], id_r = jac_in_[r];
1452  // Nonzero
1453  double nz = hess_nz[k], nz_tr = hess_nz[k_tr];
1454  // Check if entry is NaN of inf
1455  if (std::isnan(nz) || std::isinf(nz)) {
1456  std::stringstream ss;
1457  ss << "Second derivative w.r.t. " << fmu_.desc_in(m, id_r) << " and "
1458  << fmu_.desc_in(m, id_c) << " is " << nz;
1459  casadi_warning(ss.str());
1460  } else if (std::isnan(nz_tr) || std::isinf(nz_tr)) {
1461  std::stringstream ss;
1462  ss << "Second derivative w.r.t. " << fmu_.desc_in(m, id_c) << " and "
1463  << fmu_.desc_in(m, id_r) << " is " << nz_tr;
1464  casadi_warning(ss.str());
1465  } else {
1466  // Normaliation factor to be used for relative tolerance
1467  double nz_max = std::fmax(std::fabs(nz), std::fabs(nz_tr));
1468  // Check if above absolute and relative tolerance bounds
1469  if (nz_max > abstol_ && std::fabs(nz - nz_tr) > nz_max * reltol_) {
1470  std::stringstream ss;
1471  ss << "Hessian appears nonsymmetric. Got " << nz << " vs. " << nz_tr
1472  << " for second derivative w.r.t. " << fmu_.desc_in(m, id_r) << " and "
1473  << fmu_.desc_in(m, id_c) << ", hess_nz = " << k << "/" << k_tr;
1474  casadi_warning(ss.str());
1475  }
1476  }
1477  }
1478  // Make Hessian symmetric by averaging the upper and lower triangular parts
1479  if (make_symmetric_) hess_nz[k] = hess_nz[k_tr] = 0.5 * (hess_nz[k] + hess_nz[k_tr]);
1480  }
1481  }
1482  }
1483  }
1484 }
std::string desc_in(FmuMemory *m, size_t id, bool more=true) const
Definition: fmu.cpp:221
casadi_int size1() const
Get the number of rows.
Definition: sparsity.cpp:124

References abstol_, casadi::casadi_copy(), casadi::Sparsity::colind(), casadi::Fmu::desc_in(), fmu_, hess_sp_, hessian_coloring_, jac_in_, make_symmetric_, reltol_, casadi::Sparsity::row(), casadi::Sparsity::size1(), validate_hessian_, and which_hess_color_.

Referenced by eval().

◆ find()

void casadi::FunctionInternal::find ( std::map< FunctionInternal *, std::pair< Function, size_t > > &  all_fun,
casadi_int  max_depth 
) const
virtualinherited

◆ finish_trace()

void casadi::FunctionInternal::finish_trace ( std::ostream &  trace,
double **  res,
int  ret 
) const
protectedinherited

Definition at line 868 of file function_internal.cpp.

869  {
870  if (ret == 0) {
871  trace << "{\"event\":\"outputs\",\"values\":[";
872  for (casadi_int i = 0; i < n_out_; ++i) {
873  if (i) trace << ",";
874  trace_values(trace, res[i], nnz_out(i));
875  }
876  trace << "]}\n";
877  }
878  trace << "{\"event\":\"end\",\"status\":" << ret << "}\n";
879  trace.flush();
880  casadi_assert(trace.good(), "Failed to write dump_trace for '" + name_ + "'");
881  }
static void trace_values(std::ostream &trace, const double *values, casadi_int nnz)

References casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::nnz_out(), and casadi::FunctionInternal::trace_values().

Referenced by casadi::MXFunction::eval(), and casadi::SXFunction::eval().

◆ format_time()

void casadi::ProtoFunction::format_time ( char *  buffer,
double  time 
) const
inherited

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

Definition at line 4117 of file function_internal.cpp.

4117  {
4118  // Always of width 8
4119  casadi_assert_dev(time>=0);
4120  double log_time = log10(time);
4121  int magn = static_cast<int>(floor(log_time));
4122  int iprefix = static_cast<int>(floor(log_time/3));
4123  if (iprefix<-4) {
4124  sprint(buffer, 10, " 0");
4125  return;
4126  }
4127  if (iprefix>=5) {
4128  sprint(buffer, 10, " inf");
4129  return;
4130  }
4131  char prefixes[] = "TGMk munp";
4132  char prefix = prefixes[4-iprefix];
4133 
4134  int rem = magn-3*iprefix;
4135  double time_normalized = time/pow(10, 3*iprefix);
4136 
4137  if (rem==0) {
4138  sprint(buffer, 10, " %1.2f%cs", time_normalized, prefix);
4139  } else if (rem==1) {
4140  sprint(buffer, 10, " %2.2f%cs", time_normalized, prefix);
4141  } else {
4142  sprint(buffer, 10, "%3.2f%cs", time_normalized, prefix);
4143  }
4144  }
void sprint(char *buf, size_t buf_sz, const char *fmt,...) const
C-style formatted printing to string.

References casadi::ProtoFunction::sprint().

Referenced by casadi::ProtoFunction::print_time().

◆ forward()

Function casadi::FunctionInternal::forward ( casadi_int  nfwd) const
inherited

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_l0

Definition at line 2278 of file function_internal.cpp.

2278  {
2279  casadi_assert_dev(nfwd>=0);
2280  // Used wrapped function if forward not available
2281  if (!enable_forward_ && !enable_fd_) {
2282  // Derivative information must be available
2283  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2284  return wrap().forward(nfwd);
2285  }
2286  // Retrieve/generate cached
2287  Function f;
2288  std::string fname = forward_name(name_, nfwd);
2289  if (!incache(fname, f)) {
2290  casadi_int i;
2291  // Prefix to be used for forward seeds, sensitivities
2292  std::string pref = diff_prefix("fwd");
2293  // Names of inputs
2294  std::vector<std::string> inames;
2295  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2296  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2297  for (i=0; i<n_in_; ++i) inames.push_back(pref + name_in_[i]);
2298  // Names of outputs
2299  std::vector<std::string> onames;
2300  for (i=0; i<n_out_; ++i) onames.push_back(pref + name_out_[i]);
2301  // Options
2303  if (enable_forward_) {
2304  opts = combine(opts, generate_options("forward"));
2305  } else {
2306  opts = combine(opts, FunctionInternal::generate_options("forward"));
2307  }
2308  opts["derivative_of"] = self();
2309  // Generate derivative function
2310  casadi_assert_dev(enable_forward_ || enable_fd_);
2311  if (enable_forward_) {
2312  f = get_forward(nfwd, fname, inames, onames, opts);
2313  } else {
2314  opts = combine(opts, fd_options_);
2315  // Get FD method
2316  if (fd_method_.empty() || fd_method_=="central") {
2317  f = Function::create(new CentralDiff(fname, nfwd), opts);
2318  } else if (fd_method_=="forward") {
2319  f = Function::create(new ForwardDiff(fname, nfwd), opts);
2320  } else if (fd_method_=="backward") {
2321  f = Function::create(new BackwardDiff(fname, nfwd), opts);
2322  } else if (fd_method_=="smoothing") {
2323  f = Function::create(new Smoothing(fname, nfwd), opts);
2324  } else {
2325  casadi_error("Unknown 'fd_method': " + fd_method_);
2326  }
2327  }
2328  // Consistency check for inputs
2329  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_in_);
2330  casadi_int ind=0;
2331  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2332  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2333  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), nfwd*size2_in(i));
2334  // Consistency check for outputs
2335  casadi_assert_dev(f.n_out()==n_out_);
2336  for (i=0; i<n_out_; ++i) f.assert_sparsity_out(i, sparsity_out(i), nfwd);
2337  // Save to cache
2338  tocache_if_missing(f);
2339  }
2340  return f;
2341  }
std::string diff_prefix(const std::string &prefix) const
Determine prefix for differentiated functions.
void tocache_if_missing(Function &f, const std::string &suffix="") const
Save function to cache, only if missing.
static std::string forward_name(const std::string &fcn, casadi_int nfwd)
Helper function: Get name of forward derivative function.
bool incache(const std::string &fname, Function &f, const std::string &suffix="") const
Get function in cache.
Dict generate_options(const std::string &target) const override
Reconstruct options dict.
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.
Function forward(casadi_int nfwd) const
Get a function that calculates nfwd forward derivatives.
Definition: function.cpp:1324
static Function create(FunctionInternal *node)
Create from node.
Definition: function.cpp:488
Dict combine(const Dict &first, const Dict &second, bool recurse)
Combine two dicts. First has priority.

References casadi::Function::assert_size_in(), casadi::Function::assert_sparsity_out(), casadi::combine(), casadi::Function::create(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::diff_prefix(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::fd_method_, casadi::FunctionInternal::fd_options_, casadi::Function::forward(), casadi::FunctionInternal::forward_name(), casadi::FunctionInternal::forward_options_, casadi::FunctionInternal::generate_options(), casadi::FunctionInternal::get_forward(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::sparsity_out(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_forward(), and casadi::Function::forward().

◆ forward_name()

static std::string casadi::FunctionInternal::forward_name ( const std::string &  fcn,
casadi_int  nfwd 
)
inlinestaticinherited

◆ free_mem()

void casadi::FmuFunction::free_mem ( void *  mem) const
overridevirtual

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

Reimplemented from casadi::ProtoFunction.

Definition at line 91 of file fmu_function.cpp.

91  {
92  // Consistency check
93  casadi_assert(mem != nullptr, "Memory is null");
94  FmuMemory* m = static_cast<FmuMemory*>(mem);
95  // Free slave memory
96  for (FmuMemory*& s : m->slaves) {
97  if (!s) continue;
98  // Free FMU memory
99  if (s->instance) {
100  fmu_.free_instance(s->instance);
101  s->instance = nullptr;
102  }
103  // Free the slave
104  fmu_.free_mem(s);
105  }
106  // Free FMI memory
107  if (m->instance) {
108  fmu_.free_instance(m->instance);
109  m->instance = nullptr;
110  }
111  // Free the memory object
112  fmu_.free_mem(m);
113 }
void free_mem(void *mem) const
Free memory block.
Definition: fmu.cpp:99
void free_instance(void *instance) const
Definition: fmu.cpp:279

References fmu_, casadi::Fmu::free_instance(), casadi::Fmu::free_mem(), casadi::FmuMemory::instance, and casadi::FmuMemory::slaves.

◆ free_mx()

std::vector< MX > casadi::FunctionInternal::free_mx ( ) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 3624 of file function_internal.cpp.

3624  {
3625  casadi_error("'free_mx' only defined for 'MXFunction'");
3626  }

◆ free_sx()

std::vector< SX > casadi::FunctionInternal::free_sx ( ) const
virtualinherited

Reimplemented in casadi::SXFunction.

Definition at line 3628 of file function_internal.cpp.

3628  {
3629  casadi_error("'free_sx' only defined for 'SXFunction'");
3630  }

◆ from_compact()

Sparsity casadi::FunctionInternal::from_compact ( casadi_int  oind,
casadi_int  iind,
const Sparsity &  sp 
) const
inherited

Definition at line 2043 of file function_internal.cpp.

2044  {
2045  // Return value
2046  Sparsity r = sp;
2047  // Insert rows if sparse output
2048  if (numel_out(oind) != r.size1()) {
2049  casadi_assert_dev(r.size1() == nnz_out(oind));
2050  r.enlargeRows(numel_out(oind), sparsity_out(oind).find());
2051  }
2052  // Insert columns if sparse input
2053  if (numel_in(iind) != r.size2()) {
2054  casadi_assert_dev(r.size2() == nnz_in(iind));
2055  r.enlargeColumns(numel_in(iind), sparsity_in(iind).find());
2056  }
2057  // Return non-compact pattern
2058  return r;
2059  }
casadi_int numel_out() const
Number of input/output elements.
casadi_int numel_in() const
Number of input/output elements.
virtual void find(std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, casadi_int max_depth) const

References casadi::Sparsity::enlargeColumns(), casadi::Sparsity::enlargeRows(), casadi::FunctionInternal::find(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::numel_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sparsity_in(), and casadi::FunctionInternal::sparsity_out().

Referenced by casadi::FunctionInternal::jac_sparsity().

◆ fwd_seed()

template<typename MatType >
std::vector< std::vector< MatType > > casadi::FunctionInternal::fwd_seed ( casadi_int  nfwd) const
inherited

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

Definition at line 1582 of file function_internal.hpp.

1583  {
1584  std::vector<std::vector<MatType>> fseed(nfwd);
1585  for (casadi_int dir=0; dir<nfwd; ++dir) {
1586  fseed[dir].resize(n_in_);
1587  for (casadi_int iind=0; iind<n_in_; ++iind) {
1588  std::string n = "f" + str(dir) + "_" + name_in_[iind];
1589  Sparsity sp = is_diff_in_[iind] ? sparsity_in(iind) : Sparsity(size_in(iind));
1590  fseed[dir][iind] = MatType::sym(n, sp);
1591  }
1592  }
1593  return fseed;
1594  }

References casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::size_in(), casadi::FunctionInternal::sparsity_in(), and casadi::str().

◆ fwdViaJac()

bool casadi::FunctionInternal::fwdViaJac ( casadi_int  nfwd) const
virtualinherited

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

Definition at line 3239 of file function_internal.cpp.

3239  {
3240  if (!enable_forward_ && !enable_fd_) return true;
3241  if (jac_penalty_==-1) return false;
3242 
3243  // Heuristic 1: Jac calculated via forward mode likely cheaper
3244  if (jac_penalty_*static_cast<double>(nnz_in())<nfwd) return true;
3245 
3246  // Heuristic 2: Jac calculated via reverse mode likely cheaper
3247  double w = ad_weight();
3248  if (enable_reverse_ &&
3249  jac_penalty_*(1-w)*static_cast<double>(nnz_out())<w*static_cast<double>(nfwd))
3250  return true; // NOLINT
3251 
3252  return false;
3253  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::nnz_in(), and casadi::FunctionInternal::nnz_out().

Referenced by casadi::FunctionInternal::call_forward().

◆ generate_dependencies()

std::string casadi::FunctionInternal::generate_dependencies ( const std::string &  fname,
const Dict &  opts 
) const
virtualinherited

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

Reimplemented in casadi::OracleFunction.

Definition at line 3068 of file function_internal.cpp.

3069  {
3070  casadi_error("'generate_dependencies' not defined for " + class_name());
3071  }

References casadi::SharedObjectInternal::class_name().

◆ generate_in()

void casadi::FunctionInternal::generate_in ( const std::string &  fname,
const double **  arg 
) const
inherited

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

Definition at line 794 of file function_internal.cpp.

794  {
795  // Set up output stream
796  auto of_ptr = Filesystem::ofstream_ptr(fname);
797  std::ostream& of = *of_ptr;
798  normalized_setup(of);
799 
800  // Encode each input
801  for (casadi_int i=0; i<n_in_; ++i) {
802  const double* v = arg[i];
803  for (casadi_int k=0;k<nnz_in(i);++k) {
804  normalized_out(of, v ? v[k] : 0);
805  of << std::endl;
806  }
807  }
808  }
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
void normalized_setup(std::istream &stream)
void normalized_out(std::ostream &stream, double val)

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::normalized_out(), casadi::normalized_setup(), and casadi::Filesystem::ofstream_ptr().

◆ generate_lifted()

void casadi::FunctionInternal::generate_lifted ( Function &  vdef_fcn,
Function &  vinit_fcn 
) const
virtualinherited

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

Reimplemented in casadi::MXFunction.

Definition at line 3632 of file function_internal.cpp.

3633  {
3634  casadi_error("'generate_lifted' only defined for 'MXFunction'");
3635  }

◆ generate_options()

Dict casadi::FunctionInternal::generate_options ( const std::string &  target) const
overridevirtualinherited

Reimplemented from casadi::ProtoFunction.

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 389 of file function_internal.cpp.

389  {
390  Dict opts = ProtoFunction::generate_options(target);
391  opts["jac_penalty"] = jac_penalty_;
392  opts["user_data"] = user_data_;
393  opts["inputs_check"] = inputs_check_;
394  if (target!="tmp") opts["jit"] = jit_;
395  opts["jit_cleanup"] = jit_cleanup_;
396  opts["jit_serialize"] = jit_serialize_;
397  opts["compiler"] = compiler_plugin_;
398  opts["jit_options"] = jit_options_;
399  opts["jit_name"] = jit_base_name_;
400  opts["jit_temp_suffix"] = jit_temp_suffix_;
401  opts["ad_weight"] = ad_weight_;
402  opts["ad_weight_sp"] = ad_weight_sp_;
403  opts["always_inline"] = always_inline_;
404  opts["never_inline"] = never_inline_;
405  opts["max_num_dir"] = max_num_dir_;
406  if (target=="clone" || target=="tmp") {
407  opts["enable_forward"] = enable_forward_op_;
408  opts["enable_reverse"] = enable_reverse_op_;
409  opts["enable_jacobian"] = enable_jacobian_op_;
410  opts["enable_fd"] = enable_fd_op_;
411  opts["reverse_options"] = reverse_options_;
412  opts["forward_options"] = forward_options_;
413  opts["jacobian_options"] = jacobian_options_;
414  opts["der_options"] = der_options_;
415  opts["derivative_of"] = derivative_of_;
416  }
417  opts["fd_options"] = fd_options_;
418  opts["fd_method"] = fd_method_;
419  opts["print_in"] = print_in_;
420  opts["print_out"] = print_out_;
421  opts["print_canonical"] = print_canonical_;
422  opts["max_io"] = max_io_;
423  opts["dump_in"] = dump_in_;
424  opts["dump_out"] = dump_out_;
425  opts["dump_dir"] = dump_dir_;
426  opts["dump_format"] = dump_format_;
427  opts["dump"] = dump_;
428  if (target=="clone") {
429  opts["is_diff_in"] = is_diff_in_;
430  opts["is_diff_out"] = is_diff_out_;
431  }
432  if (target=="forward") {
433  opts["is_diff_in"] = join(is_diff_in_, is_diff_out_, is_diff_in_);
434  opts["is_diff_out"] = is_diff_out_;
435  }
436  if (target=="reverse") {
437  opts["is_diff_in"] = join(is_diff_in_, is_diff_out_, is_diff_out_);
438  opts["is_diff_out"] = is_diff_in_;
439  }
440  return opts;
441  }
std::string jit_serialize_
Serialize behaviour.
void * user_data_
User-set field.
bool inputs_check_
Errors are thrown if numerical values of inputs look bad.
bool jit_cleanup_
Cleanup jit source file.
Function derivative_of_
If the function is the derivative of another function.
virtual Dict generate_options(const std::string &target) const
Reconstruct options dict.
std::string join(const std::vector< std::string > &l, const std::string &delim)

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::ad_weight_sp_, casadi::FunctionInternal::always_inline_, casadi::FunctionInternal::compiler_plugin_, casadi::FunctionInternal::der_options_, casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_dir_, casadi::FunctionInternal::dump_format_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::enable_fd_op_, casadi::FunctionInternal::enable_forward_op_, casadi::FunctionInternal::enable_jacobian_op_, casadi::FunctionInternal::enable_reverse_op_, casadi::FunctionInternal::fd_method_, casadi::FunctionInternal::fd_options_, casadi::FunctionInternal::forward_options_, casadi::ProtoFunction::generate_options(), casadi::FunctionInternal::inputs_check_, casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::jacobian_options_, casadi::FunctionInternal::jit_, casadi::FunctionInternal::jit_base_name_, casadi::FunctionInternal::jit_cleanup_, casadi::FunctionInternal::jit_options_, casadi::FunctionInternal::jit_serialize_, casadi::FunctionInternal::jit_temp_suffix_, casadi::join(), casadi::FunctionInternal::max_io_, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::never_inline_, casadi::FunctionInternal::print_canonical_, casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, casadi::FunctionInternal::reverse_options_, and casadi::FunctionInternal::user_data_.

Referenced by casadi::Function::expand(), casadi::FunctionInternal::forward(), casadi::MXFunction::generate_options(), casadi::SXFunction::generate_options(), casadi::BlazingSplineFunction::get_jacobian(), and casadi::FunctionInternal::reverse().

◆ generate_out()

void casadi::FunctionInternal::generate_out ( const std::string &  fname,
double **  res 
) const
inherited

Definition at line 810 of file function_internal.cpp.

810  {
811  // Set up output stream
812  auto of_ptr = Filesystem::ofstream_ptr(fname);
813  std::ostream& of = *of_ptr;
814  normalized_setup(of);
815 
816  // Encode each input
817  for (casadi_int i=0; i<n_out_; ++i) {
818  const double* v = res[i];
819  for (casadi_int k=0;k<nnz_out(i);++k) {
820  normalized_out(of, v ? v[k] : std::numeric_limits<double>::quiet_NaN());
821  of << std::endl;
822  }
823  }
824  }

References casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::normalized_out(), casadi::normalized_setup(), and casadi::Filesystem::ofstream_ptr().

◆ get_abstol()

virtual double casadi::FunctionInternal::get_abstol ( ) const
inlinevirtualinherited

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

Reimplemented in casadi::SundialsInterface, casadi::Smoothing, casadi::CentralDiff, and casadi::ForwardDiff.

Definition at line 1135 of file function_internal.hpp.

1135  {
1136  return eps;
1137  }
const double eps
Machine epsilon.
Definition: calculus.hpp:56

References casadi::eps.

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

◆ get_default_in()

virtual double casadi::FunctionInternal::get_default_in ( casadi_int  ind) const
inlinevirtualinherited

◆ get_diff_in()

virtual bool casadi::FunctionInternal::get_diff_in ( casadi_int  i)
inlinevirtualinherited

◆ get_diff_out()

virtual bool casadi::FunctionInternal::get_diff_out ( casadi_int  i)
inlinevirtualinherited

◆ get_forward()

Function casadi::FmuFunction::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
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1617 of file fmu_function.cpp.

1620  {
1621  // Only implemented if "new_forward" is enabled
1622  if (!new_forward_) return FunctionInternal::get_forward(nfwd, name, inames, onames, opts);
1623  // Pass options
1624  Dict opts1 = opts;
1625  opts1["parallelization"] = to_string(parallelization_);
1626  opts1["verbose"] = verbose_;
1627  opts1["print_progress"] = print_progress_;
1628  opts1["nfwd"] = nfwd;
1629  // Return new instance of class
1630  Function ret;
1631  ret.own(new FmuFunction(name, fmu_, inames, onames));
1632  ret->construct(opts1);
1633  return ret;
1634 }

References casadi::ProtoFunction::construct(), fmu_, FmuFunction(), casadi::FunctionInternal::get_forward(), new_forward_, casadi::GenericShared< Shared, Internal >::own(), parallelization_, print_progress_, casadi::to_string(), and casadi::ProtoFunction::verbose_.

◆ get_free()

std::vector< std::string > casadi::FunctionInternal::get_free ( ) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 1129 of file function_internal.cpp.

1129  {
1130  casadi_assert_dev(!has_free());
1131  return std::vector<std::string>();
1132  }
virtual bool has_free() const
Does the function have free variables.

References casadi::FunctionInternal::has_free().

◆ get_function() [1/2]

std::vector< std::string > casadi::FunctionInternal::get_function ( ) const
virtualinherited

Reimplemented in casadi::SXFunction, casadi::OracleFunction, casadi::MXFunction, casadi::MapSum, and casadi::Map.

Definition at line 3953 of file function_internal.cpp.

3953  {
3954  // No functions
3955  return std::vector<std::string>();
3956  }

◆ get_function() [2/2]

const Function & casadi::FunctionInternal::get_function ( const std::string &  name) const
virtualinherited

Reimplemented in casadi::SXFunction, casadi::OracleFunction, casadi::MXFunction, casadi::MapSum, and casadi::Map.

Definition at line 3958 of file function_internal.cpp.

3958  {
3959  casadi_error("'get_function' not defined for " + class_name());
3960  static Function singleton;
3961  return singleton;
3962  }

References casadi::SharedObjectInternal::class_name().

◆ get_jac_sparsity()

Sparsity casadi::FmuFunction::get_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  symmetric 
) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1671 of file fmu_function.cpp.

1672  {
1673  // Available in the FMU meta information
1674  if (out_.at(oind).type == OutputType::REG) {
1675  if (in_.at(iind).type == InputType::REG) {
1676  return fmu_.jac_sparsity(out_.at(oind).ind, in_.at(iind).ind);
1677  } else if (in_.at(iind).type == InputType::ADJ) {
1678  return Sparsity(nnz_out(oind), nnz_in(iind));
1679  }
1680  } else if (out_.at(oind).type == OutputType::ADJ) {
1681  if (in_.at(iind).type == InputType::REG) {
1682  return fmu_.hess_sparsity(out_.at(oind).wrt, in_.at(iind).ind);
1683  } else if (in_.at(iind).type == InputType::ADJ) {
1684  return fmu_.jac_sparsity(in_.at(iind).ind, out_.at(oind).wrt).T();
1685  }
1686  }
1687  // Not available
1688  casadi_error("Implementation error");
1689  return Sparsity();
1690 }
Sparsity hess_sparsity(const std::vector< size_t > &r, const std::vector< size_t > &c) const
Definition: fmu.cpp:262
Sparsity jac_sparsity(const std::vector< size_t > &osub, const std::vector< size_t > &isub) const
Definition: fmu.cpp:253
Sparsity T() const
Transpose the matrix.
Definition: sparsity.cpp:394

References casadi::ADJ, fmu_, casadi::Fmu::hess_sparsity(), in_, casadi::Fmu::jac_sparsity(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), out_, casadi::REG, and casadi::Sparsity::T().

◆ get_jac_sparsity_gen()

template<bool fwd>
Sparsity casadi::FunctionInternal::get_jac_sparsity_gen ( casadi_int  oind,
casadi_int  iind 
) const
inherited

Definition at line 1331 of file function_internal.cpp.

1331  {
1332  // Number of nonzero inputs and outputs
1333  casadi_int nz_in = nnz_in(iind);
1334  casadi_int nz_out = nnz_out(oind);
1335 
1336  // Evaluation buffers
1337  std::vector<typename JacSparsityTraits<fwd>::arg_t> arg(sz_arg(), nullptr);
1338  std::vector<bvec_t*> res(sz_res(), nullptr);
1339  std::vector<casadi_int> iw(sz_iw());
1340  std::vector<bvec_t> w(sz_w(), 0);
1341 
1342  // Seeds and sensitivities
1343  std::vector<bvec_t> seed(nz_in, 0);
1344  arg[iind] = get_ptr(seed);
1345  std::vector<bvec_t> sens(nz_out, 0);
1346  res[oind] = get_ptr(sens);
1347  if (!fwd) std::swap(seed, sens);
1348 
1349  // Number of forward sweeps we must make
1350  casadi_int nsweep = seed.size() / bvec_size;
1351  if (seed.size() % bvec_size) nsweep++;
1352 
1353  // Print
1354  if (verbose_) {
1355  casadi_message(str(nsweep) + std::string(fwd ? " forward" : " reverse") + " sweeps "
1356  "needed for " + str(seed.size()) + " directions");
1357  }
1358 
1359  // Progress
1360  casadi_int progress = -10;
1361 
1362  // Temporary vectors
1363  std::vector<casadi_int> jcol, jrow;
1364 
1365  // Loop over the variables, bvec_size variables at a time
1366  for (casadi_int s=0; s<nsweep; ++s) {
1367 
1368  // Print progress
1369  if (verbose_) {
1370  casadi_int progress_new = (s*100)/nsweep;
1371  // Print when entering a new decade
1372  if (progress_new / 10 > progress / 10) {
1373  progress = progress_new;
1374  casadi_message(str(progress) + " %");
1375  }
1376  }
1377 
1378  // Nonzero offset
1379  casadi_int offset = s*bvec_size;
1380 
1381  // Number of local seed directions
1382  casadi_int ndir_local = seed.size()-offset;
1383  ndir_local = std::min(static_cast<casadi_int>(bvec_size), ndir_local);
1384 
1385  for (casadi_int i=0; i<ndir_local; ++i) {
1386  seed[offset+i] |= bvec_t(1)<<i;
1387  }
1388 
1389  // Propagate the dependencies
1390  JacSparsityTraits<fwd>::sp(this, get_ptr(arg), get_ptr(res),
1391  get_ptr(iw), get_ptr(w), memory(0));
1392 
1393  // Loop over the nonzeros of the output
1394  for (casadi_int el=0; el<sens.size(); ++el) {
1395 
1396  // Get the sparsity sensitivity
1397  bvec_t spsens = sens[el];
1398 
1399  if (!fwd) {
1400  // Clear the sensitivities for the next sweep
1401  sens[el] = 0;
1402  }
1403 
1404  // If there is a dependency in any of the directions
1405  if (spsens!=0) {
1406 
1407  // Loop over seed directions
1408  for (casadi_int i=0; i<ndir_local; ++i) {
1409 
1410  // If dependents on the variable
1411  if ((bvec_t(1) << i) & spsens) {
1412  // Add to pattern
1413  jcol.push_back(el);
1414  jrow.push_back(i+offset);
1415  }
1416  }
1417  }
1418  }
1419 
1420  // Remove the seeds
1421  for (casadi_int i=0; i<ndir_local; ++i) {
1422  seed[offset+i] = 0;
1423  }
1424  }
1425 
1426  // Construct sparsity pattern and return
1427  if (!fwd) swap(jrow, jcol);
1428  Sparsity ret = Sparsity::triplet(nz_out, nz_in, jcol, jrow);
1429  if (verbose_) {
1430  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(ret.size()) + ", "
1431  + str(ret.nnz()) + " (" + str(ret.density()) + " %) nonzeros.");
1432  }
1433  return ret;
1434  }
std::vector< double > nz_in(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
std::vector< double > nz_out(const std::vector< DM > &res) const
Convert from/to flat vector of input/output nonzeros.
static Sparsity triplet(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, std::vector< casadi_int > &mapping, bool invert_mapping)
Create a sparsity pattern given the nonzeros in sparse triplet form *.
Definition: sparsity.cpp:1143
const int bvec_size

References casadi::bvec_size, casadi::Sparsity::density(), casadi::get_ptr(), casadi::ProtoFunction::memory(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::Sparsity::size(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::triplet(), and casadi::ProtoFunction::verbose_.

◆ get_jac_sparsity_hierarchical()

Sparsity casadi::FunctionInternal::get_jac_sparsity_hierarchical ( casadi_int  oind,
casadi_int  iind 
) const
inherited

Decide which ad_mode to take

Definition at line 1671 of file function_internal.cpp.

1671  {
1672  // Number of nonzero inputs
1673  casadi_int nz_in = nnz_in(iind);
1674 
1675  // Number of nonzero outputs
1676  casadi_int nz_out = nnz_out(oind);
1677 
1678  // Seeds and sensitivities
1679  std::vector<bvec_t> s_in(nz_in, 0);
1680  std::vector<bvec_t> s_out(nz_out, 0);
1681 
1682  // Evaluation buffers
1683  std::vector<const bvec_t*> arg_fwd(sz_arg(), nullptr);
1684  std::vector<bvec_t*> arg_adj(sz_arg(), nullptr);
1685  arg_fwd[iind] = arg_adj[iind] = get_ptr(s_in);
1686  std::vector<bvec_t*> res(sz_res(), nullptr);
1687  res[oind] = get_ptr(s_out);
1688  std::vector<casadi_int> iw(sz_iw());
1689  std::vector<bvec_t> w(sz_w());
1690 
1691  // Sparsity triplet accumulator
1692  std::vector<casadi_int> jcol, jrow;
1693 
1694  // Cols of the coarse blocks
1695  std::vector<casadi_int> coarse_col(2, 0); coarse_col[1] = nz_out;
1696  // Rows of the coarse blocks
1697  std::vector<casadi_int> coarse_row(2, 0); coarse_row[1] = nz_in;
1698 
1699  // Cols of the fine blocks
1700  std::vector<casadi_int> fine_col;
1701 
1702  // Rows of the fine blocks
1703  std::vector<casadi_int> fine_row;
1704 
1705  // In each iteration, subdivide each coarse block in this many fine blocks
1706  casadi_int subdivision = bvec_size;
1707 
1708  Sparsity r = Sparsity::dense(1, 1);
1709 
1710  // The size of a block
1711  casadi_int granularity_row = nz_in;
1712  casadi_int granularity_col = nz_out;
1713 
1714  bool use_fwd = true;
1715 
1716  casadi_int nsweeps = 0;
1717 
1718  bool hasrun = false;
1719 
1720  // Get weighting factor
1721  double sp_w = sp_weight();
1722 
1723  // Lookup table for bvec_t
1724  std::vector<bvec_t> bvec_lookup;
1725  bvec_lookup.reserve(bvec_size);
1726  for (casadi_int i=0;i<bvec_size;++i) {
1727  bvec_lookup.push_back(bvec_t(1) << i);
1728  }
1729 
1730  while (!hasrun || coarse_col.size()!=nz_out+1 || coarse_row.size()!=nz_in+1) {
1731  if (verbose_) {
1732  casadi_message("Block size: " + str(granularity_col) + " x " + str(granularity_row));
1733  }
1734 
1735  // Clear the sparsity triplet acccumulator
1736  jcol.clear();
1737  jrow.clear();
1738 
1739  // Clear the fine block structure
1740  fine_row.clear();
1741  fine_col.clear();
1742 
1743  // r transpose will be needed in the algorithm
1744  Sparsity rT = r.T();
1745 
1748  // Forward mode
1749  Sparsity D1 = rT.uni_coloring(r);
1750  // Adjoint mode
1751  Sparsity D2 = r.uni_coloring(rT);
1752  if (verbose_) {
1753  casadi_message("Coloring on " + str(r.dim()) + " (fwd seeps: " + str(D1.size2()) +
1754  " , adj sweeps: " + str(D2.size1()) + ")");
1755  }
1756 
1757  // Use whatever required less colors if we tried both (with preference to forward mode)
1758  double fwd_cost = static_cast<double>(use_fwd ? granularity_row : granularity_col) *
1759  sp_w*static_cast<double>(D1.size2());
1760  double adj_cost = static_cast<double>(use_fwd ? granularity_col : granularity_row) *
1761  (1-sp_w)*static_cast<double>(D2.size2());
1762  use_fwd = fwd_cost <= adj_cost;
1763  if (verbose_) {
1764  casadi_message(std::string(use_fwd ? "Forward" : "Reverse") + " mode chosen "
1765  "(fwd cost: " + str(fwd_cost) + ", adj cost: " + str(adj_cost) + ")");
1766  }
1767 
1768  // Get seeds and sensitivities
1769  bvec_t* seed_v = use_fwd ? get_ptr(s_in) : get_ptr(s_out);
1770  bvec_t* sens_v = use_fwd ? get_ptr(s_out) : get_ptr(s_in);
1771 
1772  // The number of zeros in the seed and sensitivity directions
1773  casadi_int nz_seed = use_fwd ? nz_in : nz_out;
1774  casadi_int nz_sens = use_fwd ? nz_out : nz_in;
1775 
1776  // Clear the seeds
1777  for (casadi_int i=0; i<nz_seed; ++i) seed_v[i]=0;
1778 
1779  // Choose the active jacobian coloring scheme
1780  Sparsity D = use_fwd ? D1 : D2;
1781 
1782  // Adjoint mode amounts to swapping
1783  if (!use_fwd) {
1784  std::swap(coarse_col, coarse_row);
1785  std::swap(granularity_col, granularity_row);
1786  std::swap(r, rT);
1787  }
1788 
1789  // Subdivide the coarse block cols
1790  for (casadi_int k=0;k<coarse_col.size()-1;++k) {
1791  casadi_int diff = coarse_col[k+1]-coarse_col[k];
1792  casadi_int new_diff = diff/subdivision;
1793  if (diff%subdivision>0) new_diff++;
1794  std::vector<casadi_int> temp = range(coarse_col[k], coarse_col[k+1], new_diff);
1795  fine_col.insert(fine_col.end(), temp.begin(), temp.end());
1796  }
1797  // Subdivide the coarse block rows
1798  for (casadi_int k=0;k<coarse_row.size()-1;++k) {
1799  casadi_int diff = coarse_row[k+1]-coarse_row[k];
1800  casadi_int new_diff = diff/subdivision;
1801  if (diff%subdivision>0) new_diff++;
1802  std::vector<casadi_int> temp = range(coarse_row[k], coarse_row[k+1], new_diff);
1803  fine_row.insert(fine_row.end(), temp.begin(), temp.end());
1804  }
1805  if (fine_row.back()!=coarse_row.back()) fine_row.push_back(coarse_row.back());
1806  if (fine_col.back()!=coarse_col.back()) fine_col.push_back(coarse_col.back());
1807 
1808  granularity_col = fine_col[1] - fine_col[0];
1809  granularity_row = fine_row[1] - fine_row[0];
1810 
1811  // The index into the bvec bit vector
1812  casadi_int bvec_i = 0;
1813 
1814  // Create lookup tables for the fine blocks
1815  std::vector<casadi_int> fine_col_lookup = lookupvector(fine_col, nz_sens+1);
1816  std::vector<casadi_int> fine_row_lookup = lookupvector(fine_row, nz_seed+1);
1817 
1818  // Triplet data used as a lookup table
1819  std::vector<casadi_int> lookup_col;
1820  std::vector<casadi_int> lookup_row;
1821  std::vector<casadi_int> lookup_value;
1822 
1823 
1824  // The maximum number of fine blocks contained in one coarse block
1825  casadi_int n_fine_blocks_max = 0;
1826  for (casadi_int i=0;i<coarse_row.size()-1;++i) {
1827  casadi_int del = fine_row_lookup[coarse_row[i+1]]-fine_row_lookup[coarse_row[i]];
1828  n_fine_blocks_max = std::max(n_fine_blocks_max, del);
1829  }
1830 
1831  // Loop over all coarse seed directions from the coloring
1832  for (casadi_int csd=0; csd<D.size2(); ++csd) {
1833 
1834  casadi_int fci_offset = 0;
1835  casadi_int fci_cap = bvec_size-bvec_i;
1836 
1837  // Flag to indicate if all fine blocks have been handled
1838  bool f_finished = false;
1839 
1840  // Loop while not finished
1841  while (!f_finished) {
1842 
1843  // Loop over all coarse rows that are found in the coloring for this coarse seed direction
1844  for (casadi_int k=D.colind(csd); k<D.colind(csd+1); ++k) {
1845  casadi_int cci = D.row(k);
1846 
1847  // The first and last rows of the fine block
1848  casadi_int fci_start = fine_row_lookup[coarse_row[cci]];
1849  casadi_int fci_end = fine_row_lookup[coarse_row[cci+1]];
1850 
1851  // Local counter that modifies index into bvec
1852  casadi_int bvec_i_mod = 0;
1853 
1854  casadi_int value = -bvec_i + fci_offset + fci_start;
1855 
1856  // Loop over the rows of the fine block
1857  for (casadi_int fci = fci_offset; fci < std::min(fci_end-fci_start, fci_cap); ++fci) {
1858 
1859  // Loop over the coarse block cols that appear in the coloring
1860  // for the current coarse seed direction
1861  for (casadi_int cri=rT.colind(cci);cri<rT.colind(cci+1);++cri) {
1862  lookup_col.push_back(rT.row(cri));
1863  lookup_row.push_back(bvec_i+bvec_i_mod);
1864  lookup_value.push_back(value);
1865  }
1866 
1867  // Toggle on seeds
1868  bvec_toggle(seed_v, fine_row[fci+fci_start], fine_row[fci+fci_start+1],
1869  bvec_i+bvec_i_mod);
1870  bvec_i_mod++;
1871  }
1872  }
1873 
1874  // Bump bvec_i for next major coarse direction
1875  bvec_i+= std::min(n_fine_blocks_max, fci_cap);
1876 
1877  // Check if bvec buffer is full
1878  if (bvec_i==bvec_size || csd==D.size2()-1) {
1879  // Calculate sparsity for bvec_size directions at once
1880 
1881  // Statistics
1882  nsweeps+=1;
1883 
1884  // Construct lookup table
1885  IM lookup = IM::triplet(lookup_row, lookup_col, lookup_value, bvec_size,
1886  coarse_col.size());
1887 
1888  // Propagate the dependencies
1889  if (use_fwd) {
1890  JacSparsityTraits<true>::sp(this, get_ptr(arg_fwd), get_ptr(res),
1891  get_ptr(iw), get_ptr(w), memory(0));
1892  } else {
1893  std::fill(w.begin(), w.end(), 0);
1894  JacSparsityTraits<false>::sp(this, get_ptr(arg_adj), get_ptr(res),
1895  get_ptr(iw), get_ptr(w), memory(0));
1896  }
1897 
1898  // Temporary bit work vector
1899  bvec_t spsens;
1900 
1901  // Loop over the cols of coarse blocks
1902  for (casadi_int cri=0;cri<coarse_col.size()-1;++cri) {
1903 
1904  // Loop over the cols of fine blocks within the current coarse block
1905  for (casadi_int fri=fine_col_lookup[coarse_col[cri]];
1906  fri<fine_col_lookup[coarse_col[cri+1]];++fri) {
1907  // Lump individual sensitivities together into fine block
1908  bvec_or(sens_v, spsens, fine_col[fri], fine_col[fri+1]);
1909 
1910  // Next iteration if no sparsity
1911  if (!spsens) continue;
1912 
1913  // Loop over all bvec_bits
1914  for (casadi_int bvec_i=0;bvec_i<bvec_size;++bvec_i) {
1915  if (spsens & bvec_lookup[bvec_i]) {
1916  // if dependency is found, add it to the new sparsity pattern
1917  casadi_int ind = lookup.sparsity().get_nz(bvec_i, cri);
1918  if (ind==-1) continue;
1919  jrow.push_back(bvec_i+lookup->at(ind));
1920  jcol.push_back(fri);
1921  }
1922  }
1923  }
1924  }
1925 
1926  // Clear the forward seeds/adjoint sensitivities, ready for next bvec sweep
1927  std::fill(s_in.begin(), s_in.end(), 0);
1928 
1929  // Clear the adjoint seeds/forward sensitivities, ready for next bvec sweep
1930  std::fill(s_out.begin(), s_out.end(), 0);
1931 
1932  // Clean lookup table
1933  lookup_col.clear();
1934  lookup_row.clear();
1935  lookup_value.clear();
1936  }
1937 
1938  if (n_fine_blocks_max>fci_cap) {
1939  fci_offset += std::min(n_fine_blocks_max, fci_cap);
1940  bvec_i = 0;
1941  fci_cap = bvec_size;
1942  } else {
1943  f_finished = true;
1944  }
1945 
1946  }
1947 
1948  }
1949 
1950  // Swap results if adjoint mode was used
1951  if (use_fwd) {
1952  // Construct fine sparsity pattern
1953  r = Sparsity::triplet(fine_row.size()-1, fine_col.size()-1, jrow, jcol);
1954  coarse_col = fine_col;
1955  coarse_row = fine_row;
1956  } else {
1957  // Construct fine sparsity pattern
1958  r = Sparsity::triplet(fine_col.size()-1, fine_row.size()-1, jcol, jrow);
1959  coarse_col = fine_row;
1960  coarse_row = fine_col;
1961  }
1962  hasrun = true;
1963  }
1964  if (verbose_) {
1965  casadi_message("Number of sweeps: " + str(nsweeps));
1966  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(r.size()) + ", " +
1967  str(r.nnz()) + " (" + str(r.density()) + " %) nonzeros.");
1968  }
1969 
1970  return r.T();
1971  }
virtual double sp_weight() const
Weighting factor for chosing forward/reverse mode,.
static Matrix< casadi_int > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< casadi_int > &d)
Construct a sparse matrix from triplet form.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
Definition: sparsity.cpp:1028
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
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.
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31
std::vector< T > diff(const std::vector< T > &values)
diff
bvec_t bvec_or(const bvec_t *arg, casadi_int n)
Bit-wise or operation on bvec_t array.
void bvec_toggle(bvec_t *s, casadi_int begin, casadi_int end, casadi_int j)

References casadi::bvec_or(), casadi::bvec_size, casadi::bvec_toggle(), casadi::Sparsity::colind(), casadi::D, casadi::Sparsity::dense(), casadi::Sparsity::density(), casadi::diff(), casadi::Sparsity::dim(), casadi::Sparsity::get_nz(), casadi::get_ptr(), casadi::lookupvector(), casadi::ProtoFunction::memory(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::range(), casadi::Sparsity::row(), casadi::Sparsity::size(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sp_weight(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::triplet(), casadi::Matrix< casadi_int >::triplet(), casadi::Sparsity::uni_coloring(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::get_jac_sparsity().

◆ get_jac_sparsity_hierarchical_symm()

Sparsity casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm ( casadi_int  oind,
casadi_int  iind 
) const
inherited

A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition for symmetric Jacobians

Definition at line 1436 of file function_internal.cpp.

1437  {
1438  casadi_assert_dev(has_spfwd());
1439 
1440  // Number of nonzero inputs
1441  casadi_int nz = nnz_in(iind);
1442  casadi_assert_dev(nz==nnz_out(oind));
1443 
1444  // Evaluation buffers
1445  std::vector<const bvec_t*> arg(sz_arg(), nullptr);
1446  std::vector<bvec_t*> res(sz_res(), nullptr);
1447  std::vector<casadi_int> iw(sz_iw());
1448  std::vector<bvec_t> w(sz_w());
1449 
1450  // Seeds
1451  std::vector<bvec_t> seed(nz, 0);
1452  arg[iind] = get_ptr(seed);
1453 
1454  // Sensitivities
1455  std::vector<bvec_t> sens(nz, 0);
1456  res[oind] = get_ptr(sens);
1457 
1458  // Sparsity triplet accumulator
1459  std::vector<casadi_int> jcol, jrow;
1460 
1461  // Cols/rows of the coarse blocks
1462  std::vector<casadi_int> coarse(2, 0); coarse[1] = nz;
1463 
1464  // Cols/rows of the fine blocks
1465  std::vector<casadi_int> fine;
1466 
1467  // In each iteration, subdivide each coarse block in this many fine blocks
1468  casadi_int subdivision = bvec_size;
1469 
1470  Sparsity r = Sparsity::dense(1, 1);
1471 
1472  // The size of a block
1473  casadi_int granularity = nz;
1474 
1475  casadi_int nsweeps = 0;
1476 
1477  bool hasrun = false;
1478 
1479  while (!hasrun || coarse.size()!=nz+1) {
1480  if (verbose_) casadi_message("Block size: " + str(granularity));
1481 
1482  // Clear the sparsity triplet acccumulator
1483  jcol.clear();
1484  jrow.clear();
1485 
1486  // Clear the fine block structure
1487  fine.clear();
1488 
1489  Sparsity D = r.star_coloring();
1490 
1491  if (verbose_) {
1492  casadi_message("Star coloring on " + str(r.dim()) + ": "
1493  + str(D.size2()) + " <-> " + str(D.size1()));
1494  }
1495 
1496  // Clear the seeds
1497  std::fill(seed.begin(), seed.end(), 0);
1498 
1499  // Subdivide the coarse block
1500  for (casadi_int k=0; k<coarse.size()-1; ++k) {
1501  casadi_int diff = coarse[k+1]-coarse[k];
1502  casadi_int new_diff = diff/subdivision;
1503  if (diff%subdivision>0) new_diff++;
1504  std::vector<casadi_int> temp = range(coarse[k], coarse[k+1], new_diff);
1505  fine.insert(fine.end(), temp.begin(), temp.end());
1506  }
1507  if (fine.back()!=coarse.back()) fine.push_back(coarse.back());
1508 
1509  granularity = fine[1] - fine[0];
1510 
1511  // The index into the bvec bit vector
1512  casadi_int bvec_i = 0;
1513 
1514  // Create lookup tables for the fine blocks
1515  std::vector<casadi_int> fine_lookup = lookupvector(fine, nz+1);
1516 
1517  // Triplet data used as a lookup table
1518  std::vector<casadi_int> lookup_col;
1519  std::vector<casadi_int> lookup_row;
1520  std::vector<casadi_int> lookup_value;
1521 
1522  // The maximum number of fine blocks contained in one coarse block
1523  casadi_int n_fine_blocks_max = 0;
1524  for (casadi_int i=0;i<coarse.size()-1;++i) {
1525  casadi_int del = fine_lookup[coarse[i+1]]-fine_lookup[coarse[i]];
1526  n_fine_blocks_max = std::max(n_fine_blocks_max, del);
1527  }
1528 
1529  // Loop over all coarse seed directions from the coloring
1530  for (casadi_int csd=0; csd<D.size2(); ++csd) {
1531 
1532 
1533  casadi_int fci_offset = 0;
1534  casadi_int fci_cap = bvec_size-bvec_i;
1535 
1536  // Flag to indicate if all fine blocks have been handled
1537  bool f_finished = false;
1538 
1539  // Loop while not finished
1540  while (!f_finished) {
1541 
1542  // Loop over all coarse rows that are found in the coloring for this coarse seed direction
1543  for (casadi_int k=D.colind(csd); k<D.colind(csd+1); ++k) {
1544  casadi_int cci = D.row(k);
1545 
1546  // The first and last rows of the fine block
1547  casadi_int fci_start = fine_lookup[coarse[cci]];
1548  casadi_int fci_end = fine_lookup[coarse[cci+1]];
1549 
1550  // Local counter that modifies index into bvec
1551  casadi_int bvec_i_mod = 0;
1552 
1553  casadi_int value = -bvec_i + fci_offset + fci_start;
1554 
1555  //casadi_assert_dev(value>=0);
1556 
1557  // Loop over the rows of the fine block
1558  for (casadi_int fci = fci_offset; fci<std::min(fci_end-fci_start, fci_cap); ++fci) {
1559 
1560  // Loop over the coarse block cols that appear in the
1561  // coloring for the current coarse seed direction
1562  for (casadi_int cri=r.colind(cci);cri<r.colind(cci+1);++cri) {
1563  lookup_col.push_back(r.row(cri));
1564  lookup_row.push_back(bvec_i+bvec_i_mod);
1565  lookup_value.push_back(value);
1566  }
1567 
1568  // Toggle on seeds
1569  bvec_toggle(get_ptr(seed), fine[fci+fci_start], fine[fci+fci_start+1],
1570  bvec_i+bvec_i_mod);
1571  bvec_i_mod++;
1572  }
1573  }
1574 
1575  // Bump bvec_i for next major coarse direction
1576  bvec_i += std::min(n_fine_blocks_max, fci_cap);
1577 
1578  // Check if bvec buffer is full
1579  if (bvec_i==bvec_size || csd==D.size2()-1) {
1580  // Calculate sparsity for bvec_size directions at once
1581 
1582  // Statistics
1583  nsweeps+=1;
1584 
1585  // Construct lookup table
1586  IM lookup = IM::triplet(lookup_row, lookup_col, lookup_value,
1587  bvec_size, coarse.size());
1588 
1589  std::reverse(lookup_col.begin(), lookup_col.end());
1590  std::reverse(lookup_row.begin(), lookup_row.end());
1591  std::reverse(lookup_value.begin(), lookup_value.end());
1592  IM duplicates =
1593  IM::triplet(lookup_row, lookup_col, lookup_value, bvec_size, coarse.size())
1594  - lookup;
1595  duplicates = sparsify(duplicates);
1596  lookup(duplicates.sparsity()) = -bvec_size;
1597 
1598  // Propagate the dependencies
1599  JacSparsityTraits<true>::sp(this, get_ptr(arg), get_ptr(res),
1600  get_ptr(iw), get_ptr(w), nullptr);
1601 
1602  // Temporary bit work vector
1603  bvec_t spsens;
1604 
1605  // Loop over the cols of coarse blocks
1606  for (casadi_int cri=0; cri<coarse.size()-1; ++cri) {
1607 
1608  // Loop over the cols of fine blocks within the current coarse block
1609  for (casadi_int fri=fine_lookup[coarse[cri]];fri<fine_lookup[coarse[cri+1]];++fri) {
1610  // Lump individual sensitivities together into fine block
1611  bvec_or(get_ptr(sens), spsens, fine[fri], fine[fri+1]);
1612 
1613  // Loop over all bvec_bits
1614  for (casadi_int bvec_i=0;bvec_i<bvec_size;++bvec_i) {
1615  if (spsens & (bvec_t(1) << bvec_i)) {
1616  // if dependency is found, add it to the new sparsity pattern
1617  casadi_int ind = lookup.sparsity().get_nz(bvec_i, cri);
1618  if (ind==-1) continue;
1619  casadi_int lk = lookup->at(ind);
1620  if (lk>-bvec_size) {
1621  jrow.push_back(bvec_i+lk);
1622  jcol.push_back(fri);
1623  jrow.push_back(fri);
1624  jcol.push_back(bvec_i+lk);
1625  }
1626  }
1627  }
1628  }
1629  }
1630 
1631  // Clear the forward seeds/adjoint sensitivities, ready for next bvec sweep
1632  std::fill(seed.begin(), seed.end(), 0);
1633 
1634  // Clean lookup table
1635  lookup_col.clear();
1636  lookup_row.clear();
1637  lookup_value.clear();
1638  }
1639 
1640  if (n_fine_blocks_max>fci_cap) {
1641  fci_offset += std::min(n_fine_blocks_max, fci_cap);
1642  bvec_i = 0;
1643  fci_cap = bvec_size;
1644  } else {
1645  f_finished = true;
1646  }
1647  }
1648  }
1649 
1650  // Construct fine sparsity pattern
1651  r = Sparsity::triplet(fine.size()-1, fine.size()-1, jrow, jcol);
1652 
1653  // There may be false positives here that are not present
1654  // in the reverse mode that precedes it.
1655  // This can lead to an assymetrical result
1656  // cf. #1522
1657  r=r*r.T();
1658 
1659  coarse = fine;
1660  hasrun = true;
1661  }
1662  if (verbose_) {
1663  casadi_message("Number of sweeps: " + str(nsweeps));
1664  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(r.size()) +
1665  ", " + str(r.nnz()) + " (" + str(r.density()) + " %) nonzeros.");
1666  }
1667 
1668  return r.T();
1669  }
virtual bool has_spfwd() const
Is the class able to propagate seeds through the algorithm?

References casadi::bvec_or(), casadi::bvec_size, casadi::bvec_toggle(), casadi::Sparsity::colind(), casadi::D, casadi::Sparsity::dense(), casadi::Sparsity::density(), casadi::diff(), casadi::Sparsity::dim(), casadi::Sparsity::get_nz(), casadi::get_ptr(), casadi::FunctionInternal::has_spfwd(), casadi::lookupvector(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::range(), casadi::Sparsity::row(), casadi::Sparsity::size(), casadi::Matrix< Scalar >::sparsity(), casadi::Sparsity::star_coloring(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::triplet(), casadi::Matrix< casadi_int >::triplet(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::get_jac_sparsity().

◆ get_jacobian()

Function casadi::FmuFunction::get_jacobian ( const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict &  opts 
) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1594 of file fmu_function.cpp.

1595  {
1596  // Hack: Inherit parallelization, verbosity option
1597  Dict opts1 = opts;
1598  opts1["parallelization"] = to_string(parallelization_);
1599  opts1["verbose"] = verbose_;
1600  opts1["print_progress"] = print_progress_;
1601  // Return new instance of class
1602  Function ret;
1603  ret.own(new FmuFunction(name, fmu_, inames, onames));
1604  ret->construct(opts1);
1605  return ret;
1606 }

References casadi::ProtoFunction::construct(), fmu_, FmuFunction(), casadi::GenericShared< Shared, Internal >::own(), parallelization_, print_progress_, casadi::to_string(), and casadi::ProtoFunction::verbose_.

◆ get_jit_directory()

std::string casadi::FunctionInternal::get_jit_directory ( const Dict &  jit_options)
staticinherited

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

Definition at line 710 of file function_internal.cpp.

710  {
711  // Start with default temp work dir
712  std::string jit_directory = GlobalOptions::getTempWorkDir();
713 
714  // Get user-specified directory
715  std::string directory;
716  directory = get_from_dict(jit_options, "directory", std::string(""));
717 
718  // What if directory itself is absolute?
719  if (Filesystem::is_absolute(directory)) {
720  // Override
721  jit_directory = directory;
722  } else {
723  jit_directory = jit_directory + directory;
724  if (Filesystem::is_enabled()) {
725  jit_directory = Filesystem::absolute(jit_directory);
726  }
727  }
728 
729  return Filesystem::ensure_trailing_slash(jit_directory);
730  }
static std::string absolute(const std::string &path)
Definition: filesystem.cpp:78
static bool is_absolute(const std::string &path)
Definition: filesystem.cpp:162
static std::string ensure_trailing_slash(const std::string &path)
Definition: filesystem.cpp:155
static bool is_enabled()
Definition: filesystem.cpp:83
static std::string getTempWorkDir()
T get_from_dict(const std::map< std::string, T > &d, const std::string &key, const T &default_value)

References casadi::Filesystem::absolute(), casadi::Filesystem::ensure_trailing_slash(), casadi::get_from_dict(), casadi::GlobalOptions::getTempWorkDir(), casadi::Filesystem::is_absolute(), and casadi::Filesystem::is_enabled().

Referenced by casadi::FunctionInternal::finalize(), and casadi::ShellCompiler::init().

◆ get_max_in()

virtual double casadi::FunctionInternal::get_max_in ( casadi_int  ind) const
inlinevirtualinherited

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

Definition at line 1106 of file function_internal.hpp.

1106  {
1107  return inf;
1108  }
const double inf
infinity
Definition: calculus.hpp:50

References casadi::inf.

◆ get_min_in()

virtual double casadi::FunctionInternal::get_min_in ( casadi_int  ind) const
inlinevirtualinherited

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

Definition at line 1113 of file function_internal.hpp.

1113  {
1114  return -inf;
1115  }

References casadi::inf.

◆ get_n_in()

size_t casadi::FmuFunction::get_n_in ( )
inlineoverridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 241 of file fmu_function.hpp.

241 { return in_.size();}

◆ get_n_out()

size_t casadi::FmuFunction::get_n_out ( )
inlineoverridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 242 of file fmu_function.hpp.

242 {return out_.size();}

◆ get_name_in()

std::string casadi::FunctionInternal::get_name_in ( casadi_int  i)
virtualinherited

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

Reimplemented in casadi::Rootfinder, casadi::OnnxFunction, casadi::Nlpsol, casadi::MapSum, casadi::Map, casadi::Interpolant, casadi::Integrator, casadi::FiniteDiff, casadi::External, casadi::Dple, casadi::Conic, casadi::CallbackInternal, and casadi::BlazingSplineFunction.

Definition at line 673 of file function_internal.cpp.

673  {
674  if (!derivative_of_.is_null()) {
675  std::string n = derivative_of_.name();
676  if (name_ == "jac_" + n || name_ == "adj1_" + n) {
677  if (i < derivative_of_.n_in()) {
678  // Same as nondifferentiated function
679  return derivative_of_.name_in(i);
680  } else if (i < derivative_of_.n_in() + derivative_of_.n_out()) {
681  // Nondifferentiated output
682  return "out_" + derivative_of_.name_out(i - derivative_of_.n_in());
683  } else {
684  // Adjoint seed
685  return "adj_" + derivative_of_.name_out(i - derivative_of_.n_in()
686  - derivative_of_.n_out());
687  }
688  }
689  }
690  // Default name
691  return "i" + str(i);
692  }
const std::vector< std::string > & name_in() const
Get input scheme.
Definition: function.cpp:1113
const std::string & name() const
Name of the function.
Definition: function.cpp:1504
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
const std::vector< std::string > & name_out() const
Get output scheme.
Definition: function.cpp:1117

References casadi::FunctionInternal::derivative_of_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::name(), casadi::ProtoFunction::name_, casadi::Function::name_in(), casadi::Function::name_out(), and casadi::str().

Referenced by casadi::External::get_name_in(), and casadi::FunctionInternal::init().

◆ get_name_out()

std::string casadi::FunctionInternal::get_name_out ( casadi_int  i)
virtualinherited

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

Reimplemented in casadi::Rootfinder, casadi::OnnxFunction, casadi::Nlpsol, casadi::MapSum, casadi::Map, casadi::Interpolant, casadi::Integrator, casadi::FiniteDiff, casadi::External, casadi::Dple, casadi::Conic, casadi::CallbackInternal, and casadi::BlazingSplineFunction.

Definition at line 694 of file function_internal.cpp.

694  {
695  if (!derivative_of_.is_null()) {
696  std::string n = derivative_of_.name();
697  if (name_ == "jac_" + n) {
698  // Jacobian block
699  casadi_int oind = i / derivative_of_.n_in(), iind = i % derivative_of_.n_in();
700  return "jac_" + derivative_of_.name_out(oind) + "_" + derivative_of_.name_in(iind);
701  } else if (name_ == "adj1_" + n) {
702  // Adjoint sensitivity
703  return "adj_" + derivative_of_.name_in(i);
704  }
705  }
706  // Default name
707  return "o" + str(i);
708  }

References casadi::FunctionInternal::derivative_of_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Function::n_in(), casadi::Function::name(), casadi::ProtoFunction::name_, casadi::Function::name_in(), casadi::Function::name_out(), and casadi::str().

Referenced by casadi::External::get_name_out(), and casadi::FunctionInternal::init().

◆ get_nominal_in()

std::vector< double > casadi::FmuFunction::get_nominal_in ( casadi_int  i) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 902 of file fmu_function.cpp.

902  {
903  switch (in_.at(i).type) {
904  case InputType::REG:
905  return fmu_.all_nominal_in(in_.at(i).ind);
906  case InputType::FWD:
907  case InputType::ADJ:
908  case InputType::ADJ_OUT:
909  break;
910  case InputType::OUT:
911  return fmu_.all_nominal_out(in_.at(i).ind);
912  }
913  // Default: Base class
915 }
std::vector< double > all_nominal_out(size_t ind) const
Definition: fmu.cpp:213
std::vector< double > all_nominal_in(size_t ind) const
Definition: fmu.cpp:205
virtual std::vector< double > get_nominal_in(casadi_int ind) const

References casadi::ADJ, casadi::ADJ_OUT, casadi::Fmu::all_nominal_in(), casadi::Fmu::all_nominal_out(), fmu_, casadi::FWD, casadi::FunctionInternal::get_nominal_in(), in_, casadi::OUT, and casadi::REG.

◆ get_nominal_out()

std::vector< double > casadi::FmuFunction::get_nominal_out ( casadi_int  i) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 917 of file fmu_function.cpp.

917  {
918  switch (out_.at(i).type) {
919  case OutputType::REG:
920  return fmu_.all_nominal_out(out_.at(i).ind);
921  case OutputType::FWD:
922  case OutputType::ADJ:
923  break;
924  case OutputType::JAC:
925  casadi_warning("FmuFunction::get_nominal_out not implemented for OutputType::JAC");
926  break;
928  casadi_warning("FmuFunction::get_nominal_out not implemented for OutputType::JAC_TRANS");
929  break;
931  casadi_warning("FmuFunction::get_nominal_out not implemented for OutputType::JAC_ADJ_OUT");
932  break;
934  casadi_warning("FmuFunction::get_nominal_out not implemented for OutputType::JAC_REG_ADJ");
935  break;
936  case OutputType::HESS:
937  casadi_warning("FmuFunction::get_nominal_out not implemented for OutputType::HESS");
938  break;
939  }
940  // Default: Base class
942 }
virtual std::vector< double > get_nominal_out(casadi_int ind) const

References casadi::ADJ, casadi::Fmu::all_nominal_out(), fmu_, casadi::FWD, casadi::FunctionInternal::get_nominal_out(), casadi::HESS, casadi::JAC, casadi::JAC_ADJ_OUT, casadi::JAC_REG_ADJ, casadi::JAC_TRANS, out_, and casadi::REG.

◆ get_options()

const Options& casadi::FmuFunction::get_options ( ) const
inlineoverridevirtual

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

Reimplemented from casadi::ProtoFunction.

Definition at line 206 of file fmu_function.hpp.

206 { return options_;}
static const Options options_
Options.

◆ get_partition()

void casadi::FunctionInternal::get_partition ( casadi_int  iind,
casadi_int  oind,
Sparsity &  D1,
Sparsity &  D2,
bool  compact,
bool  symmetric,
bool  allow_forward,
bool  allow_reverse 
) const
inherited

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

Definition at line 2126 of file function_internal.cpp.

2128  {
2129  if (verbose_) casadi_message(name_ + "::get_partition");
2130  casadi_assert(allow_forward || allow_reverse, "Inconsistent options");
2131 
2132  // Sparsity pattern with transpose
2133  Sparsity &AT = jac_sparsity(oind, iind, compact, symmetric);
2134  Sparsity A = symmetric ? AT : AT.T();
2135 
2136  // Get seed matrices by graph coloring
2137  if (symmetric) {
2138  casadi_assert_dev(enable_forward_ || enable_fd_);
2139  casadi_assert_dev(allow_forward);
2140 
2141  // Star coloring if symmetric
2142  if (verbose_) casadi_message("FunctionInternal::getPartition star_coloring");
2143  D1 = A.star_coloring();
2144  if (verbose_) {
2145  casadi_message("Star coloring completed: " + str(D1.size2())
2146  + " directional derivatives needed ("
2147  + str(A.size1()) + " without coloring).");
2148  }
2149 
2150  } else {
2151  casadi_assert_dev(enable_forward_ || enable_fd_ || enable_reverse_);
2152  // Get weighting factor
2153  double w = ad_weight();
2154 
2155  // Which AD mode?
2156  if (w==1) allow_forward = false;
2157  if (w==0) allow_reverse = false;
2158  casadi_assert(allow_forward || allow_reverse, "Conflicting ad weights");
2159 
2160  // Best coloring encountered so far (relatively tight upper bound)
2161  double best_coloring = std::numeric_limits<double>::infinity();
2162 
2163  // Test forward mode first?
2164  bool test_fwd_first = allow_forward && w*static_cast<double>(A.size1()) <=
2165  (1-w)*static_cast<double>(A.size2());
2166  casadi_int mode_fwd = test_fwd_first ? 0 : 1;
2167 
2168  // Test both coloring modes
2169  for (casadi_int mode=0; mode<2; ++mode) {
2170  // Is this the forward mode?
2171  bool fwd = mode==mode_fwd;
2172 
2173  // Skip?
2174  if (!allow_forward && fwd) continue;
2175  if (!allow_reverse && !fwd) continue;
2176 
2177  // Perform the coloring
2178  if (fwd) {
2179  if (verbose_) casadi_message("Unidirectional coloring (forward mode)");
2180  bool d = best_coloring>=w*static_cast<double>(A.size1());
2181  casadi_int max_colorings_to_test =
2182  d ? A.size1() : static_cast<casadi_int>(floor(best_coloring/w));
2183  D1 = AT.uni_coloring(A, max_colorings_to_test);
2184  if (D1.is_null()) {
2185  if (verbose_) {
2186  casadi_message("Forward mode coloring interrupted (more than "
2187  + str(max_colorings_to_test) + " needed).");
2188  }
2189  } else {
2190  if (verbose_) {
2191  casadi_message("Forward mode coloring completed: "
2192  + str(D1.size2()) + " directional derivatives needed ("
2193  + str(A.size1()) + " without coloring).");
2194  }
2195  D2 = Sparsity();
2196  best_coloring = w*static_cast<double>(D1.size2());
2197  }
2198  } else {
2199  if (verbose_) casadi_message("Unidirectional coloring (adjoint mode)");
2200  bool d = best_coloring>=(1-w)*static_cast<double>(A.size2());
2201  casadi_int max_colorings_to_test =
2202  d ? A.size2() : static_cast<casadi_int>(floor(best_coloring/(1-w)));
2203 
2204  D2 = A.uni_coloring(AT, max_colorings_to_test);
2205  if (D2.is_null()) {
2206  if (verbose_) {
2207  casadi_message("Adjoint mode coloring interrupted (more than "
2208  + str(max_colorings_to_test) + " needed).");
2209  }
2210  } else {
2211  if (verbose_) {
2212  casadi_message("Adjoint mode coloring completed: "
2213  + str(D2.size2()) + " directional derivatives needed ("
2214  + str(A.size2()) + " without coloring).");
2215  }
2216  D1 = Sparsity();
2217  best_coloring = (1-w)*static_cast<double>(D2.size2());
2218  }
2219  }
2220  }
2221 
2222  }
2223  }
Sparsity & jac_sparsity(casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
Get Jacobian sparsity.

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::ProtoFunction::name_, casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Sparsity::star_coloring(), casadi::str(), casadi::Sparsity::T(), casadi::Sparsity::uni_coloring(), and casadi::ProtoFunction::verbose_.

◆ get_reltol()

virtual double casadi::FunctionInternal::get_reltol ( ) const
inlinevirtualinherited

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

Reimplemented in casadi::SundialsInterface.

Definition at line 1128 of file function_internal.hpp.

1128  {
1129  return eps;
1130  }

References casadi::eps.

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

◆ get_reverse()

Function casadi::FmuFunction::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
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1643 of file fmu_function.cpp.

1646  {
1647  // Hack: Inherit parallelization option
1648  Dict opts1 = opts;
1649  opts1["parallelization"] = to_string(parallelization_);
1650  opts1["verbose"] = verbose_;
1651  opts1["new_jacobian"] = new_hessian_;
1652  opts1["print_progress"] = print_progress_;
1653  opts1["nadj"] = nadj;
1654  // Return new instance of class
1655  Function ret;
1656  ret.own(new FmuFunction(name, fmu_, inames, onames));
1657  ret->construct(opts1);
1658  return ret;
1659 }

References casadi::ProtoFunction::construct(), fmu_, FmuFunction(), new_hessian_, casadi::GenericShared< Shared, Internal >::own(), parallelization_, print_progress_, casadi::to_string(), and casadi::ProtoFunction::verbose_.

◆ get_sparsity_in()

Sparsity casadi::FmuFunction::get_sparsity_in ( casadi_int  i)
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 863 of file fmu_function.cpp.

863  {
864  switch (in_.at(i).type) {
865  case InputType::REG:
866  return Sparsity::dense(fmu_.ired(in_.at(i).ind).size(), 1);
867  case InputType::FWD:
868  return Sparsity::dense(fmu_.ired(in_.at(i).ind).size(), nfwd_);
869  case InputType::ADJ:
870  return Sparsity::dense(fmu_.ored(in_.at(i).ind).size(), nadj_);
871  case InputType::OUT:
872  return Sparsity(fmu_.ored(in_.at(i).ind).size(), 1);
873  case InputType::ADJ_OUT:
874  return Sparsity(fmu_.ired(in_.at(i).ind).size(), 1);
875  }
876  return Sparsity();
877 }

References casadi::ADJ, casadi::ADJ_OUT, casadi::Sparsity::dense(), fmu_, casadi::FWD, in_, casadi::Fmu::ired(), nadj_, nfwd_, casadi::Fmu::ored(), casadi::OUT, and casadi::REG.

◆ get_sparsity_out()

Sparsity casadi::FmuFunction::get_sparsity_out ( casadi_int  i)
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 879 of file fmu_function.cpp.

879  {
880  const OutputStruct& s = out_.at(i);
881  switch (out_.at(i).type) {
882  case OutputType::REG:
883  return Sparsity::dense(fmu_.ored(s.ind).size(), 1);
884  case OutputType::FWD:
885  return Sparsity::dense(fmu_.ored(s.ind).size(), nfwd_);
886  case OutputType::ADJ:
887  return Sparsity::dense(fmu_.ired(s.wrt).size(), nadj_);
888  case OutputType::JAC:
889  return fmu_.jac_sparsity(s.ind, s.wrt);
891  return fmu_.jac_sparsity(s.ind, s.wrt).T();
893  return Sparsity(fmu_.ired(s.ind).size(), fmu_.ored(s.wrt).size());
895  return Sparsity(fmu_.ored(s.ind).size(), fmu_.ored(s.wrt).size());
896  case OutputType::HESS:
897  return fmu_.hess_sparsity(s.ind, s.wrt);
898  }
899  return Sparsity();
900 }

References casadi::ADJ, casadi::Sparsity::dense(), fmu_, casadi::FWD, casadi::HESS, casadi::Fmu::hess_sparsity(), casadi::OutputStruct::ind, casadi::Fmu::ired(), casadi::JAC, casadi::JAC_ADJ_OUT, casadi::JAC_REG_ADJ, casadi::Fmu::jac_sparsity(), casadi::JAC_TRANS, nadj_, nfwd_, casadi::Fmu::ored(), out_, casadi::REG, casadi::Sparsity::T(), and casadi::OutputStruct::wrt.

◆ get_stats()

Dict casadi::FmuFunction::get_stats ( void *  mem) const
overridevirtual

Reimplemented from casadi::ProtoFunction.

Definition at line 1692 of file fmu_function.cpp.

1692  {
1693  // Get the stats from the base classes
1694  Dict stats = FunctionInternal::get_stats(mem);
1695  // Get memory object
1696  FmuMemory* m = static_cast<FmuMemory*>(mem);
1697  // Get auxilliary variables from Fmu
1698  fmu_.get_stats(m, &stats, name_in_, get_ptr(in_));
1699  // Return stats
1700  return stats;
1701 }
void get_stats(FmuMemory *m, Dict *stats, const std::vector< std::string > &name_in, const InputStruct *in) const
Get stats.
Definition: fmu.cpp:433
Dict get_stats(void *mem) const override
Get all statistics.

References fmu_, casadi::get_ptr(), casadi::Fmu::get_stats(), casadi::FunctionInternal::get_stats(), in_, and casadi::FunctionInternal::name_in_.

◆ getAdaptorSolverName()

virtual std::string casadi::FunctionInternal::getAdaptorSolverName ( ) const
inlinevirtualinherited

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

Definition at line 306 of file function_internal.hpp.

306 { return ""; }

◆ getCount()

Definition at line 60 of file generic_shared_internal.hpp.

210  {
211  return static_cast<const Internal*>(this)->count;
212  }

◆ has_codegen()

virtual bool casadi::FunctionInternal::has_codegen ( ) const
inlinevirtualinherited

◆ has_derivative()

bool casadi::FunctionInternal::has_derivative ( ) const
inherited

◆ has_eval_dm()

virtual bool casadi::FunctionInternal::has_eval_dm ( ) const
inlinevirtualinherited

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

Reimplemented in casadi::CallbackInternal.

Definition at line 437 of file function_internal.hpp.

437 { return false;}

Referenced by casadi::FunctionInternal::eval().

◆ has_forward()

bool casadi::FmuFunction::has_forward ( casadi_int  nfwd) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1608 of file fmu_function.cpp.

1608  {
1609  // Only implemented if "new_forward" is enabled
1610  if (!new_forward_) return FunctionInternal::has_forward(nfwd);
1611  // Only first order analytic derivative possible
1612  if (!all_regular()) return false;
1613  // Use analytic forward derivatives
1614  return true;
1615 }

References all_regular(), casadi::FunctionInternal::has_forward(), and new_forward_.

◆ has_free()

virtual bool casadi::FunctionInternal::has_free ( ) const
inlinevirtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 756 of file function_internal.hpp.

756 { return false;}

Referenced by casadi::FunctionInternal::get_free().

◆ has_function()

virtual bool casadi::FunctionInternal::has_function ( const std::string &  fname) const
inlinevirtualinherited

Reimplemented in casadi::OracleFunction, casadi::MapSum, and casadi::Map.

Definition at line 371 of file function_internal.hpp.

371 {return false;}

◆ has_jac_sparsity()

bool casadi::FmuFunction::has_jac_sparsity ( casadi_int  oind,
casadi_int  iind 
) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1661 of file fmu_function.cpp.

1661  {
1662  // Available in the FMU meta information
1663  if ((out_.at(oind).type == OutputType::REG || out_.at(oind).type == OutputType::ADJ)
1664  && (in_.at(iind).type == InputType::REG || in_.at(iind).type == InputType::ADJ)) {
1665  return true;
1666  }
1667  // Not available
1668  return false;
1669 }

References casadi::ADJ, in_, out_, and casadi::REG.

◆ has_jacobian()

bool casadi::FmuFunction::has_jacobian ( ) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1587 of file fmu_function.cpp.

1587  {
1588  // Calculation of Hessian inside FmuFunction (in development)
1589  if (new_jacobian_ && all_vectors()) return true;
1590  // Only first order
1591  return all_regular();
1592 }
bool all_vectors() const

References all_regular(), all_vectors(), and new_jacobian_.

◆ has_memory()

bool casadi::ProtoFunction::has_memory ( int  ind) const
inherited

Definition at line 3912 of file function_internal.cpp.

3912  {
3913  return ind<mem_.size();
3914  }

◆ has_option()

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

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

Definition at line 1113 of file function_internal.cpp.

1113  {
1114  return get_options().find(option_name) != nullptr;
1115  }
const Options::Entry * find(const std::string &name) const
Definition: options.cpp:32

References casadi::Options::find(), and casadi::ProtoFunction::get_options().

◆ has_reverse()

bool casadi::FmuFunction::has_reverse ( casadi_int  nadj) const
overridevirtual

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1636 of file fmu_function.cpp.

1636  {
1637  // Only first order analytic derivative possible
1638  if (!all_regular()) return false;
1639  // Use analytic adjoint derivatives
1640  return true;
1641 }

References all_regular().

◆ has_spfwd()

virtual bool casadi::FunctionInternal::has_spfwd ( ) const
inlinevirtualinherited

◆ has_sprev()

virtual bool casadi::FunctionInternal::has_sprev ( ) const
inlinevirtualinherited

◆ identify_io()

void casadi::FmuFunction::identify_io ( std::vector< std::string > *  scheme_in,
std::vector< std::string > *  scheme_out,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out 
)
static

Definition at line 684 of file fmu_function.cpp.

688  {
689  // Clear returns
690  if (scheme_in) scheme_in->clear();
691  if (scheme_out) scheme_out->clear();
692  // Parse FmuFunction inputs
693  for (const std::string& n : name_in) {
694  try {
695  (void)InputStruct::parse(n, nullptr, scheme_in, scheme_out);
696  } catch (std::exception& e) {
697  casadi_error("Cannot process input " + n + ": " + std::string(e.what()));
698  }
699  }
700  // Parse FmuFunction outputs
701  for (const std::string& n : name_out) {
702  try {
703  (void)OutputStruct::parse(n, nullptr, scheme_in, scheme_out);
704  } catch (std::exception& e) {
705  casadi_error("Cannot process output " + n + ": " + std::string(e.what()));
706  }
707  }
708  // Remove duplicates in scheme_in, also sorts alphabetically
709  if (scheme_in) {
710  std::set<std::string> s(scheme_in->begin(), scheme_in->end());
711  scheme_in->assign(s.begin(), s.end());
712  }
713  // Remove duplicates in scheme_out, also sorts alphabetically
714  if (scheme_out) {
715  std::set<std::string> s(scheme_out->begin(), scheme_out->end());
716  scheme_out->assign(s.begin(), s.end());
717  }
718 }

References casadi::InputStruct::parse(), and casadi::OutputStruct::parse().

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

◆ incache()

bool casadi::FunctionInternal::incache ( const std::string &  fname,
Function &  f,
const std::string &  suffix = "" 
) const
inherited

◆ index_in()

casadi_int casadi::FunctionInternal::index_in ( const std::string &  name) const
inlineinherited

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

Definition at line 1162 of file function_internal.hpp.

1162  {
1163  for (casadi_int i=0; i<name_in_.size(); ++i) {
1164  if (name_in_[i]==name) return i;
1165  }
1166  casadi_error("FunctionInternal::index_in: could not find entry \""
1167  + name + "\". Available names are: " + str(name_in_) + ".");
1168  return -1;
1169  }

References casadi::str().

Referenced by casadi::FunctionInternal::convert_arg().

◆ index_out()

casadi_int casadi::FunctionInternal::index_out ( const std::string &  name) const
inlineinherited

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

Definition at line 1174 of file function_internal.hpp.

1174  {
1175  for (casadi_int i=0; i<name_out_.size(); ++i) {
1176  if (name_out_[i]==name) return i;
1177  }
1178  casadi_error("FunctionInternal::index_out: could not find entry \""
1179  + name + "\". Available names are: " + str(name_out_) + ".");
1180  return -1;
1181  }

References casadi::str().

Referenced by casadi::FunctionInternal::convert_res().

◆ info()

Dict casadi::FunctionInternal::info ( ) const
virtualinherited

◆ init()

void casadi::FmuFunction::init ( const Dict &  opts)
overridevirtual

Reimplemented from casadi::ProtoFunction.

Definition at line 336 of file fmu_function.cpp.

336  {
337  // Read options
338  for (auto&& op : opts) {
339  if (op.first=="enable_ad") {
340  casadi_warning("Option 'enable_ad' has been renamed 'uses_directional_derivatives'");
341  uses_directional_derivatives_ = op.second;
342  } else if (op.first=="uses_directional_derivatives") {
343  uses_directional_derivatives_ = op.second;
344  } else if (op.first=="nfwd") {
345  nfwd_ = op.second;
346  } else if (op.first=="nadj") {
347  nadj_ = op.second;
348  } else if (op.first=="uses_adjoint_derivatives") {
349  uses_adjoint_derivatives_ = op.second;
350  } else if (op.first=="validate_forward") {
351  validate_forward_ = op.second;
352  } else if (op.first=="validate_hessian") {
353  validate_hessian_ = op.second;
354  } else if (op.first=="validate_ad") {
355  casadi_warning("Option 'validate_ad' has been renamed 'validate_forward'");
356  validate_forward_ = op.second;
357  } else if (op.first=="check_hessian") {
358  casadi_warning("Option 'check_hessian' has been renamed 'validate_hessian'");
359  validate_hessian_ = op.second;
360  } else if (op.first=="validate_ad_file") {
361  validate_ad_file_ = op.second.to_string();
362  } else if (op.first=="make_symmetric") {
363  make_symmetric_ = op.second;
364  } else if (op.first=="step") {
365  step_ = op.second;
366  } else if (op.first=="fd_flip") {
367  fd_flip_ = op.second;
368  } else if (op.first=="abstol") {
369  abstol_ = op.second;
370  } else if (op.first=="reltol") {
371  reltol_ = op.second;
372  } else if (op.first=="parallelization") {
373  parallelization_ = to_enum<Parallelization>(op.second, "serial");
374  } else if (op.first=="print_progress") {
375  print_progress_ = op.second;
376  } else if (op.first=="new_forward") {
377  new_forward_ = op.second;
378  } else if (op.first=="new_jacobian") {
379  new_jacobian_ = op.second;
380  } else if (op.first=="new_hessian") {
381  new_hessian_ = op.second;
382  } else if (op.first=="hessian_coloring") {
383  hessian_coloring_ = op.second;
384  } else if (op.first=="asymmetric_hessian_coloring") {
385  asymmetric_hessian_coloring_ = op.second;
386  } else if (op.first=="enable_forward_jacobian") {
387  enable_forward_jacobian_ = op.second;
388  } else if (op.first=="enable_adjoint_jacobian") {
389  enable_adjoint_jacobian_ = op.second;
390  } else if (op.first=="enable_adjoint_hessian") {
391  enable_adjoint_hessian_ = op.second;
392  }
393  }
394 
395  // Call the initialization method of the base class
397 
398  // Read FD mode
399  fd_ = to_enum<FdMode>(fd_method_, "forward");
400 
401  // Consistency checks
403  "FMU does not provide support for analytic derivatives");
404  if (validate_forward_ && !uses_directional_derivatives_) casadi_error("Inconsistent options");
406  "FMU does not provide support for adjoint derivatives");
407  if (enable_adjoint_jacobian_) casadi_assert(uses_adjoint_derivatives_, "Inconsistent options");
408 
409  // New AD validation file, if any
410  if (!validate_ad_file_.empty()) {
411  auto valfile_ptr = Filesystem::ofstream_ptr(validate_ad_file_);
412  std::ostream& valfile = *valfile_ptr;
413  valfile << "Output Input Value Nominal Min Max AD FD Step Offset Stencil" << std::endl;
414  }
415 
416  // Quick return if no Jacobian calculation
417  if (!has_jac_ && !has_adj_ && !has_hess_) return;
418 
419  // Parallelization
420  switch (parallelization_) {
422  if (verbose_) casadi_message("Serial evaluation");
423  break;
424 #ifdef WITH_OPENMP
426  max_n_tasks_ = omp_get_max_threads();
427  if (verbose_) casadi_message("OpenMP using at most " + str(max_n_tasks_) + " threads");
428  break;
429 #endif // WITH_OPENMP
430 #ifdef CASADI_WITH_THREAD
432  max_n_tasks_ = std::thread::hardware_concurrency();
433  if (verbose_) casadi_message("std::thread using at most " + str(max_n_tasks_) + " threads");
434  break;
435 #endif // CASADI_WITH_THREAD
436  default:
437  casadi_warning("Parallelization " + to_string(parallelization_)
438  + " not enabled during compilation. Falling back to serial evaluation");
440  break;
441  }
442 
443  // Collect all inputs in any Jacobian, Hessian or adjoint block
444  std::vector<size_t> in_jac(fmu_.n_in(), 0);
445  jac_in_.clear();
446  jac_nom_in_.clear();
447  for (auto&& i : out_) {
448  if (i.type == OutputType::JAC || i.type == OutputType::JAC_TRANS
449  || i.type == OutputType::ADJ || i.type == OutputType::HESS) {
450  // Get input indices
451  const std::vector<size_t>& iind = fmu_.ired(i.wrt);
452  // Skip if no entries
453  if (iind.empty()) continue;
454  // Consistency check
455  bool exists = in_jac[iind.front()] > 0;
456  for (size_t j : iind) casadi_assert((in_jac[j] > 0) == exists, "Jacobian not a block");
457  // Add selection
458  if (!exists) {
459  for (size_t j : iind) {
460  jac_in_.push_back(j);
461  jac_nom_in_.push_back(fmu_.nominal_in(j));
462  in_jac[j] = jac_in_.size();
463  }
464  }
465  // Add column interval
466  i.cbegin = in_jac[iind.front()] - 1;
467  i.cend = i.cbegin + iind.size();
468  // Also rows for Hessian blocks
469  if (i.type == OutputType::HESS) {
470  // Get input indices
471  const std::vector<size_t>& iind = fmu_.ired(i.ind);
472  // Skip if no entries
473  if (iind.empty()) continue;
474  // Consistency check
475  bool exists = in_jac[iind.front()] > 0;
476  for (size_t j : iind) casadi_assert((in_jac[j] > 0) == exists, "Hessian not a block");
477  // Add selection
478  if (!exists) {
479  for (size_t j : iind) {
480  jac_in_.push_back(j);
481  jac_nom_in_.push_back(fmu_.nominal_in(j));
482  in_jac[j] = jac_in_.size();
483  }
484  }
485  // Add column interval
486  i.rbegin = in_jac[iind.front()] - 1;
487  i.rend = i.rbegin + iind.size();
488  }
489  }
490  }
491 
492  // Transpose of Jacobian sparsity
493  sp_trans_map_.resize(out_.size(), -1);
494  sp_trans_.clear();
495 
496  // Collect all outputs in any Jacobian or adjoint block
497  in_jac.resize(fmu_.n_out());
498  std::fill(in_jac.begin(), in_jac.end(), 0);
499  jac_out_.clear();
500  for (size_t k = 0; k < out_.size(); ++k) {
501  OutputStruct& i = out_[k];
502  if (i.type == OutputType::JAC || i.type == OutputType::JAC_TRANS) {
503  // Get output indices
504  const std::vector<size_t>& oind = fmu_.ored(i.ind);
505  // Skip if no entries
506  if (oind.empty()) continue;
507  // Consistency check
508  bool exists = in_jac[oind.front()] > 0;
509  for (size_t j : oind) casadi_assert((in_jac[j] > 0) == exists, "Jacobian not a block");
510  // Add selection
511  if (!exists) {
512  for (size_t j : oind) {
513  jac_out_.push_back(j);
514  in_jac[j] = jac_out_.size();
515  }
516  }
517  // Add row interval
518  i.rbegin = in_jac[oind.front()] - 1;
519  i.rend = i.rbegin + oind.size();
520  // Additional memory for transpose
521  if (i.type == OutputType::JAC_TRANS) {
522  // Retrieve the sparsity pattern
523  const Sparsity& sp = sparsity_out(k);
524  // Save transpose of sparsity pattern
525  sp_trans_map_.at(k) = sp_trans_.size();
526  sp_trans_.push_back(sp.T());
527  // Work vectors for casadi_trans
528  alloc_w(sp.nnz());
529  alloc_iw(sp.size2());
530  }
531  }
532  }
533  // NOTE(@jaeandersson): Make conditional !need_jac && uses_adjoint_derivatives_?
534  for (auto&& i : in_) {
535  if (i.type == InputType::ADJ) {
536  // Get output indices
537  const std::vector<size_t>& oind = fmu_.ored(i.ind);
538  // Skip if no entries
539  if (oind.empty()) continue;
540  // Consistency check
541  bool exists = in_jac[oind.front()] > 0;
542  for (size_t j : oind) casadi_assert((in_jac[j] > 0) == exists, "Jacobian not a block");
543  // Add selection
544  if (!exists) {
545  for (size_t j : oind) {
546  jac_out_.push_back(j);
547  in_jac[j] = jac_out_.size();
548  }
549  }
550  }
551  }
552 
553  // Get sparsity pattern for extended Jacobian
555 
556  // Calculate graph coloring
558  if (verbose_) casadi_message("Jacobian graph coloring: " + str(jac_sp_.size2())
559  + " -> " + str(jac_colors_.size2()) + " directions");
560 
561  // Setup Jacobian memory
562  casadi_jac_setup(&jac_prob_, jac_sp_, jac_colors_);
566 
567  // Do not use more threads than there are colors in the Jacobian
569 
570  // Graph coloring for Jacobian via adjoint derivatives
572  // Graph coloring of the transpose of the Jacobian
573  adj_sp_ = jac_sp_.T();
575  if (verbose_) casadi_message("Jacobian graph coloring via adjoint derivatives: "
576  + str(adj_sp_.size2()) + " -> " + str(adj_colors_.size2()) + " directions");
577  // Setup Jacobian memory
578  casadi_jac_setup(&adj_prob_, adj_sp_, adj_colors_);
579  adj_prob_.nom_in = nullptr; // default value (1) probably fine since no FD is used
582  // Do not use more threads than there are colors in the Jacobian
583  max_jac_tasks_ = std::max(max_jac_tasks_, std::min(max_n_tasks_, adj_colors_.size2()));
584  }
585 
586  // Work vector for storing extended Jacobian, shared between threads
587  if (has_jac_) {
588  alloc_w(jac_sp_.nnz(), true); // jac_nz
589  }
590 
591  // Work vectors for adjoint derivative calculation, shared between threads
592  if (has_adj_) {
593  alloc_w(nadj_ * fmu_.n_out(), true); // aseed
594  alloc_w(nadj_ * fmu_.n_in(), true); // asens
595  }
596 
597  // If Hessian calculation is needed
598  if (has_hess_) {
599  // Get sparsity pattern for extended Hessian
601  casadi_assert(hess_sp_.size1() == jac_in_.size(), "Inconsistent Hessian dimensions");
602  casadi_assert(hess_sp_.size2() == jac_in_.size(), "Inconsistent Hessian dimensions");
603  const casadi_int *hess_row = hess_sp_.row();
604  casadi_int hess_nnz = hess_sp_.nnz();
605 
606  // Get linearly and nonlinearly entering variables
607  std::vector<bool> is_nonlin(jac_in_.size(), false);
608  for (casadi_int k = 0; k < hess_nnz; ++k) is_nonlin[hess_row[k]] = true;
609  nonlin_.clear();
610  std::vector<casadi_int> lin;
611  for (casadi_int c = 0; c < jac_in_.size(); ++c) {
612  if (is_nonlin[c]) {
613  nonlin_.push_back(c);
614  } else {
615  lin.push_back(c);
616  }
617  }
618  // Star-coloring to calculate Hessian
619  casadi_int max_hessian_colors = 0;
620  if (hessian_coloring_) {
621  // Star coloring
623  max_hessian_colors = hess_colors_.size2();
624  if (verbose_) casadi_message("Hessian graph coloring: " + str(nonlin_.size())
625  + " -> " + str(max_hessian_colors) + " directions");
626  // Zero out corresponding rows (should be handled in star_coloring call)
628  }
629  // Unidirectional coloring to calculate Hessian
631  // Both symmetric and asymmetric coloring supported
633  max_hessian_colors = std::max(max_hessian_colors, hess_uni_colors_.size2());
634  if (verbose_) casadi_message("Hessian unidirectional coloring with "
635  + str(hess_uni_colors_.size2()) + " directions");
636  // Zero out corresponding rows (should be handled in uni_coloring call)
638  }
639  // Dummy coloring: One color for each nonlinear variable
641  hess_uni_colors_ = Sparsity(jac_in_.size(), nonlin_.size(),
642  range(nonlin_.size() + 1), nonlin_);
643  max_hessian_colors = hess_uni_colors_.size2();
644  if (verbose_) {
645  casadi_message("Hessian calculation for " + str(nonlin_.size()) + " variables");
646  }
647  }
648 
649  // Number of threads to be used for Hessian calculation
650  max_hess_tasks_ = std::min(max_n_tasks_, max_hessian_colors);
651 
652  // Work vector for storing extended Hessian, shared between threads
653  alloc_w(hess_sp_.nnz(), true); // hess_nz
654 
655  // Work vector for perturbed adjoint sensitivities
656  alloc_w(max_hess_tasks_ * fmu_.n_in(), true); // pert_asens
657 
658  // Work vector for making symmetric or checking symmetry
660  }
661 
662  // Total number of threads used for Jacobian/adjoint calculation
663  // Note: Jacobian calculation also used for Hessian
665  if (verbose_) casadi_message("Allocated memory for " + str(max_n_tasks_) + " threads");
666 
667  // Work vectors for Jacobian/adjoint/Hessian calculation, for each thread
668  casadi_int jac_iw, jac_w;
669  casadi_jac_work(&jac_prob_, &jac_iw, &jac_w);
670  alloc_iw(max_n_tasks_ * jac_iw, true);
671  alloc_w(max_n_tasks_ * jac_w, true);
672 
673  // Work vectors for Jacobian calculation via adjoint derivatives, for each thread
675  casadi_jac_work(&adj_prob_, &jac_iw, &jac_w);
676  alloc_iw(max_n_tasks_ * jac_iw, true);
677  alloc_w(max_n_tasks_ * jac_w, true);
678  // Work vectors for casadi_trans
679  alloc_w(jac_sp_.nnz());
681  }
682 }
void init(const Dict &opts) override
Initialize.
std::vector< casadi_int > erase(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Erase rows and/or columns of a matrix.
Definition: sparsity.cpp:339
Sparsity star_coloring_new(std::vector< casadi_int > &which_color, const Dict &opts=Dict()) const
Perform a star coloring of a symmetric matrix:
Definition: sparsity.cpp:759
Sparsity uni_coloring(const Sparsity &AT=Sparsity(), casadi_int cutoff=std::numeric_limits< casadi_int >::max()) const
Perform a unidirectional coloring: A greedy distance-2 coloring algorithm.
Definition: sparsity.cpp:751

References abstol_, casadi::ADJ, adj_colors_, adj_prob_, adj_sp_, casadi::FunctionInternal::alloc_iw(), casadi::FunctionInternal::alloc_w(), asymmetric_hessian_coloring_, enable_adjoint_hessian_, enable_adjoint_jacobian_, enable_forward_jacobian_, casadi::Sparsity::erase(), fd_, fd_flip_, casadi::FunctionInternal::fd_method_, fmu_, casadi::get_ptr(), has_adj_, has_hess_, has_jac_, casadi::HESS, hess_colors_, hess_sp_, casadi::Fmu::hess_sparsity(), hess_uni_colors_, hessian_coloring_, in_, casadi::OutputStruct::ind, casadi::FunctionInternal::init(), casadi::Fmu::ired(), casadi::JAC, jac_colors_, jac_in_, jac_nom_in_, jac_out_, jac_prob_, jac_sp_, casadi::Fmu::jac_sparsity(), casadi::JAC_TRANS, make_symmetric_, casadi_jac_prob< T1 >::map_in, casadi_jac_prob< T1 >::map_out, max_hess_tasks_, max_jac_tasks_, max_n_tasks_, casadi::Fmu::n_in(), casadi::Fmu::n_out(), nadj_, new_forward_, new_hessian_, new_jacobian_, nfwd_, casadi::Sparsity::nnz(), casadi_jac_prob< T1 >::nom_in, casadi::Fmu::nominal_in(), nonlin_, casadi::Filesystem::ofstream_ptr(), casadi::OPENMP, casadi::Fmu::ored(), out_, parallelization_, print_progress_, casadi::Fmu::provides_adjoint_derivatives(), casadi::Fmu::provides_directional_derivatives(), casadi::range(), casadi::OutputStruct::rbegin, reltol_, casadi::OutputStruct::rend, casadi::Sparsity::row(), casadi::SERIAL, casadi::Sparsity::size1(), casadi::Sparsity::size2(), sp_trans_, sp_trans_map_, casadi::FunctionInternal::sparsity_out(), casadi::Sparsity::star_coloring_new(), step_, casadi::str(), casadi::Sparsity::T(), casadi::THREAD, casadi::to_string(), casadi::OutputStruct::type, casadi::Sparsity::uni_coloring(), uses_adjoint_derivatives_, uses_directional_derivatives_, validate_ad_file_, validate_forward_, validate_hessian_, casadi::ProtoFunction::verbose_, and which_hess_color_.

◆ init_mem()

int casadi::FmuFunction::init_mem ( void *  mem) const
overridevirtual

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

Reimplemented from casadi::ProtoFunction.

Definition at line 59 of file fmu_function.cpp.

59  {
60  casadi_assert(mem != nullptr, "Memory is null");
61  // Instantiate base classes
62  if (FunctionInternal::init_mem(mem)) return 1;
63  // Number of memory instances needed
64  casadi_int n_mem = std::max(static_cast<casadi_int>(1),
65  std::max(max_jac_tasks_, max_hess_tasks_));
66  // Initialize master and all slaves
67  FmuMemory* m = static_cast<FmuMemory*>(mem);
68  for (casadi_int i = 0; i < n_mem; ++i) {
69  // Initialize the memory object itself or a slave
70  FmuMemory* m1 = i == 0 ? m : m->slaves.at(i - 1);
71  if (fmu_.init_mem(m1)) return 1;
72  }
73  // Reset timers
74  m->n_get_all = m->n_get_directional = m->n_get_adjoint = 0;
75  m->t_get_all = m->t_get_directional = m->t_get_adjoint = 0;
76  // Make sure we can query stats, even before numerical evaluation
77  m->stats_available = true;
78  return 0;
79 }
int init_mem(FmuMemory *m) const
Initalize memory block.
Definition: fmu.cpp:270

References fmu_, casadi::Fmu::init_mem(), casadi::ProtoFunction::init_mem(), max_hess_tasks_, max_jac_tasks_, casadi::FmuMemory::n_get_adjoint, casadi::FmuMemory::n_get_all, casadi::FmuMemory::n_get_directional, casadi::FmuMemory::slaves, casadi::FunctionMemory::stats_available, casadi::FmuMemory::t_get_adjoint, casadi::FmuMemory::t_get_all, and casadi::FmuMemory::t_get_directional.

◆ initSingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::initSingleton ( )
inlineprotectedinherited

Called in the constructor of singletons to avoid that the counter reaches zero

Definition at line 71 of file generic_shared_internal.hpp.

71  {
72  casadi_assert_dev(static_cast<Internal*>(this)->count==0);
73  static_cast<Internal*>(this)->count++;
74  }

◆ instruction_constant()

double casadi::FunctionInternal::instruction_constant ( casadi_int  k) const
virtualinherited

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

Reimplemented in casadi::SXFunction.

Definition at line 3649 of file function_internal.cpp.

3649  {
3650  casadi_error("'instruction_constant' not defined for " + class_name());
3651  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_id()

casadi_int casadi::FunctionInternal::instruction_id ( casadi_int  k) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3641 of file function_internal.cpp.

3641  {
3642  casadi_error("'instruction_id' not defined for " + class_name());
3643  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_input()

std::vector< casadi_int > casadi::FunctionInternal::instruction_input ( casadi_int  k) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3645 of file function_internal.cpp.

3645  {
3646  casadi_error("'instruction_input' not defined for " + class_name());
3647  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_MX()

MX casadi::FunctionInternal::instruction_MX ( casadi_int  k) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 3657 of file function_internal.cpp.

3657  {
3658  casadi_error("'instruction_MX' not defined for " + class_name());
3659  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_output()

std::vector< casadi_int > casadi::FunctionInternal::instruction_output ( casadi_int  k) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3653 of file function_internal.cpp.

3653  {
3654  casadi_error("'instruction_output' not defined for " + class_name());
3655  }

References casadi::SharedObjectInternal::class_name().

◆ instructions_sx()

SX casadi::FunctionInternal::instructions_sx ( ) const
virtualinherited

Reimplemented in casadi::SXFunction.

Definition at line 3661 of file function_internal.cpp.

3661  {
3662  casadi_error("'instructions_sx' not defined for " + class_name());
3663  }

References casadi::SharedObjectInternal::class_name().

◆ is_a()

bool casadi::FunctionInternal::is_a ( const std::string &  type,
bool  recursive 
) const
virtualinherited

◆ jac_is_symm()

bool casadi::FunctionInternal::jac_is_symm ( casadi_int  oind,
casadi_int  iind 
) const
virtualinherited

Definition at line 1973 of file function_internal.cpp.

1973  {
1974  // If derivative expression
1975  if (!derivative_of_.is_null()) {
1976  std::string n = derivative_of_.name();
1977  // Reverse move
1978  if (name_ == "adj1_" + n) {
1979  if (iind == oind) return true;
1980  }
1981  }
1982  // Not symmetric by default
1983  return false;
1984  }

References casadi::FunctionInternal::derivative_of_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Function::name(), and casadi::ProtoFunction::name_.

◆ jac_sparsity()

Sparsity & casadi::FunctionInternal::jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  compact,
bool  symmetric 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kz Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 2061 of file function_internal.cpp.

2062  {
2063 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
2064  // Safe access to jac_sparsity_
2065  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
2066 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
2067  // If first call, allocate cache
2068  for (bool c : {false, true}) {
2069  if (jac_sparsity_[c].empty()) jac_sparsity_[c].resize(n_in_ * n_out_);
2070  }
2071  // Flat index
2072  casadi_int ind = iind + oind * n_in_;
2073  // Reference to the block
2074  Sparsity& jsp = jac_sparsity_[compact].at(ind);
2075  // If null, generate
2076  if (jsp.is_null()) {
2077  // Use (non)-compact pattern, if given
2078  Sparsity& jsp_other = jac_sparsity_[!compact].at(ind);
2079  if (!jsp_other.is_null()) {
2080  jsp = compact ? to_compact(oind, iind, jsp_other) : from_compact(oind, iind, jsp_other);
2081  } else {
2082  // Generate pattern
2083  Sparsity sp;
2084  bool sp_is_compact;
2085  if (!is_diff_out_.at(oind) || !is_diff_in_.at(iind)) {
2086  // All-zero sparse
2087  sp = Sparsity(nnz_out(oind), nnz_in(iind));
2088  sp_is_compact = true;
2089  } else {
2090  // Use internal routine to determine sparsity
2091  if (has_spfwd() || has_sprev() || has_jac_sparsity(oind, iind)) {
2092  sp = get_jac_sparsity(oind, iind, symmetric);
2093  }
2094  // If null, dense
2095  if (sp.is_null()) sp = Sparsity::dense(nnz_out(oind), nnz_in(iind));
2096  // Is the return the compact pattern?
2097  sp_is_compact = sp.size1() == nnz_out(oind) && sp.size2() == nnz_in(iind);
2098  }
2099  // Save to cache and convert if needed
2100  if (sp_is_compact == compact) {
2101  jsp = sp;
2102  } else {
2103  jsp_other = sp;
2104  jsp = compact ? to_compact(oind, iind, sp) : from_compact(oind, iind, sp);
2105  }
2106  }
2107  }
2108 
2109  // Make sure the Jacobian is symmetric if requested, cf. #1522, #3074, #3134
2110  if (symmetric) {
2111  if (compact) {
2112  Sparsity sp = from_compact(oind, iind, jsp);
2113  if (!sp.is_symmetric()) {
2114  sp = sp * sp.T();
2115  jsp = to_compact(oind, iind, sp);
2116  }
2117  } else {
2118  if (!jsp.is_symmetric()) jsp = jsp * jsp.T();
2119  }
2120  }
2121 
2122  // Return a reference to the block
2123  return jsp;
2124  }
virtual bool has_sprev() const
Is the class able to propagate seeds through the algorithm?
std::vector< Sparsity > jac_sparsity_[2]
Cache for sparsities of the Jacobian blocks.
Sparsity to_compact(casadi_int oind, casadi_int iind, const Sparsity &sp) const
Convert to compact Jacobian sparsity pattern.
virtual bool has_jac_sparsity(casadi_int oind, casadi_int iind) const
Get Jacobian sparsity.
Sparsity from_compact(casadi_int oind, casadi_int iind, const Sparsity &sp) const
Convert from compact Jacobian sparsity pattern.
virtual Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const
Get Jacobian sparsity.

References casadi::Sparsity::dense(), casadi::FunctionInternal::from_compact(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::has_jac_sparsity(), casadi::FunctionInternal::has_spfwd(), casadi::FunctionInternal::has_sprev(), casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Sparsity::is_symmetric(), casadi::FunctionInternal::jac_sparsity_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Sparsity::T(), and casadi::FunctionInternal::to_compact().

Referenced by casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::sp_forward_block(), and casadi::FunctionInternal::sp_reverse().

◆ jacobian()

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

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

Definition at line 2461 of file function_internal.cpp.

2461  {
2462  // Used wrapped function if jacobian not available
2463  if (!has_jacobian()) {
2464  // Derivative information must be available
2465  casadi_assert(has_derivative(),
2466  "Derivatives cannot be calculated for " + name_);
2467  return wrap().jacobian();
2468  }
2469  // Retrieve/generate cached
2470  Function f;
2471  std::string fname = "jac_" + name_;
2472  if (!incache(fname, f)) {
2473  // Names of inputs
2474  std::vector<std::string> inames;
2475  for (casadi_int i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2476  for (casadi_int i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2477  // Names of outputs
2478  std::vector<std::string> onames;
2479  onames.reserve(n_in_ * n_out_);
2480  for (size_t oind = 0; oind < n_out_; ++oind) {
2481  for (size_t iind = 0; iind < n_in_; ++iind) {
2482  onames.push_back("jac_" + name_out_[oind] + "_" + name_in_[iind]);
2483  }
2484  }
2485  // Options
2487  opts["derivative_of"] = self();
2488  // Generate derivative function
2489  casadi_assert_dev(enable_jacobian_);
2490  f = get_jacobian(fname, inames, onames, opts);
2491  // Consistency checks
2492  casadi_assert(f.n_in() == inames.size(),
2493  "Mismatching input signature, expected " + str(inames));
2494  casadi_assert(f.n_out() == onames.size(),
2495  "Mismatching output signature, expected " + str(onames));
2496  // Save to cache
2497  tocache_if_missing(f);
2498  }
2499  return f;
2500  }
virtual bool has_jacobian() const
Return Jacobian of all input elements with respect to all output elements.
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.
Function jacobian() const
Calculate all Jacobian blocks.
Definition: function.cpp:1068

References casadi::combine(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::enable_jacobian_, casadi::FunctionInternal::get_jacobian(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_jacobian(), casadi::FunctionInternal::incache(), casadi::Function::jacobian(), casadi::FunctionInternal::jacobian_options_, casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), and casadi::Function::jacobian().

◆ jit_dependencies()

virtual void casadi::FunctionInternal::jit_dependencies ( const std::string &  fname)
inlinevirtualinherited

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

Reimplemented in casadi::OracleFunction.

Definition at line 950 of file function_internal.hpp.

950 {}

Referenced by casadi::FunctionInternal::finalize().

◆ map()

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

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

Definition at line 1200 of file function_internal.cpp.

1200  {
1201  Function f;
1202  if (parallelization=="serial") {
1203  // Serial maps are cached
1204  std::string fname = "map" + str(n) + "_" + name_;
1205  if (!incache(fname, f)) {
1206  // Create new serial map
1207  f = Map::create(parallelization, self(), n);
1208  casadi_assert_dev(f.name()==fname);
1209  // Save in cache
1210  tocache_if_missing(f);
1211  }
1212  } else {
1213  // Non-serial maps are not cached
1214  f = Map::create(parallelization, self(), n);
1215  }
1216  return f;
1217  }
static Function create(const std::string &parallelization, const Function &f, casadi_int n)
Definition: map.cpp:39

References casadi::Map::create(), casadi::FunctionInternal::incache(), casadi::Function::name(), casadi::ProtoFunction::name_, casadi::str(), and casadi::FunctionInternal::tocache_if_missing().

Referenced by casadi::Dple::get_forward(), casadi::Dple::get_reverse(), and casadi::FunctionInternal::mapsum_mx().

◆ mapsum_mx()

std::vector< MX > casadi::FunctionInternal::mapsum_mx ( const std::vector< MX > &  arg,
const std::string &  parallelization 
)
inherited

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

Definition at line 3670 of file function_internal.cpp.

3671  {
3672  if (x.empty()) return x;
3673  // Check number of arguments
3674  casadi_assert(x.size()==n_in_, "mapsum_mx: Wrong number_i of arguments");
3675  // Number of parallel calls
3676  casadi_int npar = 1;
3677  // Check/replace arguments
3678  std::vector<MX> x_mod(x.size());
3679  for (casadi_int i=0; i<n_in_; ++i) {
3680  if (check_mat(x[i].sparsity(), sparsity_in_[i], npar)) {
3681  x_mod[i] = replace_mat(x[i], sparsity_in_[i], npar);
3682  } else {
3683  // Mismatching sparsity: The following will throw an error message
3684  npar = 0;
3685  check_arg(x, npar);
3686  }
3687  }
3688 
3689  casadi_int n = 1;
3690  for (casadi_int i=0; i<x_mod.size(); ++i) {
3691  n = std::max(x_mod[i].size2() / size2_in(i), n);
3692  }
3693 
3694  std::vector<casadi_int> reduce_in;
3695  for (casadi_int i=0; i<x_mod.size(); ++i) {
3696  if (x_mod[i].size2()/size2_in(i)!=n) {
3697  reduce_in.push_back(i);
3698  }
3699  }
3700 
3701  Function ms = self().map("mapsum", parallelization, n, reduce_in, range(n_out_));
3702 
3703  // Call the internal function
3704  return ms(x_mod);
3705  }
Function map(casadi_int n, const std::string &parallelization) const
Generate/retrieve cached serial map.
void check_arg(const std::vector< M > &arg, casadi_int &npar) const
Check if input arguments have correct length and dimensions.
M replace_mat(const M &arg, const Sparsity &inp, casadi_int npar)

References casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::map(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::range(), casadi::replace_mat(), casadi::FunctionInternal::size2_in(), and casadi::FunctionInternal::sparsity_in_.

◆ matching_arg()

template<typename M >
bool casadi::FunctionInternal::matching_arg ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

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

Definition at line 1808 of file function_internal.hpp.

1808  {
1809  check_arg(arg, npar);
1810  for (casadi_int i=0; i<n_in_; ++i) {
1811  if (arg.at(i).size1()!=size1_in(i)) return false;
1812  if (arg.at(i).size2()!=size2_in(i) && arg.at(i).size2()!=npar*size2_in(i)) return false;
1813  }
1814  return true;
1815  }

References casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::size1_in(), and casadi::FunctionInternal::size2_in().

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::FunctionInternal::call(), casadi::FunctionInternal::call_forward(), and casadi::FunctionInternal::nz_in().

◆ matching_res()

template<typename M >
bool casadi::FunctionInternal::matching_res ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

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

Definition at line 1818 of file function_internal.hpp.

1818  {
1819  check_res(res, npar);
1820  for (casadi_int i=0; i<n_out_; ++i) {
1821  if (res.at(i).size1()!=size1_out(i)) return false;
1822  if (res.at(i).size2()!=size2_out(i) && res.at(i).size2()!=npar*size2_out(i)) return false;
1823  }
1824  return true;
1825  }
void check_res(const std::vector< M > &res, casadi_int &npar) const
Check if output arguments have correct length and dimensions.

References casadi::FunctionInternal::check_res(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::size1_out(), and casadi::FunctionInternal::size2_out().

Referenced by casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::call_reverse(), and casadi::FunctionInternal::nz_out().

◆ memory()

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

Definition at line 3905 of file function_internal.cpp.

3905  {
3906 #ifdef CASADI_WITH_THREAD
3907  std::lock_guard<std::mutex> lock(mtx_);
3908 #endif //CASADI_WITH_THREAD
3909  return mem_.at(ind);
3910  }

Referenced by casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::Sqpmethod::solve_ela_QP(), and casadi::Sqpmethod::solve_QP().

◆ merge()

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

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

Reimplemented in casadi::BlazingSplineFunction.

Definition at line 3620 of file function_internal.cpp.

3621  {
3622  }

◆ mx_in() [1/2]

const std::vector< MX > casadi::FunctionInternal::mx_in ( ) const
virtualinherited

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

Reimplemented in casadi::MXFunction.

Definition at line 3600 of file function_internal.cpp.

3600  {
3601  std::vector<MX> ret(n_in_);
3602  for (casadi_int i=0; i<ret.size(); ++i) {
3603  ret[i] = mx_in(i);
3604  }
3605  return ret;
3606  }
virtual const std::vector< MX > mx_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

Referenced by casadi::Nlpsol::get_forward(), casadi::LinearInterpolantJac::get_jacobian(), casadi::Nlpsol::get_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ mx_in() [2/2]

const MX casadi::FunctionInternal::mx_in ( casadi_int  ind) const
virtualinherited

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

Reimplemented in casadi::MXFunction.

Definition at line 3592 of file function_internal.cpp.

3592  {
3593  return MX::sym(name_in_.at(ind), sparsity_in(ind));
3594  }
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.

References casadi::FunctionInternal::name_in_, casadi::FunctionInternal::sparsity_in(), and casadi::GenericMatrix< MX >::sym().

◆ mx_out() [1/2]

const std::vector< MX > casadi::FunctionInternal::mx_out ( ) const
virtualinherited

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

Definition at line 3608 of file function_internal.cpp.

3608  {
3609  std::vector<MX> ret(n_out_);
3610  for (casadi_int i=0; i<ret.size(); ++i) {
3611  ret[i] = mx_out(i);
3612  }
3613  return ret;
3614  }
virtual const std::vector< MX > mx_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

Referenced by casadi::Nlpsol::get_forward(), and casadi::Nlpsol::get_reverse().

◆ mx_out() [2/2]

const MX casadi::FunctionInternal::mx_out ( casadi_int  ind) const
virtualinherited

◆ n_instructions()

casadi_int casadi::FunctionInternal::n_instructions ( ) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3637 of file function_internal.cpp.

3637  {
3638  casadi_error("'n_instructions' not defined for " + class_name());
3639  }

References casadi::SharedObjectInternal::class_name().

◆ n_nodes()

casadi_int casadi::FunctionInternal::n_nodes ( ) const
virtualinherited

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

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3665 of file function_internal.cpp.

3665  {
3666  casadi_error("'n_nodes' not defined for " + class_name());
3667  }

References casadi::SharedObjectInternal::class_name().

◆ nnz_in() [1/2]

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

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

Definition at line 2420 of file function_internal.cpp.

2420  {
2421  casadi_int ret=0;
2422  for (casadi_int iind=0; iind<n_in_; ++iind) ret += nnz_in(iind);
2423  return ret;
2424  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::adjViaJac(), casadi::FunctionInternal::call_gen(), casadi::JitFunction::codegen_body(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::eval_gen(), casadi::CallbackInternal::finalize(), casadi::FunctionInternal::from_compact(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::generate_in(), casadi::FunctionInternal::get_jac_sparsity(), casadi::Expm::get_jac_sparsity(), get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::JitFunction::init(), casadi::Nlpsol::init(), casadi::CbcInterface::init(), casadi::ClpInterface::init(), casadi::CplexInterface::init(), casadi::OoqpInterface::init(), casadi::ProxqpInterface::init(), casadi::QpoasesInterface::init(), casadi::ImplicitToNlp::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::open_trace(), casadi::ImplicitToNlp::set_work(), casadi::CbcInterface::solve(), casadi::ClpInterface::solve(), casadi::CplexInterface::solve(), casadi::OoqpInterface::solve(), casadi::PiqpInterface::solve(), casadi::ProxqpInterface::solve(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FunctionInternal::sp_forward(), and casadi::FunctionInternal::sp_reverse().

◆ nnz_in() [2/2]

casadi_int casadi::FunctionInternal::nnz_in ( casadi_int  ind) const
inlineinherited

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

Definition at line 1010 of file function_internal.hpp.

1010 { return sparsity_in(ind).nnz(); }

◆ nnz_out() [1/2]

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

◆ nnz_out() [2/2]

casadi_int casadi::FunctionInternal::nnz_out ( casadi_int  ind) const
inlineinherited

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

Definition at line 1012 of file function_internal.hpp.

1012 { return sparsity_out(ind).nnz(); }

◆ numel_in() [1/2]

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

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

Definition at line 2432 of file function_internal.cpp.

2432  {
2433  casadi_int ret=0;
2434  for (casadi_int iind=0; iind<n_in_; ++iind) ret += numel_in(iind);
2435  return ret;
2436  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::from_compact(), and casadi::Integrator::get_reverse().

◆ numel_in() [2/2]

casadi_int casadi::FunctionInternal::numel_in ( casadi_int  ind) const
inlineinherited

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

Definition at line 1020 of file function_internal.hpp.

1020 { return sparsity_in(ind).numel(); }
casadi_int numel() const
The total number of elements, including structural zeros, i.e. size2()*size1()
Definition: sparsity.cpp:132

◆ numel_out() [1/2]

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

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

Definition at line 2438 of file function_internal.cpp.

2438  {
2439  casadi_int ret=0;
2440  for (casadi_int oind=0; oind<n_out_; ++oind) ret += numel_out(oind);
2441  return ret;
2442  }

References casadi::FunctionInternal::n_out_.

Referenced by casadi::FunctionInternal::from_compact(), and casadi::Integrator::get_reverse().

◆ numel_out() [2/2]

casadi_int casadi::FunctionInternal::numel_out ( casadi_int  ind) const
inlineinherited

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

Definition at line 1021 of file function_internal.hpp.

1021 { return sparsity_out(ind).numel(); }

◆ nz_in() [1/2]

std::vector< double > casadi::FunctionInternal::nz_in ( const std::vector< DM > &  arg) const
inherited

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

Definition at line 3760 of file function_internal.cpp.

3760  {
3761  // Disallow parallel inputs
3762  casadi_int npar = -1;
3763  if (!matching_arg(arg, npar)) {
3764  return nz_in(replace_arg(arg, npar));
3765  }
3766 
3767  std::vector<DM> arg2 = project_arg(arg, 1);
3768  std::vector<double> ret(nnz_in());
3769  casadi_int offset = 0;
3770  for (casadi_int i=0;i<n_in_;++i) {
3771  const double* e = arg2.at(i).ptr();
3772  std::copy(e, e+nnz_in(i), ret.begin()+offset);
3773  offset+= nnz_in(i);
3774  }
3775  return ret;
3776  }

References casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::project_arg(), and casadi::FunctionInternal::replace_arg().

Referenced by casadi::SXFunction::call_activity(), casadi::SXFunction::call_fwd(), casadi::SXFunction::call_rev(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), and casadi::FunctionInternal::get_jac_sparsity_hierarchical().

◆ nz_in() [2/2]

std::vector< DM > casadi::FunctionInternal::nz_in ( const std::vector< double > &  arg) const
inherited

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

Definition at line 3730 of file function_internal.cpp.

3730  {
3731  casadi_assert(nnz_in()==arg.size(),
3732  "Dimension mismatch. Expecting " + str(nnz_in()) +
3733  ", got " + str(arg.size()) + " instead.");
3734 
3735  std::vector<DM> ret = dm_in();
3736  casadi_int offset = 0;
3737  for (casadi_int i=0;i<n_in_;++i) {
3738  DM& r = ret.at(i);
3739  std::copy(arg.begin()+offset, arg.begin()+offset+nnz_in(i), r.ptr());
3740  offset+= nnz_in(i);
3741  }
3742  return ret;
3743  }
Matrix< double > DM
Definition: dm_fwd.hpp:33

References casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::Matrix< Scalar >::ptr(), and casadi::str().

◆ nz_out() [1/2]

std::vector< double > casadi::FunctionInternal::nz_out ( const std::vector< DM > &  res) const
inherited

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

Definition at line 3778 of file function_internal.cpp.

3778  {
3779  // Disallow parallel inputs
3780  casadi_int npar = -1;
3781  if (!matching_res(res, npar)) {
3782  return nz_out(replace_res(res, npar));
3783  }
3784 
3785  std::vector<DM> res2 = project_res(res, 1);
3786  std::vector<double> ret(nnz_out());
3787  casadi_int offset = 0;
3788  for (casadi_int i=0;i<n_out_;++i) {
3789  const double* e = res2.at(i).ptr();
3790  std::copy(e, e+nnz_out(i), ret.begin()+offset);
3791  offset+= nnz_out(i);
3792  }
3793  return ret;
3794  }
std::vector< M > project_res(const std::vector< M > &arg, casadi_int npar) const
Project sparsities.
std::vector< M > replace_res(const std::vector< M > &res, casadi_int npar) const
Replace 0-by-0 outputs.

References casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::project_res(), and casadi::FunctionInternal::replace_res().

Referenced by casadi::SXFunction::call_activity(), casadi::SXFunction::call_fwd(), casadi::SXFunction::call_rev(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), and casadi::FunctionInternal::get_jac_sparsity_hierarchical().

◆ nz_out() [2/2]

std::vector< DM > casadi::FunctionInternal::nz_out ( const std::vector< double > &  res) const
inherited

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

Definition at line 3745 of file function_internal.cpp.

3745  {
3746  casadi_assert(nnz_out()==res.size(),
3747  "Dimension mismatch. Expecting " + str(nnz_out()) +
3748  ", got " + str(res.size()) + " instead.");
3749 
3750  std::vector<DM> ret = dm_out();
3751  casadi_int offset = 0;
3752  for (casadi_int i=0;i<n_out_;++i) {
3753  DM& r = ret.at(i);
3754  std::copy(res.begin()+offset, res.begin()+offset+nnz_out(i), r.ptr());
3755  offset+= nnz_out(i);
3756  }
3757  return ret;
3758  }

References casadi::FunctionInternal::dm_out(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::Matrix< Scalar >::ptr(), and casadi::str().

◆ open_trace()

std::unique_ptr< std::ostream > casadi::FunctionInternal::open_trace ( const double **  arg,
casadi_int  dump_id 
) const
protectedinherited

Definition at line 847 of file function_internal.cpp.

848  {
849  if (dump_id < 0) dump_id = get_dump_id();
850  std::stringstream filename;
851  filename << dump_dir_ << filesep() << name_ << "." << std::setfill('0')
852  << std::setw(6) << dump_id << ".trace.jsonl";
853  auto output = Filesystem::ofstream_ptr(filename.str());
854  std::ostream& trace = *output;
855  normalized_setup(trace);
856  trace << "{\"event\":\"header\",\"format\":\"casadi_trace\",\"version\":1,"
857  << "\"function\":\"" << name_ << "\",\"type\":\"" << class_name()
858  << "\",\"dump_id\":" << dump_id << "}\n";
859  trace << "{\"event\":\"inputs\",\"values\":[";
860  for (casadi_int i = 0; i < n_in_; ++i) {
861  if (i) trace << ",";
862  trace_values(trace, arg[i], nnz_in(i));
863  }
864  trace << "]}\n";
865  return output;
866  }
std::string filesep()
Definition: casadi_os.cpp:71
std::string filename(const std::string &path)
Definition: ghc.cpp:55

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::dump_dir_, casadi::filename(), casadi::filesep(), casadi::FunctionInternal::n_in_, casadi::ProtoFunction::name_, casadi::FunctionInternal::nnz_in(), casadi::normalized_setup(), casadi::Filesystem::ofstream_ptr(), and casadi::FunctionInternal::trace_values().

Referenced by casadi::MXFunction::eval(), and casadi::SXFunction::eval().

◆ oracle()

const Function & casadi::FunctionInternal::oracle ( ) const
virtualinherited

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

Reimplemented in casadi::OracleFunction.

Definition at line 3997 of file function_internal.cpp.

3997  {
3998  casadi_error("'oracle' not defined for " + class_name());
3999  static Function singleton;
4000  return singleton;
4001  }

References casadi::SharedObjectInternal::class_name().

Referenced by casadi::Function::oracle(), and casadi::DaeBuilder::oracle().

◆ print()

void casadi::ProtoFunction::print ( const char *  fmt,
  ... 
) const
inherited

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

Definition at line 4158 of file function_internal.cpp.

4158  {
4159  // Variable number of arguments
4160  va_list args;
4161  va_start(args, fmt);
4162  // Static & dynamic buffers
4163  char buf[256];
4164  size_t buf_sz = sizeof(buf);
4165  char* buf_dyn = nullptr;
4166  // Try to print with a small buffer
4167  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
4168  // Need a larger buffer?
4169  if (n>static_cast<casadi_int>(buf_sz)) {
4170  buf_sz = static_cast<size_t>(n+1);
4171  buf_dyn = new char[buf_sz];
4172  n = vsnprintf(buf_dyn, buf_sz, fmt, args);
4173  }
4174  // Print buffer content
4175  if (n>=0) uout() << (buf_dyn ? buf_dyn : buf) << std::flush;
4176  // Cleanup
4177  delete[] buf_dyn;
4178  va_end(args);
4179  // Throw error if failure
4180  casadi_assert(n>=0, "Print failure while processing '" + std::string(fmt) + "'");
4181  }

References casadi::uout().

Referenced by casadi::Feasiblesqpmethod::anderson_acc_step_update(), casadi::Nlpsol::callback(), casadi::Blocksqp::convertHessian(), eval_task(), casadi::Feasiblesqpmethod::feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::Blocksqp::fullstep(), casadi::Blocksqp::init(), casadi::Feasiblesqpmethod::init(), casadi::Ipqp::init(), casadi::Qrqp::init(), casadi::Qrsqp::init(), casadi::Sqpmethod::init(), casadi::LinsolQr::nfact(), casadi::Feasiblesqpmethod::print_iteration(), casadi::Qrsqp::print_iteration(), casadi::Sqpmethod::print_iteration(), casadi::SundialsInterface::print_stats(), casadi::ProtoFunction::print_time(), casadi::Blocksqp::printInfo(), casadi::Blocksqp::printProgress(), casadi::Blocksqp::run(), casadi::Blocksqp::solve(), casadi::Feasiblesqpmethod::solve(), casadi::Qrsqp::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Sqpmethod::solve_QP(), and casadi::Blocksqp::solveQP().

◆ print_canonical() [1/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
casadi_int  sz,
const double *  nz 
)
staticinherited

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

Definition at line 966 of file function_internal.cpp.

966  {
967  StreamStateGuard backup(stream);
968  normalized_setup(stream);
969  if (nz) {
970  stream << "[";
971  for (casadi_int i=0; i<sz; ++i) {
972  if (i>0) stream << ", ";
973  normalized_out(stream, nz[i]);
974  }
975  stream << "]";
976  } else {
977  stream << "NULL";
978  }
979  }

References casadi::normalized_out(), and casadi::normalized_setup().

◆ print_canonical() [2/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
const Sparsity &  sp,
const double *  nz 
)
staticinherited

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

Definition at line 981 of file function_internal.cpp.

982  {
983  StreamStateGuard backup(stream);
984  normalized_setup(stream);
985  if (nz) {
986  if (!sp.is_scalar(true)) {
987  stream << sp.dim(false) << ": ";
988  stream << "[";
989  }
990  for (casadi_int i=0; i<sp.nnz(); ++i) {
991  if (i>0) stream << ", ";
992  normalized_out(stream, nz[i]);
993  }
994  if (!sp.is_scalar(true)) {
995  stream << "]";
996  if (!sp.is_dense()) {
997  stream << ", colind: [";
998  for (casadi_int i=0; i<sp.size2()+1; ++i) {
999  if (i>0) stream << ", ";
1000  stream << sp.colind()[i];
1001  }
1002  stream << "]";
1003  stream << ", row: [";
1004  for (casadi_int i=0; i<sp.nnz(); ++i) {
1005  if (i>0) stream << ", ";
1006  stream << sp.row()[i];
1007  }
1008  stream << "]";
1009  }
1010  }
1011  } else {
1012  stream << "NULL";
1013  }
1014  }

References casadi::Sparsity::colind(), casadi::Sparsity::dim(), casadi::Sparsity::is_dense(), casadi::Sparsity::is_scalar(), casadi::Sparsity::nnz(), casadi::normalized_out(), casadi::normalized_setup(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::Monitor::eval(), casadi::MXFunction::print_arg(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_out(), casadi::MXFunction::print_res(), and casadi::SXFunction::print_res().

◆ print_canonical() [3/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
double  a 
)
staticinherited

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

Definition at line 1016 of file function_internal.cpp.

1016  {
1017  StreamStateGuard backup(stream);
1018  normalized_setup(stream);
1019  normalized_out(stream, a);
1020  }

References casadi::normalized_out(), and casadi::normalized_setup().

◆ print_dimensions()

void casadi::FunctionInternal::print_dimensions ( std::ostream &  stream) const
inherited

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

Definition at line 1092 of file function_internal.cpp.

1092  {
1093  stream << " Number of inputs: " << n_in_ << std::endl;
1094  for (casadi_int i=0; i<n_in_; ++i) {
1095  stream << " Input " << i << " (\"" << name_in_[i] << "\"): "
1096  << sparsity_in_[i].dim() << std::endl;
1097  }
1098  stream << " Number of outputs: " << n_out_ << std::endl;
1099  for (casadi_int i=0; i<n_out_; ++i) {
1100  stream << " Output " << i << " (\"" << name_out_[i] << "\"): "
1101  << sparsity_out_[i].dim() << std::endl;
1102  }
1103  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

◆ print_in()

void casadi::FunctionInternal::print_in ( std::ostream &  stream,
const double **  arg,
bool  truncate 
) const
inherited

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

Definition at line 932 of file function_internal.cpp.

932  {
933  stream << "Function " << name_ << " (" << this << ")" << std::endl;
934  for (casadi_int i=0; i<n_in_; ++i) {
935  stream << "Input " << i << " (" << name_in_[i] << "): ";
936  if (arg[i]) {
937  if (print_canonical_) {
938  print_canonical(stream, sparsity_in_[i], arg[i]);
939  } else {
940  DM::print_default(stream, sparsity_in_[i], arg[i], truncate);
941  }
942  stream << std::endl;
943  } else {
944  stream << "NULL" << std::endl;
945  }
946  }
947  }
static void print_canonical(std::ostream &stream, const Sparsity &sp, const double *nz)
Print canonical representation of a numeric matrix.
static void print_default(std::ostream &stream, const Sparsity &sp, const double *nonzeros, bool truncate=true)
Print default style.

References casadi::FunctionInternal::n_in_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::print_canonical(), casadi::FunctionInternal::print_canonical_, casadi::Matrix< double >::print_default(), and casadi::FunctionInternal::sparsity_in_.

Referenced by casadi::FunctionInternal::eval_gen().

◆ print_option()

void casadi::ProtoFunction::print_option ( const std::string &  name,
std::ostream &  stream 
) const
inherited

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

Definition at line 1109 of file function_internal.cpp.

1109  {
1110  get_options().print_one(name, stream);
1111  }
void print_one(const std::string &name, std::ostream &stream) const
Print all information there is to know about a certain option.
Definition: options.cpp:274

References casadi::ProtoFunction::get_options(), and casadi::Options::print_one().

◆ print_options()

void casadi::ProtoFunction::print_options ( std::ostream &  stream) const
inherited

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

Definition at line 1105 of file function_internal.cpp.

1105  {
1106  get_options().print_all(stream);
1107  }
void print_all(std::ostream &stream) const
Print list of options.
Definition: options.cpp:268

References casadi::ProtoFunction::get_options(), and casadi::Options::print_all().

◆ print_out()

void casadi::FunctionInternal::print_out ( std::ostream &  stream,
double **  res,
bool  truncate 
) const
inherited

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

Definition at line 949 of file function_internal.cpp.

949  {
950  stream << "Function " << name_ << " (" << this << ")" << std::endl;
951  for (casadi_int i=0; i<n_out_; ++i) {
952  stream << "Output " << i << " (" << name_out_[i] << "): ";
953  if (res[i]) {
954  if (print_canonical_) {
955  print_canonical(stream, sparsity_out_[i], res[i]);
956  } else {
957  DM::print_default(stream, sparsity_out_[i], res[i], truncate);
958  }
959  stream << std::endl;
960  } else {
961  stream << "NULL" << std::endl;
962  }
963  }
964  }

References casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::print_canonical(), casadi::FunctionInternal::print_canonical_, casadi::Matrix< double >::print_default(), and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::eval_gen().

◆ print_time()

void casadi::ProtoFunction::print_time ( const std::map< std::string, FStats > &  fstats) const
inherited

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

Definition at line 4078 of file function_internal.cpp.

4078  {
4079  if (!print_time_) return;
4080  // Length of the name being printed
4081  size_t name_len=0;
4082  for (auto &&s : fstats) {
4083  name_len = std::max(s.first.size(), name_len);
4084  }
4085  name_len = std::max(name_.size(), name_len);
4086 
4087  // Print name with a given length. Format: "%NNs "
4088  char namefmt[10];
4089  sprint(namefmt, sizeof(namefmt), "%%%ds ", static_cast<casadi_int>(name_len));
4090 
4091  // Print header
4092  print(namefmt, name_.c_str());
4093 
4094  print(" : %8s %10s %8s %10s %9s\n", "t_proc", "(avg)", "t_wall", "(avg)", "n_eval");
4095 
4096 
4097  char buffer_proc[10];
4098  char buffer_wall[10];
4099  char buffer_proc_avg[10];
4100  char buffer_wall_avg[10];
4101 
4102  // Print keys
4103  for (const auto &s : fstats) {
4104  if (s.second.n_call!=0) {
4105  print(namefmt, s.first.c_str());
4106  format_time(buffer_proc, s.second.t_proc);
4107  format_time(buffer_wall, s.second.t_wall);
4108  format_time(buffer_proc_avg, s.second.t_proc/s.second.n_call);
4109  format_time(buffer_wall_avg, s.second.t_wall/s.second.n_call);
4110  print(" | %s (%s) %s (%s) %9d\n",
4111  buffer_proc, buffer_proc_avg,
4112  buffer_wall, buffer_wall_avg, s.second.n_call);
4113  }
4114  }
4115  }
void format_time(char *buffer, double time) const
Format time in a fixed width 8 format.

References casadi::ProtoFunction::format_time(), casadi::ProtoFunction::name_, casadi::ProtoFunction::print(), casadi::ProtoFunction::print_time_, and casadi::ProtoFunction::sprint().

Referenced by casadi::FunctionInternal::eval_gen().

◆ project_arg()

template<typename M >
std::vector< M > casadi::FunctionInternal::project_arg ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

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

Definition at line 1680 of file function_internal.hpp.

1681  {
1682  casadi_assert_dev(arg.size()==n_in_);
1683 
1684  // Which arguments require mapped evaluation
1685  std::vector<bool> mapped(n_in_);
1686  for (casadi_int i=0; i<n_in_; ++i) {
1687  mapped[i] = arg[i].size2()!=size2_in(i);
1688  }
1689 
1690  // Check if matching input sparsity
1691  std::vector<bool> matching(n_in_);
1692  bool any_mismatch = false;
1693  for (casadi_int i=0; i<n_in_; ++i) {
1694  if (mapped[i]) {
1695  matching[i] = arg[i].sparsity().is_stacked(sparsity_in(i), npar);
1696  } else {
1697  matching[i] = arg[i].sparsity()==sparsity_in(i);
1698  }
1699  any_mismatch = any_mismatch || !matching[i];
1700  }
1701 
1702  // Correct input sparsity
1703  if (any_mismatch) {
1704  std::vector<M> arg2(arg);
1705  for (casadi_int i=0; i<n_in_; ++i) {
1706  if (!matching[i]) {
1707  if (mapped[i]) {
1708  arg2[i] = project(arg2[i], repmat(sparsity_in(i), 1, npar));
1709  } else {
1710  arg2[i] = project(arg2[i], sparsity_in(i));
1711  }
1712  }
1713  }
1714  return arg2;
1715  }
1716  return arg;
1717  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::size2_in(), and casadi::FunctionInternal::sparsity_in().

Referenced by casadi::FunctionInternal::call_gen(), and casadi::FunctionInternal::nz_in().

◆ project_res()

template<typename M >
std::vector< M > casadi::FunctionInternal::project_res ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

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

Definition at line 1720 of file function_internal.hpp.

1721  {
1722  return arg;
1723  }

Referenced by casadi::FunctionInternal::nz_out().

◆ purgable()

template<typename MatType >
bool casadi::FunctionInternal::purgable ( const std::vector< MatType > &  seed)
staticinherited

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

Definition at line 1573 of file function_internal.hpp.

1573  {
1574  for (auto i=v.begin(); i!=v.end(); ++i) {
1575  if (!i->is_zero()) return false;
1576  }
1577  return true;
1578  }

Referenced by casadi::MXFunction::ad_forward(), and casadi::MXFunction::ad_reverse().

◆ release()

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

Definition at line 3937 of file function_internal.cpp.

3937  {
3938 #ifdef CASADI_WITH_THREAD
3939  std::lock_guard<std::mutex> lock(mtx_);
3940 #endif //CASADI_WITH_THREAD
3941  unused_.push(mem);
3942  }

Referenced by casadi::FunctionInternal::codegen_meta().

◆ replace_arg()

template<typename M >
std::vector< M > casadi::FunctionInternal::replace_arg ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

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

Definition at line 1855 of file function_internal.hpp.

1856  {
1857  std::vector<M> r(arg.size());
1858  for (casadi_int i=0; i<r.size(); ++i) r[i] = replace_mat(arg[i], sparsity_in(i), npar);
1859  return r;
1860  }

References casadi::replace_mat(), and casadi::FunctionInternal::sparsity_in().

Referenced by casadi::FunctionInternal::call(), casadi::FunctionInternal::nz_in(), and casadi::FunctionInternal::replace_fseed().

◆ replace_aseed() [1/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_aseed ( const std::vector< std::vector< M > > &  aseed,
casadi_int  npar 
) const
inherited

Definition at line 1879 of file function_internal.hpp.

1880  {
1881  std::vector<std::vector<M> > r(aseed.size());
1882  for (casadi_int d=0; d<r.size(); ++d) r[d] = replace_res(aseed[d], npar);
1883  return r;
1884  }

References casadi::FunctionInternal::replace_res().

◆ replace_aseed() [2/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_aseed ( const std::vector< std::vector< M >> &  aseed,
casadi_int  npar 
) const
inherited

◆ replace_fseed() [1/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_fseed ( const std::vector< std::vector< M > > &  fseed,
casadi_int  npar 
) const
inherited

Definition at line 1871 of file function_internal.hpp.

1872  {
1873  std::vector<std::vector<M> > r(fseed.size());
1874  for (casadi_int d=0; d<r.size(); ++d) r[d] = replace_arg(fseed[d], npar);
1875  return r;
1876  }

References casadi::FunctionInternal::replace_arg().

◆ replace_fseed() [2/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_fseed ( const std::vector< std::vector< M >> &  fseed,
casadi_int  npar 
) const
inherited

◆ replace_res()

template<typename M >
std::vector< M > casadi::FunctionInternal::replace_res ( const std::vector< M > &  res,
casadi_int  npar 
) const
inherited

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

Definition at line 1863 of file function_internal.hpp.

1864  {
1865  std::vector<M> r(res.size());
1866  for (casadi_int i=0; i<r.size(); ++i) r[i] = replace_mat(res[i], sparsity_out(i), npar);
1867  return r;
1868  }

References casadi::replace_mat(), and casadi::FunctionInternal::sparsity_out().

Referenced by casadi::FunctionInternal::nz_out(), and casadi::FunctionInternal::replace_aseed().

◆ reset_dump_count()

void casadi::FunctionInternal::reset_dump_count ( )
inherited

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

Definition at line 471 of file function_internal.cpp.

471  {
472  dump_count_ = 0;
473  }

References casadi::FunctionInternal::dump_count_.

◆ reverse()

Function casadi::FunctionInternal::reverse ( casadi_int  nadj) const
inherited

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_l1

Definition at line 2343 of file function_internal.cpp.

2343  {
2344  casadi_assert_dev(nadj>=0);
2345  // Used wrapped function if reverse not available
2346  if (!enable_reverse_) {
2347  // Derivative information must be available
2348  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2349  return wrap().reverse(nadj);
2350  }
2351  // Retrieve/generate cached
2352  Function f;
2353  std::string fname = reverse_name(name_, nadj);
2354  if (!incache(fname, f)) {
2355  casadi_int i;
2356  // Prefix to be used for adjoint seeds, sensitivities
2357  std::string pref = diff_prefix("adj");
2358  // Names of inputs
2359  std::vector<std::string> inames;
2360  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2361  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2362  for (i=0; i<n_out_; ++i) inames.push_back(pref + name_out_[i]);
2363  // Names of outputs
2364  std::vector<std::string> onames;
2365  for (casadi_int i=0; i<n_in_; ++i) onames.push_back(pref + name_in_[i]);
2366  // Options
2368  opts = combine(opts, generate_options("reverse"));
2369  opts["derivative_of"] = self();
2370  // Generate derivative function
2371  casadi_assert_dev(enable_reverse_);
2372  f = get_reverse(nadj, fname, inames, onames, opts);
2373  // Consistency check for inputs
2374  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_out_);
2375  casadi_int ind=0;
2376  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2377  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2378  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), nadj*size2_out(i));
2379  // Consistency check for outputs
2380  casadi_assert_dev(f.n_out()==n_in_);
2381  for (i=0; i<n_in_; ++i) f.assert_sparsity_out(i, sparsity_in(i), nadj);
2382  // Save to cache
2383  tocache_if_missing(f);
2384  }
2385  return f;
2386  }
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.
static std::string reverse_name(const std::string &fcn, casadi_int nadj)
Helper function: Get name of adjoint derivative function.
Function reverse(casadi_int nadj) const
Get a function that calculates nadj adjoint derivatives.
Definition: function.cpp:1332

References casadi::Function::assert_size_in(), casadi::Function::assert_sparsity_out(), casadi::combine(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::diff_prefix(), casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::generate_options(), casadi::FunctionInternal::get_reverse(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::Function::reverse(), casadi::FunctionInternal::reverse_name(), casadi::FunctionInternal::reverse_options_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_reverse(), and casadi::Function::reverse().

◆ reverse_name()

static std::string casadi::FunctionInternal::reverse_name ( const std::string &  fcn,
casadi_int  nadj 
)
inlinestaticinherited

Definition at line 675 of file function_internal.hpp.

675  {
676  return "adj" + str(nadj) + "_" + fcn;
677  }

References casadi::str().

Referenced by casadi::FunctionInternal::reverse(), and casadi::FixedStepIntegrator::stepB().

◆ self()

Function casadi::FunctionInternal::self ( ) const
inlineinherited

◆ serialize()

void casadi::ProtoFunction::serialize ( SerializingStream &  s) const
inherited

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

Definition at line 4451 of file function_internal.cpp.

4451  {
4452  serialize_type(s);
4453  serialize_body(s);
4454  }
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.

References casadi::ProtoFunction::serialize_body(), and casadi::ProtoFunction::serialize_type().

◆ serialize_base_function()

virtual std::string casadi::ProtoFunction::serialize_base_function ( ) const
inlinevirtualinherited

◆ serialize_body()

void casadi::FmuFunction::serialize_body ( SerializingStream &  s) const
overridevirtual

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

Reimplemented from casadi::ProtoFunction.

Definition at line 1703 of file fmu_function.cpp.

1703  {
1705  s.version("FmuFunction", 6);
1706 
1707  s.pack("FmuFunction::Fmu", fmu_);
1708 
1709  casadi_assert_dev(in_.size()==n_in_);
1710  for (const InputStruct& e : in_) {
1711  s.pack("FmuFunction::in::type", static_cast<int>(e.type));
1712  s.pack("FmuFunction::in::ind", e.ind);
1713  }
1714  casadi_assert_dev(out_.size()==n_out_);
1715  for (const OutputStruct& e : out_) {
1716  s.pack("FmuFunction::out::type", static_cast<int>(e.type));
1717  s.pack("FmuFunction::out::ind", e.ind);
1718  s.pack("FmuFunction::out::wrt", e.wrt);
1719  s.pack("FmuFunction::out::rbegin", e.rbegin);
1720  s.pack("FmuFunction::out::rend", e.rend);
1721  s.pack("FmuFunction::out::cbegin", e.cbegin);
1722  s.pack("FmuFunction::out::cend", e.cend);
1723  }
1724  s.pack("FmuFunction::jac_in", jac_in_);
1725  s.pack("FmuFunction::jac_out", jac_out_);
1726  s.pack("FmuFunction::jac_nom_in", jac_nom_in_);
1727  s.pack("FmuFunction::sp_trans", sp_trans_);
1728  s.pack("FmuFunction::sp_trans_map", sp_trans_map_);
1729 
1730  s.pack("FmuFunction::has_jac", has_jac_);
1731  s.pack("FmuFunction::has_fwd", has_fwd_);
1732  s.pack("FmuFunction::has_adj", has_adj_);
1733  s.pack("FmuFunction::has_hess", has_hess_);
1734 
1735  s.pack("FmuFunction::uses_directional_derivatives", uses_directional_derivatives_);
1736  s.pack("FmuFunction::uses_adjoint_derivatives", uses_adjoint_derivatives_);
1737  s.pack("FmuFunction::nfwd", nfwd_);
1738  s.pack("FmuFunction::nadj", nadj_);
1739  s.pack("FmuFunction::validate_forward", validate_forward_);
1740  s.pack("FmuFunction::validate_hessian", validate_hessian_);
1741  s.pack("FmuFunction::make_symmetric", make_symmetric_);
1742  s.pack("FmuFunction::step", step_);
1743  s.pack("FmuFunction::fd_flip", fd_flip_);
1744  s.pack("FmuFunction::abstol", abstol_);
1745  s.pack("FmuFunction::reltol", reltol_);
1746  s.pack("FmuFunction::print_progress", print_progress_);
1747  s.pack("FmuFunction::new_jacobian", new_jacobian_);
1748  s.pack("FmuFunction::new_forward", new_forward_);
1749  s.pack("FmuFunction::new_hessian", new_hessian_);
1750  s.pack("FmuFunction::hessian_coloring", hessian_coloring_);
1751  s.pack("FmuFunction::asymmetric_hessian_coloring", asymmetric_hessian_coloring_);
1752  s.pack("FmuFunction::enable_forward_jacobian", enable_forward_jacobian_);
1753  s.pack("FmuFunction::enable_adjoint_jacobian", enable_adjoint_jacobian_);
1754  s.pack("FmuFunction::enable_adjoint_hessian", enable_adjoint_hessian_);
1755  s.pack("FmuFunction::validate_ad_file", validate_ad_file_);
1756 
1757  s.pack("FmuFunction::fd", static_cast<int>(fd_));
1758  s.pack("FmuFunction::parallelization", static_cast<int>(parallelization_));
1759  s.pack("FmuFunction::init_stats", init_stats_);
1760 
1761  s.pack("FmuFunction::jac_sp", jac_sp_);
1762  s.pack("FmuFunction::hess_sp", hess_sp_);
1763  s.pack("FmuFunction::adj_sp", adj_sp_);
1764  s.pack("FmuFunction::jac_colors", jac_colors_);
1765  s.pack("FmuFunction::adj_colors", adj_colors_);
1766  s.pack("FmuFunction::hess_colors", hess_colors_);
1767  s.pack("FmuFunction::hess_uni_colors", hess_uni_colors_);
1768  s.pack("FmuFunction::which_hess_color", which_hess_color_);
1769  s.pack("FmuFunction::nonlin", nonlin_);
1770 
1771 
1772  s.pack("FmuFunction::max_jac_tasks", max_jac_tasks_);
1773  s.pack("FmuFunction::max_hess_tasks", max_hess_tasks_);
1774  s.pack("FmuFunction::max_n_tasks", max_n_tasks_);
1775 
1776 }
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.

References abstol_, adj_colors_, adj_sp_, asymmetric_hessian_coloring_, enable_adjoint_hessian_, enable_adjoint_jacobian_, enable_forward_jacobian_, fd_, fd_flip_, fmu_, has_adj_, has_fwd_, has_hess_, has_jac_, hess_colors_, hess_sp_, hess_uni_colors_, hessian_coloring_, in_, init_stats_, jac_colors_, jac_in_, jac_nom_in_, jac_out_, jac_sp_, make_symmetric_, max_hess_tasks_, max_jac_tasks_, max_n_tasks_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, nadj_, new_forward_, new_hessian_, new_jacobian_, nfwd_, nonlin_, out_, casadi::SerializingStream::pack(), parallelization_, print_progress_, reltol_, casadi::FunctionInternal::serialize_body(), sp_trans_, sp_trans_map_, step_, uses_adjoint_derivatives_, uses_directional_derivatives_, validate_ad_file_, validate_forward_, validate_hessian_, casadi::SerializingStream::version(), and which_hess_color_.

◆ serialize_type()

void casadi::FunctionInternal::serialize_type ( SerializingStream &  s) const
overridevirtualinherited

◆ set_jac_sparsity()

void casadi::FunctionInternal::set_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
const Sparsity &  sp 
)
protectedinherited

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

Definition at line 4022 of file function_internal.cpp.

4022  {
4023 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
4024  // Safe access to jac_sparsity_
4025  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
4026 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
4027  casadi_int ind = iind + oind * n_in_;
4028  jac_sparsity_[false].resize(n_in_ * n_out_);
4029  jac_sparsity_[false].at(ind) = sp;
4030  jac_sparsity_[true].resize(n_in_ * n_out_);
4031  jac_sparsity_[true].at(ind) = to_compact(oind, iind, sp);
4032  }

References casadi::FunctionInternal::jac_sparsity_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::to_compact().

◆ set_temp()

virtual void casadi::FunctionInternal::set_temp ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
inlinevirtualinherited

◆ set_work()

virtual void casadi::FunctionInternal::set_work ( void *  mem,
const double **&  arg,
double **&  res,
casadi_int *&  iw,
double *&  w 
) const
inlinevirtualinherited

◆ setup()

void casadi::FunctionInternal::setup ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
inherited

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

Definition at line 3796 of file function_internal.cpp.

3797  {
3798  set_work(mem, arg, res, iw, w);
3799  set_temp(mem, arg, res, iw, w);
3800  auto *m = static_cast<FunctionMemory*>(mem);
3801  m->stats_available = true;
3802  }
virtual void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const
Set the (persistent) work vectors.
virtual void set_temp(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (temporary) work vectors.

References casadi::FunctionInternal::set_temp(), casadi::FunctionInternal::set_work(), and casadi::FunctionMemory::stats_available.

Referenced by casadi::Conic::eval(), casadi::Nlpsol::eval(), casadi::CallbackInternal::eval(), casadi::FiniteDiff::eval(), eval(), casadi::Integrator::eval(), casadi::Map::eval(), casadi::OmpMap::eval(), casadi::ThreadMap::eval(), casadi::MapSum::eval(), casadi::MXFunction::eval(), casadi::Rootfinder::eval(), casadi::Switch::eval(), casadi::SXFunction::eval(), casadi::SlicotDple::eval(), casadi::SlicotExpm::eval(), casadi::BSplineInterpolant::eval(), and casadi::LinearInterpolant::eval().

◆ shared_from_this() [1/2]

B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( )
inlineprotectedinherited

Definition at line 83 of file generic_shared_internal.hpp.

83  {
84  casadi_assert_dev(B::test_cast(static_cast<Internal*>(this)));
85  B ret;
86  ret.own(static_cast<Internal*>(this));
87  return ret;
88  }

◆ shared_from_this() [2/2]

const B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( ) const
inlineprotectedinherited

Definition at line 92 of file generic_shared_internal.hpp.

92  {
93  casadi_assert_dev(B::test_cast(static_cast<const Internal*>(this)));
94  B ret;
95  ret.own(const_cast<Internal*>(static_cast<const Internal*>(this)));
96  return ret;
97  }

◆ signature()

std::string casadi::FunctionInternal::signature ( const std::string &  fname) const
inherited

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

Definition at line 2555 of file function_internal.cpp.

2555  {
2556  return "int " + fname + "(const casadi_real** arg, casadi_real** res, "
2557  "casadi_int* iw, casadi_real* w, int mem)";
2558  }

Referenced by casadi::CodeGenerator::add(), casadi::FunctionInternal::codegen(), casadi::External::codegen_declarations(), and casadi::OnnxFunction::init().

◆ signature_unrolled()

std::string casadi::FunctionInternal::signature_unrolled ( const std::string &  fname) const
inherited

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

Definition at line 2560 of file function_internal.cpp.

2560  {
2561  std::vector<std::string> args;
2562  for (auto e : name_in_) {
2563  args.push_back("const casadi_real* " + str(e));
2564  }
2565  for (auto e : name_out_) {
2566  args.push_back("casadi_real* " + str(e));
2567  }
2568  args.push_back("const casadi_real** arg");
2569  args.push_back("casadi_real** res");
2570  args.push_back("casadi_int* iw");
2571  args.push_back("casadi_real* w");
2572  args.push_back("int mem");
2573  return "int " + fname + "_unrolled(" + join(args, ", ") + ")";
2574  }

References casadi::join(), casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, and casadi::str().

Referenced by casadi::CodeGenerator::add().

◆ simplify_passes()

Function casadi::FunctionInternal::simplify_passes ( const std::vector< std::pair< std::string, casadi_int > > &  tasks) const
virtualinherited

Each pass is a (task, count) pair; count>0 runs the task that many times, count==0 runs it until a fixed point.

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

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3991 of file function_internal.cpp.

3992  {
3993  casadi_assert(tasks.empty(), "simplify passes not supported for " + class_name());
3994  return self();
3995  }

References casadi::SharedObjectInternal::class_name().

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

◆ size1_in()

casadi_int casadi::FunctionInternal::size1_in ( casadi_int  ind) const
inlineinherited

◆ size1_out()

casadi_int casadi::FunctionInternal::size1_out ( casadi_int  ind) const
inlineinherited

◆ size2_in()

casadi_int casadi::FunctionInternal::size2_in ( casadi_int  ind) const
inlineinherited

◆ size2_out()

casadi_int casadi::FunctionInternal::size2_out ( casadi_int  ind) const
inlineinherited

◆ size_in()

std::pair<casadi_int, casadi_int> casadi::FunctionInternal::size_in ( casadi_int  ind) const
inlineinherited

◆ size_out()

std::pair<casadi_int, casadi_int> casadi::FunctionInternal::size_out ( casadi_int  ind) const
inlineinherited

◆ slice()

Function casadi::FunctionInternal::slice ( const std::string &  name,
const std::vector< casadi_int > &  order_in,
const std::vector< casadi_int > &  order_out,
const Dict &  opts 
) const
virtualinherited

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

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 4003 of file function_internal.cpp.

4005  {
4006  return wrap().slice(name, order_in, order_out, opts);
4007  }
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

References casadi::Function::slice(), and casadi::FunctionInternal::wrap().

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

◆ sp_forward()

int casadi::FunctionInternal::sp_forward ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t *  w,
void *  mem 
) const
virtualinherited

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

Reimplemented in casadi::BSplineInterpolant, casadi::SXFunction, casadi::Rootfinder, casadi::MXFunction, casadi::MapSum, casadi::Map, and casadi::Integrator.

Definition at line 3083 of file function_internal.cpp.

3084  {
3085  // Loop over outputs
3086  for (casadi_int oind=0; oind<n_out_; ++oind) {
3087  // Skip if nothing to assign
3088  if (res[oind]==nullptr || nnz_out(oind)==0) continue;
3089  // Clear result
3090  casadi_clear(res[oind], nnz_out(oind));
3091  // Loop over inputs
3092  for (casadi_int iind=0; iind<n_in_; ++iind) {
3093  // Skip if no seeds
3094  if (arg[iind]==nullptr || nnz_in(iind)==0) continue;
3095  // Propagate sparsity for the specific block
3096  if (sp_forward_block(arg, res, iw, w, mem, oind, iind)) return 1;
3097  }
3098  }
3099  return 0;
3100  }
virtual int sp_forward_block(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, casadi_int oind, casadi_int iind) const
Propagate sparsity forward, specific block.
void casadi_clear(T1 *x, casadi_int n)
CLEAR: x <- 0.

References casadi::casadi_clear(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), and casadi::FunctionInternal::sp_forward_block().

Referenced by casadi::MXFunction::sp_forward(), casadi::SXFunction::sp_forward(), and casadi::BSplineInterpolant::sp_forward().

◆ sp_forward_block()

int casadi::FunctionInternal::sp_forward_block ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t *  w,
void *  mem,
casadi_int  oind,
casadi_int  iind 
) const
virtualinherited

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

Definition at line 3102 of file function_internal.cpp.

3103  {
3104  // Get the sparsity of the Jacobian block
3105  Sparsity sp = jac_sparsity(oind, iind, true, false);
3106  if (sp.is_null() || sp.nnz() == 0) return 0; // Skip if zero
3107  // Carry out the sparse matrix-vector multiplication
3108  casadi_int d1 = sp.size2();
3109  const casadi_int *colind = sp.colind(), *row = sp.row();
3110  for (casadi_int cc=0; cc<d1; ++cc) {
3111  for (casadi_int el = colind[cc]; el < colind[cc+1]; ++el) {
3112  res[oind][row[el]] |= arg[iind][cc];
3113  }
3114  }
3115  return 0;
3116  }

References casadi::Sparsity::colind(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::Sparsity::nnz(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::FunctionInternal::sp_forward().

◆ sp_reverse()

int casadi::FunctionInternal::sp_reverse ( bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t *  w,
void *  mem 
) const
virtualinherited

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

Reimplemented in casadi::BSplineInterpolant, casadi::SXFunction, casadi::Rootfinder, casadi::MXFunction, casadi::MapSum, casadi::Map, and casadi::Integrator.

Definition at line 3118 of file function_internal.cpp.

3119  {
3120  // Loop over outputs
3121  for (casadi_int oind=0; oind<n_out_; ++oind) {
3122  // Skip if nothing to assign
3123  if (res[oind]==nullptr || nnz_out(oind)==0) continue;
3124 
3125  // Loop over inputs
3126  for (casadi_int iind=0; iind<n_in_; ++iind) {
3127  // Skip if no seeds
3128  if (arg[iind]==nullptr || nnz_in(iind)==0) continue;
3129 
3130  // Get the sparsity of the Jacobian block
3131  Sparsity sp = jac_sparsity(oind, iind, true, false);
3132  if (sp.is_null() || sp.nnz() == 0) continue; // Skip if zero
3133 
3134  // Carry out the sparse matrix-vector multiplication
3135  casadi_int d1 = sp.size2();
3136  const casadi_int *colind = sp.colind(), *row = sp.row();
3137  for (casadi_int cc=0; cc<d1; ++cc) {
3138  for (casadi_int el = colind[cc]; el < colind[cc+1]; ++el) {
3139  arg[iind][cc] |= res[oind][row[el]];
3140  }
3141  }
3142  }
3143 
3144  // Clear seeds
3145  casadi_clear(res[oind], nnz_out(oind));
3146  }
3147  return 0;
3148  }

References casadi::casadi_clear(), casadi::Sparsity::colind(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::MXFunction::sp_reverse(), casadi::SXFunction::sp_reverse(), and casadi::BSplineInterpolant::sp_reverse().

◆ sp_weight()

double casadi::FunctionInternal::sp_weight ( ) const
virtualinherited

sparsity propagation

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

Definition at line 3533 of file function_internal.cpp.

3533  {
3534  // If reverse mode propagation unavailable, use forward
3535  if (!has_sprev()) return 0;
3536 
3537  // If forward mode propagation unavailable, use reverse
3538  if (!has_spfwd()) return 1;
3539 
3540  // Use the (potentially user set) option
3541  return ad_weight_sp_;
3542  }

References casadi::FunctionInternal::ad_weight_sp_, casadi::FunctionInternal::has_spfwd(), and casadi::FunctionInternal::has_sprev().

Referenced by casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::MXFunction::sp_forward(), casadi::SXFunction::sp_forward(), casadi::MXFunction::sp_reverse(), casadi::SXFunction::sp_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ sparsity_in()

const Sparsity& casadi::FunctionInternal::sparsity_in ( casadi_int  ind) const
inlineinherited

◆ sparsity_out()

const Sparsity& casadi::FunctionInternal::sparsity_out ( casadi_int  ind) const
inlineinherited

◆ sprint()

void casadi::ProtoFunction::sprint ( char *  buf,
size_t  buf_sz,
const char *  fmt,
  ... 
) const
inherited

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

Definition at line 4146 of file function_internal.cpp.

4146  {
4147  // Variable number of arguments
4148  va_list args;
4149  va_start(args, fmt);
4150  // Print to buffer
4151  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
4152  // Cleanup
4153  va_end(args);
4154  // Throw error if failure
4155  casadi_assert(n>=0 && n<buf_sz, "Print failure while processing '" + std::string(fmt) + "'");
4156  }

Referenced by casadi::ProtoFunction::format_time(), and casadi::ProtoFunction::print_time().

◆ string_from_UnifiedReturnStatus()

std::string casadi::FunctionInternal::string_from_UnifiedReturnStatus ( UnifiedReturnStatus  status)
staticinherited

Definition at line 4214 of file function_internal.cpp.

4214  {
4215  switch (status) {
4216  case SOLVER_RET_LIMITED: return "SOLVER_RET_LIMITED";
4217  case SOLVER_RET_NAN: return "SOLVER_RET_NAN";
4218  case SOLVER_RET_SUCCESS: return "SOLVER_RET_SUCCESS";
4219  default: return "SOLVER_RET_UNKNOWN";
4220  }
4221  }
@ SOLVER_RET_NAN
@ SOLVER_RET_LIMITED
@ SOLVER_RET_SUCCESS

References casadi::SOLVER_RET_LIMITED, casadi::SOLVER_RET_NAN, and casadi::SOLVER_RET_SUCCESS.

Referenced by casadi::Conic::get_stats(), casadi::Nlpsol::get_stats(), and casadi::Rootfinder::get_stats().

◆ sx_in() [1/2]

const std::vector< SX > casadi::FunctionInternal::sx_in ( ) const
virtualinherited

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

Reimplemented in casadi::SXFunction.

Definition at line 3560 of file function_internal.cpp.

3560  {
3561  std::vector<SX> ret(n_in_);
3562  for (casadi_int i=0; i<ret.size(); ++i) {
3563  ret[i] = sx_in(i);
3564  }
3565  return ret;
3566  }
virtual const std::vector< SX > sx_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

◆ sx_in() [2/2]

const SX casadi::FunctionInternal::sx_in ( casadi_int  ind) const
virtualinherited

◆ sx_out() [1/2]

const std::vector< SX > casadi::FunctionInternal::sx_out ( ) const
virtualinherited

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

Definition at line 3568 of file function_internal.cpp.

3568  {
3569  std::vector<SX> ret(n_out_);
3570  for (casadi_int i=0; i<ret.size(); ++i) {
3571  ret[i] = sx_out(i);
3572  }
3573  return ret;
3574  }
virtual const std::vector< SX > sx_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

◆ sx_out() [2/2]

const SX casadi::FunctionInternal::sx_out ( casadi_int  ind) const
virtualinherited

◆ symbolic_output()

std::vector< MX > casadi::FunctionInternal::symbolic_output ( const std::vector< MX > &  arg) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 1265 of file function_internal.cpp.

1265  {
1266  return self()(arg);
1267  }

Referenced by casadi::MXFunction::symbolic_output().

◆ symbolicAdjSeed()

template<typename MatType >
std::vector< std::vector< MatType > > casadi::FunctionInternal::symbolicAdjSeed ( casadi_int  nadj,
const std::vector< MatType > &  v 
) const
inherited

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

Definition at line 1598 of file function_internal.hpp.

1599  {
1600  std::vector<std::vector<MatType> > aseed(nadj, v);
1601  for (casadi_int dir=0; dir<nadj; ++dir) {
1602  // Replace symbolic inputs
1603  casadi_int oind=0;
1604  for (typename std::vector<MatType>::iterator i=aseed[dir].begin();
1605  i!=aseed[dir].end();
1606  ++i, ++oind) {
1607  // Name of the adjoint seed
1608  std::stringstream ss;
1609  ss << "a";
1610  if (nadj>1) ss << dir << "_";
1611  ss << oind;
1612 
1613  // Save to matrix
1614  *i = MatType::sym(ss.str(), is_diff_out_[oind] ? i->sparsity() : Sparsity(i->size()));
1615 
1616  }
1617  }
1618  return aseed;
1619  }

References casadi::FunctionInternal::is_diff_out_.

◆ sz_arg()

size_t casadi::FunctionInternal::sz_arg ( ) const
inlineinherited

◆ sz_iw()

size_t casadi::FunctionInternal::sz_iw ( ) const
inlineinherited

◆ sz_res()

size_t casadi::FunctionInternal::sz_res ( ) const
inlineinherited

◆ sz_w()

size_t casadi::FunctionInternal::sz_w ( ) const
inlineinherited

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

Definition at line 1233 of file function_internal.hpp.

1233 { return sz_w_per_ + sz_w_tmp_;}

Referenced by casadi::FunctionInternal::alloc(), casadi::FunctionInternal::alloc_w(), casadi::FunctionInternal::call_gen(), casadi::OmpMap::codegen_body(), casadi::ThreadMap::codegen_body(), casadi::MXFunction::codegen_body(), casadi::ThreadMap::codegen_declarations(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_sz_w(), casadi::MXFunction::codegen_sz_w(), casadi::SXFunction::codegen_sz_w(), casadi::OmpMap::eval(), casadi::FunctionInternal::eval_gen(), casadi::SXFunction::eval_mx(), casadi::OracleFunction::finalize(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::External::init(), casadi::MXFunction::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::MadmpecInterface::init(), casadi::ClarabelInterface::init(), casadi::DaqpInterface::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::HighsInterface::init(), casadi::HpipmInterface::init(), casadi::MadnlpInterface::init(), casadi::MosekInterface::init(), casadi::XpressInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Qrqp::init(), casadi::Sqpmethod::init(), casadi::MXFunction::sp_reverse(), casadi::SXFunction::sp_reverse(), and casadi::FunctionInternal::sz_work().

◆ sz_work()

void casadi::FunctionInternal::sz_work ( size_t &  sz_arg,
size_t &  sz_res,
size_t &  sz_iw,
size_t &  sz_w 
) const
inherited

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

Definition at line 3150 of file function_internal.cpp.

3151  {
3152  sz_arg = this->sz_arg();
3153  sz_res = this->sz_res();
3154  sz_iw = this->sz_iw();
3155  sz_w = this->sz_w();
3156  }

References casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), and casadi::FunctionInternal::sz_w().

◆ to_compact()

Sparsity casadi::FunctionInternal::to_compact ( casadi_int  oind,
casadi_int  iind,
const Sparsity &  sp 
) const
inherited

Definition at line 2036 of file function_internal.cpp.

2037  {
2038  // Strip rows and columns
2039  std::vector<casadi_int> mapping;
2040  return sp.sub(sparsity_out(oind).find(), sparsity_in(iind).find(), mapping);
2041  }

References casadi::FunctionInternal::find(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::sparsity_out(), and casadi::Sparsity::sub().

Referenced by casadi::FunctionInternal::jac_sparsity(), and casadi::FunctionInternal::set_jac_sparsity().

◆ tocache()

void casadi::FunctionInternal::tocache ( const Function &  f,
const std::string &  suffix = "" 
) const
inherited

◆ tocache_if_missing()

void casadi::FunctionInternal::tocache_if_missing ( Function &  f,
const std::string &  suffix = "" 
) const
inherited

◆ trace_values()

void casadi::FunctionInternal::trace_values ( std::ostream &  trace,
const double *  values,
casadi_int  nnz 
)
staticprotectedinherited

Definition at line 826 of file function_internal.cpp.

827  {
828  if (!values) {
829  trace << "null";
830  return;
831  }
832  trace << "[";
833  for (casadi_int i = 0; i < nnz; ++i) {
834  if (i) trace << ",";
835  double v = values[i];
836  if (isnan(v)) {
837  trace << "\"nan\"";
838  } else if (isinf(v)) {
839  trace << (v < 0 ? "\"-inf\"" : "\"inf\"");
840  } else {
841  normalized_out(trace, v);
842  }
843  }
844  trace << "]";
845  }

References casadi::normalized_out().

Referenced by casadi::FunctionInternal::finish_trace(), casadi::FunctionInternal::open_trace(), casadi::MXFunction::trace_instruction(), and casadi::SXFunction::trace_instruction().

◆ uses_output()

virtual bool casadi::FunctionInternal::uses_output ( ) const
inlinevirtualinherited

◆ weak()

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

Definition at line 67 of file generic_shared_internal.hpp.

215  {
216 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
217  auto* w = weak_ref_.load(std::memory_order_acquire);
218  if (!w) {
219  auto* nw = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
220  GenericWeakRef<Shared, Internal>* expected = nullptr;
221  if (weak_ref_.compare_exchange_strong(
222  expected, nw, std::memory_order_release, std::memory_order_acquire)) {
223  w = nw;
224  } else {
225  delete nw; // lost the race; another thread published first
226  w = expected;
227  }
228  }
229  return w;
230 #else
231  if (weak_ref_==nullptr) {
232  weak_ref_ = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
233  }
234  return weak_ref_;
235 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
236  }

◆ which_depends()

std::vector< bool > casadi::FunctionInternal::which_depends ( const std::string &  s_in,
const std::vector< std::string > &  s_out,
casadi_int  order,
bool  tr = false 
) const
virtualinherited
Parameters
[in]s_inInput name
[in]s_outOutput name(s)
[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_k9

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3983 of file function_internal.cpp.

3985  {
3986  Function f = shared_from_this<Function>();
3987  f = f.wrap();
3988  return f.which_depends(s_in, s_out, order, tr);
3989  }

References casadi::Function::which_depends(), and casadi::Function::wrap().

◆ wrap() [1/2]

Function casadi::FunctionInternal::wrap ( ) const
inherited

◆ wrap() [2/2]

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

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

Definition at line 1244 of file function_internal.cpp.

1244  {
1245  Function f;
1246  if (!incache(name, f)) {
1247  // Options
1248  Dict opts;
1249  opts["derivative_of"] = derivative_of_;
1250  opts["ad_weight"] = ad_weight();
1251  opts["ad_weight_sp"] = sp_weight();
1252  opts["max_num_dir"] = max_num_dir_;
1253  opts["is_diff_in"] = is_diff_in_;
1254  opts["is_diff_out"] = is_diff_out_;
1255  // Wrap the function
1256  std::vector<MX> arg = mx_in();
1257  std::vector<MX> res = self()(arg);
1258  f = Function(name, arg, res, name_in_, name_out_, opts);
1259  // Save in cache
1260  tocache_if_missing(f);
1261  }
1262  return f;
1263  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::Function, casadi::FunctionInternal::incache(), casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sp_weight(), and casadi::FunctionInternal::tocache_if_missing().

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

◆ wrap_as_needed() [1/2]

Function casadi::FunctionInternal::wrap_as_needed ( const Dict &  opts) const
inherited

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

Definition at line 1219 of file function_internal.cpp.

1219  {
1220  return wrap_as_needed("wrap_" + name_, opts);
1221  }
Function wrap_as_needed(const std::string &name, const Dict &opts) const
Wrap in an Function instance consisting of only one MX call.

References casadi::ProtoFunction::name_, and casadi::FunctionInternal::wrap_as_needed().

◆ wrap_as_needed() [2/2]

Function casadi::FunctionInternal::wrap_as_needed ( const std::string &  name,
const Dict &  opts 
) const
inherited

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

Definition at line 1223 of file function_internal.cpp.

1223  {
1224  if (opts.empty() && name==name_) return shared_from_this<Function>();
1225  // Options
1226  Dict my_opts = opts;
1227  my_opts["derivative_of"] = derivative_of_;
1228  if (my_opts.find("ad_weight")==my_opts.end())
1229  my_opts["ad_weight"] = ad_weight();
1230  if (my_opts.find("ad_weight_sp")==my_opts.end())
1231  my_opts["ad_weight_sp"] = sp_weight();
1232  if (my_opts.find("max_num_dir")==my_opts.end())
1233  my_opts["max_num_dir"] = max_num_dir_;
1234  // Wrap the function
1235  std::vector<MX> arg = mx_in();
1236  std::vector<MX> res = self()(arg);
1237  return Function(name, arg, res, name_in_, name_out_, my_opts);
1238  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::Function, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::mx_in(), casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, and casadi::FunctionInternal::sp_weight().

Referenced by casadi::Function::wrap_as_needed(), and casadi::FunctionInternal::wrap_as_needed().

Member Data Documentation

◆ abstol_

double casadi::FmuFunction::abstol_

◆ ad_weight_

double casadi::FunctionInternal::ad_weight_
inherited

◆ ad_weight_sp_

double casadi::FunctionInternal::ad_weight_sp_
inherited

◆ adj_colors_

Sparsity casadi::FmuFunction::adj_colors_

Definition at line 223 of file fmu_function.hpp.

Referenced by eval_task(), FmuFunction(), init(), and serialize_body().

◆ adj_prob_

casadi_jac_prob<double> casadi::FmuFunction::adj_prob_

Definition at line 232 of file fmu_function.hpp.

Referenced by eval(), eval_task(), FmuFunction(), and init().

◆ adj_sp_

Sparsity casadi::FmuFunction::adj_sp_

Definition at line 220 of file fmu_function.hpp.

Referenced by eval(), FmuFunction(), init(), and serialize_body().

◆ always_inline_

bool casadi::FunctionInternal::always_inline_
inherited

◆ asymmetric_hessian_coloring_

bool casadi::FmuFunction::asymmetric_hessian_coloring_

Definition at line 171 of file fmu_function.hpp.

Referenced by FmuFunction(), init(), and serialize_body().

◆ cache_

WeakCache<std::string, Function> casadi::FunctionInternal::cache_
mutableinherited

◆ cache_init_

Dict casadi::FunctionInternal::cache_init_
inherited

◆ checkout_

casadi_checkout_t casadi::FunctionInternal::checkout_
inherited

◆ compiler_

Importer casadi::FunctionInternal::compiler_
inherited

◆ compiler_plugin_

std::string casadi::FunctionInternal::compiler_plugin_
inherited

◆ custom_jacobian_

Function casadi::FunctionInternal::custom_jacobian_
inherited

◆ decref_

signal_t casadi::FunctionInternal::decref_
inherited

◆ der_options_

Dict casadi::FunctionInternal::der_options_
inherited

◆ derivative_of_

Function casadi::FunctionInternal::derivative_of_
inherited

◆ deserialize_map

std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> casadi::FunctionInternal::deserialize_map
staticinherited
Initial value:
= {
{"MXFunction", MXFunction::deserialize},
{"SXFunction", SXFunction::deserialize},
{"Interpolant", Interpolant::deserialize},
{"Switch", Switch::deserialize},
{"ForwardDiff", ForwardDiff::deserialize},
{"BackwardDiff", BackwardDiff::deserialize},
{"CentralDiff", CentralDiff::deserialize},
{"Smoothing", Smoothing::deserialize},
{"Map", Map::deserialize},
{"MapSum", MapSum::deserialize},
{"Nlpsol", Nlpsol::deserialize},
{"Rootfinder", Rootfinder::deserialize},
{"Integrator", Integrator::deserialize},
{"External", External::deserialize},
{"Conic", Conic::deserialize},
{"FmuFunction", FmuFunction::deserialize},
{"BlazingSplineFunction", BlazingSplineFunction::deserialize},
}
static ProtoFunction * deserialize(DeserializingStream &s)
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static ProtoFunction * deserialize(DeserializingStream &s)
void deserialize(DeserializingStream &s, SDPToSOCPMem &m)
Definition: conic.cpp:744
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: external.cpp:508
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: mapsum.cpp:85
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: map.cpp:110
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: nlpsol.cpp:1444
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into a plugin instance (dispatches on the plugin name)
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: rootfinder.cpp:595
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
Definition: switch.hpp:150

Definition at line 1514 of file function_internal.hpp.

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

◆ dump_

bool casadi::FunctionInternal::dump_
inherited

◆ dump_count_

casadi_int casadi::FunctionInternal::dump_count_
mutableinherited

◆ dump_dir_

std::string casadi::FunctionInternal::dump_dir_
inherited

◆ dump_format_

std::string casadi::FunctionInternal::dump_format_
inherited

◆ dump_in_

bool casadi::FunctionInternal::dump_in_
inherited

◆ dump_out_

bool casadi::FunctionInternal::dump_out_
inherited

◆ enable_adjoint_hessian_

bool casadi::FmuFunction::enable_adjoint_hessian_

Definition at line 172 of file fmu_function.hpp.

Referenced by change_option(), eval_task(), FmuFunction(), init(), and serialize_body().

◆ enable_adjoint_jacobian_

bool casadi::FmuFunction::enable_adjoint_jacobian_

Definition at line 172 of file fmu_function.hpp.

Referenced by eval(), eval_task(), FmuFunction(), init(), and serialize_body().

◆ enable_fd_

bool casadi::FunctionInternal::enable_fd_
inherited

◆ enable_fd_op_

bool casadi::FunctionInternal::enable_fd_op_
inherited

◆ enable_forward_

bool casadi::FunctionInternal::enable_forward_
inherited

◆ enable_forward_jacobian_

bool casadi::FmuFunction::enable_forward_jacobian_

Definition at line 172 of file fmu_function.hpp.

Referenced by change_option(), eval(), eval_task(), FmuFunction(), init(), and serialize_body().

◆ enable_forward_op_

bool casadi::FunctionInternal::enable_forward_op_
inherited

◆ enable_jacobian_

bool casadi::FunctionInternal::enable_jacobian_
inherited

◆ enable_jacobian_op_

bool casadi::FunctionInternal::enable_jacobian_op_
inherited

◆ enable_reverse_

bool casadi::FunctionInternal::enable_reverse_
inherited

◆ enable_reverse_op_

bool casadi::FunctionInternal::enable_reverse_op_
inherited

◆ error_on_fail_

bool casadi::ProtoFunction::error_on_fail_
inherited

◆ eval_

eval_t casadi::FunctionInternal::eval_
inherited

◆ fd_

FdMode casadi::FmuFunction::fd_

◆ fd_flip_

bool casadi::FmuFunction::fd_flip_

◆ fd_method_

std::string casadi::FunctionInternal::fd_method_
inherited

◆ fd_options_

Dict casadi::FunctionInternal::fd_options_
inherited

◆ fd_step_

double casadi::FunctionInternal::fd_step_
inherited

◆ fmu_

Fmu casadi::FmuFunction::fmu_

◆ forward_options_

Dict casadi::FunctionInternal::forward_options_
inherited

◆ has_adj_

bool casadi::FmuFunction::has_adj_

Definition at line 157 of file fmu_function.hpp.

Referenced by FmuFunction(), init(), and serialize_body().

◆ has_fwd_

bool casadi::FmuFunction::has_fwd_

Definition at line 157 of file fmu_function.hpp.

Referenced by FmuFunction(), and serialize_body().

◆ has_hess_

bool casadi::FmuFunction::has_hess_

Definition at line 157 of file fmu_function.hpp.

Referenced by FmuFunction(), init(), and serialize_body().

◆ has_jac_

bool casadi::FmuFunction::has_jac_

Definition at line 157 of file fmu_function.hpp.

Referenced by FmuFunction(), init(), and serialize_body().

◆ has_refcount_

bool casadi::FunctionInternal::has_refcount_
inherited

◆ has_refcount_in_deps_

bool casadi::FunctionInternal::has_refcount_in_deps_
inherited

◆ hess_colors_

Sparsity casadi::FmuFunction::hess_colors_

Definition at line 223 of file fmu_function.hpp.

Referenced by change_option(), eval_task(), FmuFunction(), init(), and serialize_body().

◆ hess_sp_

Sparsity casadi::FmuFunction::hess_sp_

Definition at line 220 of file fmu_function.hpp.

Referenced by eval(), eval_task(), finalize_hessian(), FmuFunction(), init(), and serialize_body().

◆ hess_uni_colors_

Sparsity casadi::FmuFunction::hess_uni_colors_

Definition at line 223 of file fmu_function.hpp.

Referenced by change_option(), eval_task(), FmuFunction(), init(), and serialize_body().

◆ hessian_coloring_

bool casadi::FmuFunction::hessian_coloring_

◆ in_

std::vector<InputStruct> casadi::FmuFunction::in_

◆ incref_

signal_t casadi::FunctionInternal::incref_
inherited

◆ init_stats_

Dict casadi::FmuFunction::init_stats_

Definition at line 182 of file fmu_function.hpp.

Referenced by FmuFunction(), and serialize_body().

◆ inputs_check_

bool casadi::FunctionInternal::inputs_check_
inherited

◆ is_diff_in_

std::vector<bool> casadi::FunctionInternal::is_diff_in_
inherited

◆ is_diff_out_

std::vector<bool> casadi::FunctionInternal::is_diff_out_
inherited

◆ jac_colors_

Sparsity casadi::FmuFunction::jac_colors_

Definition at line 223 of file fmu_function.hpp.

Referenced by eval_task(), FmuFunction(), init(), and serialize_body().

◆ jac_in_

std::vector<size_t> casadi::FmuFunction::jac_in_

Definition at line 147 of file fmu_function.hpp.

Referenced by eval_task(), finalize_hessian(), FmuFunction(), init(), and serialize_body().

◆ jac_nom_in_

std::vector<double> casadi::FmuFunction::jac_nom_in_

Definition at line 150 of file fmu_function.hpp.

Referenced by FmuFunction(), init(), and serialize_body().

◆ jac_out_

std::vector<size_t> casadi::FmuFunction::jac_out_

Definition at line 147 of file fmu_function.hpp.

Referenced by eval_task(), FmuFunction(), init(), and serialize_body().

◆ jac_penalty_

double casadi::FunctionInternal::jac_penalty_
inherited

◆ jac_prob_

casadi_jac_prob<double> casadi::FmuFunction::jac_prob_

Definition at line 232 of file fmu_function.hpp.

Referenced by eval(), eval_task(), FmuFunction(), and init().

◆ jac_sp_

Sparsity casadi::FmuFunction::jac_sp_

Definition at line 220 of file fmu_function.hpp.

Referenced by eval(), FmuFunction(), init(), and serialize_body().

◆ jac_sparsity_

std::vector<Sparsity> casadi::FunctionInternal::jac_sparsity_[2]
mutableinherited

◆ jacobian_options_

Dict casadi::FunctionInternal::jacobian_options_
inherited

◆ jit_

bool casadi::FunctionInternal::jit_
inherited

◆ jit_base_name_

std::string casadi::FunctionInternal::jit_base_name_
inherited

◆ jit_cleanup_

bool casadi::FunctionInternal::jit_cleanup_
inherited

◆ jit_directory_

std::string casadi::FunctionInternal::jit_directory_
inherited

◆ jit_name_

std::string casadi::FunctionInternal::jit_name_
inherited

◆ jit_options_

Dict casadi::FunctionInternal::jit_options_
inherited

◆ jit_serialize_

std::string casadi::FunctionInternal::jit_serialize_
inherited

◆ jit_temp_suffix_

bool casadi::FunctionInternal::jit_temp_suffix_
inherited

◆ make_symmetric_

bool casadi::FmuFunction::make_symmetric_

Definition at line 171 of file fmu_function.hpp.

Referenced by change_option(), finalize_hessian(), FmuFunction(), init(), and serialize_body().

◆ max_adj_tasks_

casadi_int casadi::FmuFunction::max_adj_tasks_

Definition at line 235 of file fmu_function.hpp.

◆ max_hess_tasks_

casadi_int casadi::FmuFunction::max_hess_tasks_

Definition at line 235 of file fmu_function.hpp.

Referenced by eval(), FmuFunction(), init(), init_mem(), and serialize_body().

◆ max_io_

casadi_int casadi::FunctionInternal::max_io_
inherited

◆ max_jac_tasks_

casadi_int casadi::FmuFunction::max_jac_tasks_

Definition at line 235 of file fmu_function.hpp.

Referenced by alloc_mem(), eval(), FmuFunction(), init(), init_mem(), and serialize_body().

◆ max_n_tasks_

casadi_int casadi::FmuFunction::max_n_tasks_

Definition at line 235 of file fmu_function.hpp.

Referenced by eval(), FmuFunction(), init(), and serialize_body().

◆ max_num_dir_

casadi_int casadi::FunctionInternal::max_num_dir_
inherited

◆ n_in_

size_t casadi::FunctionInternal::n_in_
inherited

Definition at line 1312 of file function_internal.hpp.

Referenced by casadi::SXFunction::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::all_scalar(), casadi::KinsolInterface::bjac(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::call_reverse(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::check_arg(), casadi::JitFunction::codegen_body(), casadi::Map::codegen_body(), casadi::OmpMap::codegen_body(), casadi::ThreadMap::codegen_body(), casadi::MapSum::codegen_body(), casadi::MXFunction::codegen_body(), casadi::Switch::codegen_body(), casadi::SXFunction::codegen_body(), casadi::FastNewton::codegen_body(), casadi::ThreadMap::codegen_declarations(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::convert_arg(), casadi::FunctionInternal::definition(), casadi::KinsolInterface::djac(), casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::eval(), casadi::OmpMap::eval(), casadi::MXFunction::eval(), casadi::Switch::eval(), casadi::MXFunction::eval_activity(), casadi::FunctionInternal::eval_gen(), casadi::Map::eval_gen(), casadi::MapSum::eval_gen(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::Switch::eval_sx(), casadi::SXFunction::export_code_body(), casadi::CallbackInternal::finalize(), FmuFunction(), casadi::FunctionInternal::forward(), casadi::KinsolInterface::func(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::fwd_seed(), casadi::FunctionInternal::generate_in(), casadi::GenericExternal::get_jac_sparsity(), casadi::GenericExternal::has_jac_sparsity(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::Switch::init(), casadi::SXFunction::init(), casadi::ImplicitToNlp::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::KinsolInterface::jtimes(), casadi::FunctionInternal::mapsum_mx(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::open_trace(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_dimensions(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::project_arg(), casadi::KinsolInterface::psetup(), casadi::FunctionInternal::reverse(), serialize_body(), casadi::FunctionInternal::set_jac_sparsity(), casadi::Rootfinder::set_work(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FastNewton::solve(), casadi::ImplicitToNlp::solve(), casadi::Newton::solve(), casadi::FunctionInternal::sp_forward(), casadi::Integrator::sp_forward(), casadi::MXFunction::sp_forward(), casadi::Rootfinder::sp_forward(), casadi::FunctionInternal::sp_reverse(), casadi::Integrator::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), casadi::MXFunction::sp_reverse(), casadi::Rootfinder::sp_reverse(), and casadi::FunctionInternal::sx_in().

◆ n_out_

size_t casadi::FunctionInternal::n_out_
inherited

Definition at line 1312 of file function_internal.hpp.

Referenced by casadi::Rootfinder::ad_forward(), casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::all_scalar(), casadi::KinsolInterface::bjac(), casadi::FunctionInternal::call(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::call_reverse(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::check_res(), casadi::JitFunction::codegen_body(), casadi::Map::codegen_body(), casadi::OmpMap::codegen_body(), casadi::ThreadMap::codegen_body(), casadi::MapSum::codegen_body(), casadi::MXFunction::codegen_body(), casadi::Switch::codegen_body(), casadi::SXFunction::codegen_body(), casadi::FastNewton::codegen_body(), casadi::ThreadMap::codegen_declarations(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::convert_res(), casadi::FunctionInternal::definition(), casadi::KinsolInterface::djac(), casadi::FunctionInternal::dm_out(), casadi::FunctionInternal::eval(), casadi::OmpMap::eval(), casadi::MXFunction::eval(), casadi::Switch::eval(), casadi::FunctionInternal::eval_activity(), casadi::MXFunction::eval_activity(), casadi::FunctionInternal::eval_gen(), casadi::Map::eval_gen(), casadi::MapSum::eval_gen(), casadi::Switch::eval_sx(), casadi::CallbackInternal::finalize(), casadi::FunctionInternal::finish_trace(), FmuFunction(), casadi::FunctionInternal::forward(), casadi::KinsolInterface::func(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::generate_out(), casadi::LinearInterpolantJac::get_jacobian(), casadi::FunctionInternal::init(), casadi::MapSum::init(), casadi::Nlpsol::init(), casadi::Switch::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::mapsum_mx(), casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::mx_out(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::numel_out(), casadi::FunctionInternal::nz_out(), casadi::FunctionInternal::print_dimensions(), casadi::FunctionInternal::print_out(), casadi::KinsolInterface::psetup(), casadi::FunctionInternal::reverse(), serialize_body(), casadi::FunctionInternal::set_jac_sparsity(), casadi::Rootfinder::set_work(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FastNewton::solve(), casadi::ImplicitToNlp::solve(), casadi::Newton::solve(), casadi::FunctionInternal::sp_forward(), casadi::Integrator::sp_forward(), casadi::MXFunction::sp_forward(), casadi::Rootfinder::sp_forward(), casadi::FunctionInternal::sp_reverse(), casadi::Integrator::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), casadi::MXFunction::sp_reverse(), casadi::Rootfinder::sp_reverse(), and casadi::FunctionInternal::sx_out().

◆ nadj_

casadi_int casadi::FmuFunction::nadj_

◆ name_

std::string casadi::ProtoFunction::name_
inherited

Definition at line 248 of file function_internal.hpp.

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::Integrator::augmented_dae(), casadi::OracleFunction::calc_function(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), casadi::FunctionInternal::codegen_body(), casadi::External::codegen_body(), casadi::External::codegen_checkout(), casadi::External::codegen_declarations(), casadi::MXFunction::codegen_declarations(), casadi::SXFunction::codegen_declarations(), casadi::External::codegen_decref(), casadi::External::codegen_incref(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_name(), casadi::External::codegen_release(), casadi::FunctionInternal::codegen_sparsities(), casadi::ProtoFunction::construct(), casadi::OracleFunction::create_function(), casadi::FunctionInternal::definition(), casadi::FunctionInternal::eval(), casadi::MXFunction::eval(), casadi::SXFunction::eval(), casadi::FunctionInternal::eval_mx(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::SXFunction::eval_sx(), factory(), casadi::FunctionInternal::finalize(), casadi::FunctionInternal::finish_trace(), casadi::FunctionInternal::forward(), casadi::FunctionInternal::FunctionInternal(), casadi::Integrator::get_forward(), casadi::Integrator::get_forward_dae(), casadi::Map::get_function(), casadi::MapSum::get_function(), casadi::OracleFunction::get_function(), casadi::GenericExternal::get_jac_sparsity(), casadi::BlazingSplineFunction::get_jacobian(), casadi::FunctionInternal::get_n_in(), casadi::External::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::External::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::External::get_name_in(), casadi::FunctionInternal::get_name_out(), casadi::External::get_name_out(), casadi::FunctionInternal::get_partition(), casadi::Integrator::get_reverse(), casadi::FunctionInternal::get_sparsity_in(), casadi::GenericExternal::get_sparsity_in(), casadi::FunctionInternal::get_sparsity_out(), casadi::GenericExternal::get_sparsity_out(), casadi::FunctionInternal::get_stats(), casadi::External::has_forward(), casadi::GenericExternal::has_jac_sparsity(), casadi::External::has_jacobian(), casadi::External::has_reverse(), casadi::BlazingSplineFunction::init(), casadi::External::init(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::SXFunction::init(), casadi::CvodesInterface::init(), casadi::IdasInterface::init(), casadi::External::init_external(), casadi::GenericExternal::init_external(), casadi::OnnxRuntimeInterface::init_mem(), casadi::FunctionInternal::jac_is_symm(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::map(), casadi::OracleFunction::monitored(), casadi::FunctionInternal::open_trace(), casadi::MXFunction::print_arg(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_out(), casadi::MXFunction::print_res(), casadi::SXFunction::print_res(), casadi::ProtoFunction::print_time(), casadi::ProtoFunction::ProtoFunction(), casadi::CvodesInterface::reset(), casadi::IdasInterface::reset(), casadi::IdasInterface::resetB(), casadi::FunctionInternal::reverse(), casadi::ProtoFunction::serialize_body(), casadi::GurobiInterface::solve(), casadi::SnoptInterface::solve(), casadi::Integrator::sp_forward(), casadi::Integrator::sp_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ name_in_

std::vector<std::string> casadi::FunctionInternal::name_in_
inherited

◆ name_out_

std::vector<std::string> casadi::FunctionInternal::name_out_
inherited

◆ never_inline_

bool casadi::FunctionInternal::never_inline_
inherited

◆ new_forward_

bool casadi::FmuFunction::new_forward_

Definition at line 170 of file fmu_function.hpp.

Referenced by FmuFunction(), get_forward(), has_forward(), init(), and serialize_body().

◆ new_hessian_

bool casadi::FmuFunction::new_hessian_

Definition at line 170 of file fmu_function.hpp.

Referenced by FmuFunction(), get_reverse(), init(), and serialize_body().

◆ new_jacobian_

bool casadi::FmuFunction::new_jacobian_

Definition at line 170 of file fmu_function.hpp.

Referenced by FmuFunction(), has_jacobian(), init(), and serialize_body().

◆ nfwd_

casadi_int casadi::FmuFunction::nfwd_

◆ nonlin_

std::vector<casadi_int> casadi::FmuFunction::nonlin_

Definition at line 229 of file fmu_function.hpp.

Referenced by FmuFunction(), init(), and serialize_body().

◆ options_

const Options casadi::FmuFunction::options_
static

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

Definition at line 205 of file fmu_function.hpp.

◆ out_

std::vector<OutputStruct> casadi::FmuFunction::out_

◆ parallelization_

Parallelization casadi::FmuFunction::parallelization_

◆ print_canonical_

bool casadi::FunctionInternal::print_canonical_
inherited

◆ print_in_

bool casadi::FunctionInternal::print_in_
inherited

◆ print_out_

bool casadi::FunctionInternal::print_out_
inherited

◆ print_progress_

bool casadi::FmuFunction::print_progress_

◆ print_time_

bool casadi::ProtoFunction::print_time_
inherited

◆ record_time_

bool casadi::ProtoFunction::record_time_
inherited

◆ registered_functions_

std::vector<Function> casadi::FunctionInternal::registered_functions_
inherited

◆ regularity_check_

bool casadi::ProtoFunction::regularity_check_
inherited

◆ release_

casadi_release_t casadi::FunctionInternal::release_
inherited

◆ reltol_

double casadi::FmuFunction::reltol_

◆ reverse_options_

Dict casadi::FunctionInternal::reverse_options_
inherited

◆ sp_trans_

std::vector<Sparsity> casadi::FmuFunction::sp_trans_

Definition at line 153 of file fmu_function.hpp.

Referenced by eval(), FmuFunction(), init(), and serialize_body().

◆ sp_trans_map_

std::vector<casadi_int> casadi::FmuFunction::sp_trans_map_

Definition at line 154 of file fmu_function.hpp.

Referenced by eval(), FmuFunction(), init(), and serialize_body().

◆ sparsity_in_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_in_
inherited

◆ sparsity_out_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_out_
inherited

◆ stats_

Dict casadi::FunctionInternal::stats_
inherited

◆ step_

double casadi::FmuFunction::step_

◆ user_data_

void* casadi::FunctionInternal::user_data_
inherited

◆ uses_adjoint_derivatives_

bool casadi::FmuFunction::uses_adjoint_derivatives_

Definition at line 160 of file fmu_function.hpp.

Referenced by change_option(), eval_task(), FmuFunction(), init(), and serialize_body().

◆ uses_directional_derivatives_

bool casadi::FmuFunction::uses_directional_derivatives_

◆ validate_ad_file_

std::string casadi::FmuFunction::validate_ad_file_

Definition at line 173 of file fmu_function.hpp.

Referenced by casadi::FmuInternal::eval_fd(), FmuFunction(), init(), and serialize_body().

◆ validate_forward_

bool casadi::FmuFunction::validate_forward_

◆ validate_hessian_

bool casadi::FmuFunction::validate_hessian_

Definition at line 166 of file fmu_function.hpp.

Referenced by finalize_hessian(), FmuFunction(), init(), and serialize_body().

◆ verbose_

bool casadi::ProtoFunction::verbose_
inherited

Definition at line 251 of file function_internal.hpp.

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::Integrator::advance(), casadi::ProtoFunction::change_option(), casadi::BSplineInterpolant::construct_graph(), casadi::OracleFunction::create_function(), casadi::Integrator::eval(), casadi::MXFunction::eval(), casadi::SXFunction::eval(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::SXFunction::eval_sx(), factory(), casadi::FunctionInternal::finalize(), casadi::KinsolInterface::func(), casadi::CodeGenerator::generate_dump(), casadi::ProtoFunction::generate_options(), get_forward(), casadi::Integrator::get_forward(), casadi::Integrator::get_forward_dae(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), get_jacobian(), casadi::FunctionInternal::get_partition(), get_reverse(), casadi::Integrator::get_reverse(), casadi::ProtoFunction::init(), casadi::FiniteDiff::init(), init(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::SXFunction::init(), casadi::Blocksqp::init(), casadi::MadmpecInterface::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::HpipmInterface::init(), casadi::HpmpcInterface::init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), casadi::CvodesInterface::init(), casadi::IdasInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), casadi::IpoptInterface::init_mem(), casadi::MosekInterface::init_mem(), casadi::IdasInterface::init_mem(), casadi::UnoInterface::init_mem(), casadi::SXFunction::instructions_sx(), casadi::BonminInterface::intermediate_callback(), casadi::OracleFunction::jit_dependencies(), casadi::CsparseInterface::nfact(), casadi::LapackLu::nfact(), casadi::LapackQr::nfact(), casadi::LinsolQr::nfact(), casadi::Integrator::predict_events(), casadi::ProtoFunction::ProtoFunction(), casadi::CvodesInterface::reset(), casadi::IdasInterface::reset(), casadi::IdasInterface::resetB(), casadi::ProtoFunction::serialize_body(), casadi::CbcInterface::solve(), casadi::ClpInterface::solve(), casadi::CplexInterface::solve(), casadi::GurobiInterface::solve(), casadi::HpipmInterface::solve(), casadi::QpoasesInterface::solve(), casadi::Ipqp::solve(), casadi::Qrqp::solve(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::SnoptInterface::solve(), casadi::KinsolInterface::solve(), casadi::WorhpInterface::solve(), casadi::Newton::solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Sqpmethod::solve_QP(), casadi::Integrator::sp_forward(), casadi::Integrator::sp_reverse(), and casadi::Integrator::trigger_event().

◆ which_hess_color_

std::vector<casadi_int> casadi::FmuFunction::which_hess_color_

Definition at line 226 of file fmu_function.hpp.

Referenced by eval_task(), finalize_hessian(), FmuFunction(), init(), and serialize_body().


The documentation for this class was generated from the following files: