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 | Protected Attributes
casadi::ConoptInterface Class Reference

#include <conopt_interface.hpp>

Detailed Description


List of available options
IdTypeDescriptionUsed in
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
bound_consistencyOT_BOOLEnsure that primal-dual solution is consistent with the boundscasadi::Nlpsol
cacheOT_DICTPrepopulate the function cache. Default: emptycasadi::FunctionInternal
calc_fOT_BOOLCalculate 'f' in the Nlpsol base classcasadi::Nlpsol
calc_gOT_BOOLCalculate 'g' in the Nlpsol base classcasadi::Nlpsol
calc_lam_pOT_BOOLCalculate 'lam_p' in the Nlpsol base classcasadi::Nlpsol
calc_lam_xOT_BOOLCalculate 'lam_x' in the Nlpsol base classcasadi::Nlpsol
calc_multipliersOT_BOOLCalculate Lagrange multipliers in the Nlpsol base classcasadi::Nlpsol
common_optionsOT_DICTOptions for auto-generated functionscasadi::OracleFunction
compilerOT_STRINGJust-in-time compiler plugin to be used.casadi::FunctionInternal
conoptOT_DICTOptions to be passed to CONOPTcasadi::ConoptInterface
custom_jacobianOT_FUNCTIONOverride CasADi's AD. Use together with 'jac_penalty': 0. Note: Highly experimental. Syntax may break often.casadi::FunctionInternal
debugOT_BOOLPrint debug output: constraint values at each FDEval, solution vector, and option echocasadi::ConoptInterface
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
detect_simple_boundsOT_BOOLAutomatically detect simple bounds (lbx/ubx) (default false). This is hopefully beneficial to speed and robustness but may also have adverse affects: 1) Subtleties in heuristics and stopping criteria may change the solution, 2) IPOPT may lie about multipliers of simple equality bounds unless 'fixed_variable_treatment' is set to 'relax_bounds'.casadi::Nlpsol
detect_simple_bounds_is_simpleOT_BOOLVECTORFor internal use only.casadi::Nlpsol
detect_simple_bounds_partsOT_FUNCTIONFor internal use only.casadi::Nlpsol
detect_simple_bounds_target_xOT_INTVECTORFor internal use only.casadi::Nlpsol
discreteOT_BOOLVECTORIndicates which of the variables are discrete, i.e. integer-valuedcasadi::Nlpsol
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_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_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
equalityOT_BOOLVECTORIndicate an upfront hint which of the constraints are equalities. Some solvers may be able to exploit this knowledge. When true, the corresponding lower and upper bounds are assumed equal. When false, the corresponding bounds may be equal or different.casadi::Nlpsol
error_on_failOT_BOOLThrow exceptions when function evaluation fails (default true).casadi::ProtoFunction
eval_errors_fatalOT_BOOLWhen errors occur during evaluation of f,g,...,stop the iterationscasadi::Nlpsol
exact_hessianOT_BOOLProvide exact Hessian to CONOPTcasadi::ConoptInterface
expandOT_BOOLReplace MX with SX expressions in problem formulation [false] This happens before creating derivatives unless indicated by postpone_expandcasadi::OracleFunction
external_transformOT_VECTORVECTORList of external_transform instruction arguments. Default: emptycasadi::FunctionInternal
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
ignore_check_vecOT_BOOLIf set to true, the input shape of F will not be checked.casadi::Nlpsol
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
iteration_callbackOT_FUNCTIONA function that will be called at each iteration with the solver as input. Check documentation of Callback.casadi::Nlpsol
iteration_callback_ignore_errorsOT_BOOLIf set to true, errors thrown by iteration_callback will be ignored.casadi::Nlpsol
iteration_callback_stepOT_INTOnly call the callback function every few iterations.casadi::Nlpsol
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
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
min_lamOT_DOUBLEMinimum allowed multiplier valuecasadi::Nlpsol
monitorOT_STRINGVECTORSet of user problem functions to be monitoredcasadi::OracleFunction
never_inlineOT_BOOLForbid inlining.casadi::FunctionInternal
no_nlp_gradOT_BOOLPrevent the creation of the 'nlp_grad' functioncasadi::Nlpsol
optfileOT_STRINGPath to a CONOPT option file (for string-valued CR-cells such as Algorithm)casadi::ConoptInterface
oracle_optionsOT_DICTOptions to be passed to the oracle functioncasadi::Nlpsol
post_expandOT_BOOLAfter construction, expand this Function. Default: Falsecasadi::FunctionInternal
post_expand_optionsOT_DICTOptions to be passed to post-construction expansion. Default: emptycasadi::FunctionInternal
postpone_expandOT_BOOLWhen expand is active, postpone it until after creation of derivatives. Default: Falsecasadi::OracleFunction
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_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
reverse_optionsOT_DICTOptions to be passed to a reverse mode constructorcasadi::FunctionInternal
sens_linsolOT_STRINGLinear solver used for parametric sensitivities (default 'qr').casadi::Nlpsol
sens_linsol_optionsOT_DICTLinear solver options used for parametric sensitivities.casadi::Nlpsol
show_eval_warningsOT_BOOLShow warnings generated from function evaluations [true]casadi::OracleFunction
specific_optionsOT_DICTOptions for specific auto-generated functions, overwriting the defaults from common_options. Nested dictionary.casadi::OracleFunction
user_dataOT_VOIDPTRA user-defined field that can be used to identify the function or pass additional informationcasadi::FunctionInternal
verboseOT_BOOLVerbose evaluation – for debuggingcasadi::ProtoFunction
verbose_initOT_BOOLPrint out timing information about the different stages of initializationcasadi::Nlpsol
warm_startOT_BOOLWarm-start CONOPT using multipliers from a prior solve to infer basis status (IniStat=2)casadi::ConoptInterface
warn_initial_boundsOT_BOOLWarn if the initial guess does not satisfy LBX and UBXcasadi::Nlpsol

Definition at line 139 of file conopt_interface.hpp.

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

Public Types

typedef Nlpsol *(* Creator) (const std::string &name, const Function &oracle)
 
using weak_ref_type = WeakRefInternal
 
typedef int(* RegFcn) (Plugin *plugin)
 

Public Member Functions

 ConoptInterface (const std::string &name, const Function &nlp)
 
 ~ConoptInterface () override
 
const char * plugin_name () const override
 
std::string class_name () const override
 Get type name. More...
 
const Optionsget_options () const override
 Options. More...
 
void init (const Dict &opts) override
 Initialize. 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...
 
void set_work (void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
 Set the (persistent) work vectors. More...
 
int solve (void *mem) const override
 
Dict get_stats (void *mem) const override
 Get all statistics. More...
 
void ensure_row_capacity (ConoptMemory *m, casadi_int remaining_rows) const
 
void serialize_body (SerializingStream &s) const override
 Serialize an object without type information. More...
 
void serialize_type (SerializingStream &s) const override
 Serialize type information. More...
 
std::string serialize_base_function () const override
 String used to identify the immediate FunctionInternal subclass. More...
 
void disp_more (std::ostream &stream) const override
 Print description. More...
 
virtual void check_inputs (void *mem) const
 Check if the inputs correspond to a well-posed problem. More...
 
double get_default_in (casadi_int ind) const override
 Get default input value. More...
 
virtual bool integer_support () const
 Can discrete variables be treated. More...
 
int eval (const double **arg, double **res, casadi_int *iw, double *w, void *mem) const final
 Evaluate numerically. More...
 
void codegen_declarations (CodeGenerator &g) const override
 Generate code for the declarations of the C function. More...
 
void codegen_body_enter (CodeGenerator &g) const override
 Generate code for the function body. More...
 
void codegen_body_exit (CodeGenerator &g) const override
 Generate code for the function body. More...
 
void codegen_setup_constants (CodeGenerator &g, const std::string &d_nlp, const std::string &p_nlp, const std::string &d_oracle) const
 
void codegen_setup_per_call (CodeGenerator &g, const std::string &d_nlp) const
 
void codegen_post_solve (CodeGenerator &g, const std::string &d_nlp) const
 
bool uses_output () const override
 Do the derivative functions need nondifferentiated outputs? More...
 
int callback (NlpsolMemory *m) const
 
Function kkt () const
 
bool is_a (const std::string &type, bool recursive) const override
 Check if the function is of a particular type. More...
 
virtual DM getReducedHessian ()
 
virtual void setOptionsFromFile (const std::string &file)
 Read options from parameter xml. More...
 
void finalize () override
 Finalize initialization. More...
 
void join_results (OracleMemory *m) const
 Combine results from different threads. More...
 
const Functionoracle () const override
 Get oracle. More...
 
void expand ()
 
Function create_function (const Function &oracle, const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())
 
Function create_function (const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())
 
Function create_function (const std::string &fname, const std::vector< MX > &e_in, const std::vector< MX > &e_out, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Dict &opts=Dict())
 
Function create_forward (const std::string &fname, casadi_int nfwd)
 
void set_function (const Function &fcn, const std::string &fname, bool jit=false)
 
void set_function (const Function &fcn)
 
int calc_function (OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
 
int calc_sp_forward (const std::string &fcn, const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
 
int calc_sp_reverse (const std::string &fcn, bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
 
std::vector< std::string > get_function () const override
 Get list of dependency functions. More...
 
const Functionget_function (const std::string &name) const override
 
void find (std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, casadi_int max_depth) const override
 
virtual bool monitored (const std::string &name) const
 
bool has_function (const std::string &fname) const override
 
std::string generate_dependencies (const std::string &fname, const Dict &opts) const override
 Export / Generate C code for the generated functions. More...
 
void jit_dependencies (const std::string &fname) override
 JIT for dependencies. More...
 
int local_init_mem (void *mem) const
 Initalize memory block. More...
 
void set_temp (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const override
 Set the work vectors. 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 change_option (const std::string &option_name, const GenericType &option_value) override
 Change option after object creation for debugging. More...
 
void reset_dump_count ()
 Reset the counter used to name dump files. More...
 
Function self () const
 Get a public class instance. More...
 
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
 
void add_embedded (std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, const Function &dep, 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< MXmapsum_mx (const std::vector< MX > &arg, const std::string &parallelization)
 Parallel evaluation. 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...
 
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< MXfree_mx () const
 Get free variables (MX) More...
 
virtual std::vector< SXfree_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_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 bool has_codegen () const
 Is codegen supported? More...
 
virtual void export_code (const std::string &lang, std::ostream &stream, const Dict &options) const
 Export function in a specific language. More...
 
void disp (std::ostream &stream, bool more) const override
 Display object. 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_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 std::vector< double > get_nominal_in (casadi_int ind) const
 
virtual std::vector< double > get_nominal_out (casadi_int ind) const
 
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...
 
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 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...
 
virtual void check_mem_count (casadi_int n) const
 Check for validatity of memory object count. 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...
 
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...
 
virtual void deps_version_check (const std::string &stage) const
 
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
 Sparsities of function inputs and outputs. More...
 
Sparsity get_sparsity_out (casadi_int i) override
 Sparsities of function inputs and outputs. More...
 
std::string get_name_in (casadi_int i) override
 Names of function input and outputs. More...
 
std::string get_name_out (casadi_int i) override
 Names of function input and outputs. More...
 
bool has_forward (casadi_int nfwd) const override
 Generate a function that calculates forward mode 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
 Generate a function that calculates forward mode derivatives. More...
 
bool has_reverse (casadi_int nadj) const override
 Generate a function that calculates reverse mode derivatives. 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
 Generate a function that calculates reverse mode derivatives. 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< DMeval_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< DMnz_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< DMnz_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...
 
virtual bool has_jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual Function get_jacobian (const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
 Return Jacobian of all input elements with respect to all output elements. More...
 
Sparsityjac_sparsity (casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
 Get Jacobian sparsity. More...
 
virtual bool has_jac_sparsity (casadi_int oind, casadi_int iind) const
 Get Jacobian sparsity. More...
 
virtual Sparsity get_jac_sparsity (casadi_int oind, casadi_int iind, 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< SXsx_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< SXsx_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< MXmx_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< MXmx_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< DMdm_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< DMdm_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 Sparsitysparsity_in (casadi_int ind) const
 Input/output sparsity. More...
 
const Sparsitysparsity_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< MXsymbolic_output (const std::vector< MX > &arg) const
 Get a vector of symbolic variables corresponding to the 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 Nlpsolcreator (const std::string &name, const Function &nlp)
 
static ProtoFunctiondeserialize (DeserializingStream &s)
 
static int COI_CALLCONV cb_read_matrix (double LOWER[], double CURR[], double UPPER[], int VSTA[], int TYPEX[], double RHS[], int ESTA[], int COLSTA[], int ROWNO[], double VALUE[], int NLFLAG[], int NUMVAR, int NUMCON, int NUMNZ, void *USRMEM)
 
static int COI_CALLCONV cb_fdevalini (const double X[], const int ROWLIST[], int MODE, int LISTSIZE, int NUMTHREAD, int IGNERR, int *ERRCNT, int NUMVAR, void *USRMEM)
 
static int COI_CALLCONV cb_fd_eval (const double X[], double *G, double JAC[], int ROWNO, const int JACNUM[], int MODE, int IGNERR, int *ERRCNT, int NUMVAR, int NUMJAC, int THREAD, void *USRMEM)
 
static int COI_CALLCONV cb_fdevalend (int IGNERR, int *ERRCNT, void *USRMEM)
 
static int COI_CALLCONV cb_status (int MODSTA, int SOLSTA, int ITER, double OBJVAL, void *USRMEM)
 
static int COI_CALLCONV cb_solution (const double XVAL[], const double XMAR[], const int XBAS[], const int XSTA[], const double YVAL[], const double YMAR[], const int YBAS[], const int YSTA[], int NUMVAR, int NUMCON, void *USRMEM)
 
static int COI_CALLCONV cb_message (int SMSG, int DMSG, int NMSG, char *MSGV[], void *USRMEM)
 
static int COI_CALLCONV cb_errmsg (int ROWNO, int COLNO, int POSNO, const char *MSG, void *USRMEM)
 
static int COI_CALLCONV cb_option (int NCALL, double *RVAL, int *IVAL, int *LVAL, char *NAME, void *USRMEM)
 
static int COI_CALLCONV cb_progress (int LEN_INT, const int INTX[], int LEN_RL, const double RL[], const double X[], void *USRMEM)
 
static int COI_CALLCONV cb_2dlagrstr (int HSRW[], int HSCL[], int *NODRV, int NUMVAR, int NUMCON, int NHESS, void *USRMEM)
 
static int COI_CALLCONV cb_2dlagrval (const double X[], const double U[], const int HSRW[], const int HSCL[], double HSVL[], int *NODRV, int NUMVAR, int NUMCON, int NHESS, void *USRMEM)
 
static void bound_consistency (casadi_int n, double *z, double *lam, const double *lbz, const double *ubz)
 
static std::string shortname ()
 Short name. More...
 
template<typename Type >
static void append_to_vec (GenericType &t, Type el)
 WORKAROUND: Add an element to an std::vector stored in a GenericType: More...
 
template<typename XType >
static Function create_oracle (const std::map< std::string, XType > &d, const Dict &opts)
 Convert dictionary to Problem. 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 has_plugin (const std::string &pname, bool verbose=false)
 Check if a plugin is available or can be loaded. More...
 
static const Optionsplugin_options (const std::string &pname)
 Get the plugin options. More...
 
static Deserialize plugin_deserialize (const std::string &pname)
 Get the plugin deserialize_map. More...
 
static Plugin pluginFromRegFcn (RegFcn regfcn)
 Instantiate a Plugin struct from a factory function. More...
 
static Plugin load_plugin (const std::string &pname, bool register_plugin=true, bool needs_lock=true)
 Load a plugin dynamically. More...
 
static handle_t load_library (const std::string &libname, std::string &resultpath, bool global)
 Load a library dynamically. More...
 
static void registerPlugin (const Plugin &plugin, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static void registerPlugin (RegFcn regfcn, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static Plugin & getPlugin (const std::string &pname)
 Load and get the creator function. More...
 
static Nlpsolinstantiate (const std::string &fname, const std::string &pname, Problem problem)
 
static bool check_mat (const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
 

Public Attributes

Sparsity gradf_sp_
 
Sparsity jacg_sp_
 
Sparsity hesslag_sp_
 
bool exact_hessian_
 
bool warm_start_
 
bool debug_
 
Dict opts_
 
std::string optfile_
 
std::vector< bool > gradf_col_flag_
 
std::vector< int > jacg_rowstart_
 
std::vector< int > jacg_nzidx_
 
std::vector< int > jacg_col_
 
std::vector< int > jacg_nlflag_
 
bool has_linear_jac_
 
std::vector< int > gradf_nlflag_
 
bool has_linear_gradf_
 
std::vector< casadi_int > gradf_col_to_nz_
 
casadi_nlpsol_prob< double > p_nlp_
 
casadi_int nx_
 Number of variables. More...
 
casadi_int ng_
 Number of constraints. More...
 
casadi_int np_
 Number of parameters. More...
 
Function fcallback_
 callback function, executed at each iteration More...
 
casadi_int callback_step_
 Execute the callback function only after this amount of iterations. More...
 
std::string sens_linsol_
 Linear solver and options. More...
 
Dict sens_linsol_options_
 
std::vector< char > detect_simple_bounds_is_simple_
 
Function detect_simple_bounds_parts_
 
std::vector< casadi_int > detect_simple_bounds_target_x_
 
std::vector< casadi_int > detect_simple_bounds_target_g_
 
bool mi_
 
WeakRef kkt_
 Cache for KKT function. More...
 
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< Sparsitysparsity_in_
 Input and output sparsity. More...
 
std::vector< Sparsitysparsity_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, Functioncache_
 Function cache. More...
 
std::vector< Sparsityjac_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< Functionregistered_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...
 
bool eval_errors_fatal_
 Options. More...
 
bool warn_initial_bounds_
 Options. More...
 
bool iteration_callback_ignore_errors_
 Options. More...
 
bool calc_multipliers_
 Options. More...
 
bool calc_lam_x_
 Options. More...
 
bool calc_lam_p_
 Options. More...
 
bool calc_f_
 Options. More...
 
bool calc_g_
 Options. More...
 
bool bound_consistency_
 Options. More...
 
double min_lam_
 Options. More...
 
bool no_nlp_grad_
 Options. More...
 
std::vector< bool > discrete_
 Options. More...
 
std::vector< bool > equality_
 Options. More...
 

Static Public Attributes

static const Options options_
 
static const std::string meta_doc
 A documentation string. More...
 
static std::map< std::string, Plugin > solvers_
 Collection of solvers. More...
 
static const std::string infix_ = "nlpsol"
 Infix. More...
 
static std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> deserialize_map
 

Protected Member Functions

 ConoptInterface (DeserializingStream &s)
 
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 ()
 
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)
 

Protected Attributes

Function oracle_
 Oracle: Used to generate other functions. More...
 
Dict common_options_
 Options for creating functions. More...
 
Dict specific_options_
 
bool show_eval_warnings_
 Show evaluation warnings. More...
 
int max_num_threads_
 
std::map< std::string, RegFunall_functions_
 
std::vector< std::string > monitor_
 
size_t stride_arg_
 
size_t stride_res_
 
size_t stride_iw_
 
size_t stride_w_
 
bool post_expand_
 

Member Typedef Documentation

◆ Creator

typedef Nlpsol*(* casadi::Nlpsol::Creator) (const std::string &name, const Function &oracle)
inherited

Definition at line 296 of file nlpsol_impl.hpp.

◆ RegFcn

typedef int(* casadi::PluginInterface< Nlpsol >::RegFcn) (Plugin *plugin)
inherited

Definition at line 73 of file plugin_interface.hpp.

◆ weak_ref_type

Definition at line 152 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ ConoptInterface() [1/2]

casadi::ConoptInterface::ConoptInterface ( const std::string &  name,
const Function nlp 
)
explicit

Definition at line 66 of file conopt_interface.cpp.

67  : Nlpsol(name, nlp) {}
Nlpsol(const std::string &name, const Function &oracle)
Constructor.
Definition: nlpsol.cpp:346

◆ ~ConoptInterface()

casadi::ConoptInterface::~ConoptInterface ( )
override

Definition at line 69 of file conopt_interface.cpp.

69 { clear_mem(); }
void clear_mem()
Clear all memory (called from destructor)

References casadi::ProtoFunction::clear_mem().

◆ ConoptInterface() [2/2]

casadi::ConoptInterface::ConoptInterface ( DeserializingStream s)
explicitprotected

Definition at line 168 of file conopt_interface.cpp.

168  : Nlpsol(s) {
169  s.version("ConoptInterface", 1);
170  s.unpack("ConoptInterface::exact_hessian", exact_hessian_);
171  s.unpack("ConoptInterface::opts", opts_);
172  s.unpack("ConoptInterface::gradf_sp", gradf_sp_);
173  s.unpack("ConoptInterface::jacg_sp", jacg_sp_);
174  s.unpack("ConoptInterface::hesslag_sp", hesslag_sp_);
175  s.unpack("ConoptInterface::optfile", optfile_);
176  s.unpack("ConoptInterface::warm_start", warm_start_);
177  s.unpack("ConoptInterface::debug", debug_);
178 
179  // Recompute linearity flags first (needed for CSR construction below)
180  {
181  Sparsity djac_dx = get_function("nlp_jac_g").sparsity_jac(0, 1, true);
182  jacg_nlflag_.assign(jacg_sp_.nnz(), 0);
183  const casadi_int* dj_row = djac_dx.row();
184  for (casadi_int el = 0; el < djac_dx.nnz(); ++el)
185  jacg_nlflag_[dj_row[el]] = 1;
186  has_linear_jac_ = std::any_of(jacg_nlflag_.begin(), jacg_nlflag_.end(),
187  [](int f) { return f == 0; });
188  }
189 
190  // Rebuild derived arrays from the serialized sparsities
191  const casadi_int* f_row = gradf_sp_.row();
192  gradf_col_flag_.assign(nx_, false);
193  gradf_col_to_nz_.assign(nx_, -1);
194  for (casadi_int k = 0; k < gradf_sp_.nnz(); ++k) {
195  gradf_col_flag_[f_row[k]] = true;
196  gradf_col_to_nz_[f_row[k]] = k;
197  }
198 
199  {
200  Sparsity dgradf_dx = get_function("nlp_grad_f").sparsity_jac(0, 1, true);
201  gradf_nlflag_.assign(gradf_sp_.nnz(), 0);
202  const casadi_int* dg_row = dgradf_dx.row();
203  for (casadi_int el = 0; el < dgradf_dx.nnz(); ++el)
204  gradf_nlflag_[dg_row[el]] = 1;
205  has_linear_gradf_ = std::any_of(gradf_nlflag_.begin(), gradf_nlflag_.end(),
206  [](int f) { return f == 0; });
207  }
208 
209  const casadi_int* g_colind = jacg_sp_.colind();
210  const casadi_int* g_row = jacg_sp_.row();
211  casadi_int nnz_g = jacg_sp_.nnz();
212  jacg_rowstart_.assign(ng_ + 1, 0);
213  for (casadi_int el = 0; el < nnz_g; ++el)
214  if (jacg_nlflag_[el]) jacg_rowstart_[g_row[el] + 1]++;
215  for (int r = 0; r < ng_; ++r)
216  jacg_rowstart_[r + 1] += jacg_rowstart_[r];
217  jacg_nzidx_.resize(jacg_rowstart_[ng_]);
218  jacg_col_.resize(jacg_rowstart_[ng_]);
219  std::vector<int> fill_pos(ng_, 0);
220  for (int c = 0; c < nx_; ++c)
221  for (casadi_int el = g_colind[c]; el < g_colind[c+1]; ++el) {
222  if (!jacg_nlflag_[el]) continue;
223  int r = static_cast<int>(g_row[el]);
224  casadi_assert(fill_pos[r] < jacg_rowstart_[r + 1] - jacg_rowstart_[r],
225  "CSR fill overflow for row r - count/fill pass mismatch in jacg_rowstart_");
226  int pos = jacg_rowstart_[r] + fill_pos[r]++;
227  jacg_nzidx_[pos] = static_cast<int>(el);
228  jacg_col_[pos] = c;
229  }
230  }
std::vector< int > jacg_nlflag_
std::vector< bool > gradf_col_flag_
std::vector< int > jacg_rowstart_
std::vector< casadi_int > gradf_col_to_nz_
std::vector< int > gradf_nlflag_
std::vector< int > jacg_nzidx_
std::vector< int > jacg_col_
casadi_int ng_
Number of constraints.
Definition: nlpsol_impl.hpp:69
casadi_int nx_
Number of variables.
Definition: nlpsol_impl.hpp:66
std::vector< std::string > get_function() const override
Get list of dependency functions.
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148
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::Sparsity::colind(), debug_, exact_hessian_, casadi::OracleFunction::get_function(), gradf_col_flag_, gradf_col_to_nz_, gradf_nlflag_, gradf_sp_, has_linear_gradf_, has_linear_jac_, hesslag_sp_, jacg_col_, jacg_nlflag_, jacg_nzidx_, jacg_rowstart_, jacg_sp_, casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::Nlpsol::nx_, optfile_, opts_, casadi::Sparsity::row(), casadi::DeserializingStream::unpack(), casadi::DeserializingStream::version(), and warm_start_.

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_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.
size_t n_in_
Number of inputs and outputs.
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().

◆ 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::ConoptInterface::alloc_mem ( ) const
inlineoverridevirtual

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

Reimplemented from casadi::Nlpsol.

Definition at line 158 of file conopt_interface.hpp.

158 { return new ConoptMemory(*this); }

◆ 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(), casadi::FmuFunction::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().

◆ append_to_vec()

template<typename Type >
static void casadi::Nlpsol::append_to_vec ( GenericType t,
Type  el 
)
inlinestaticinherited

Definition at line 331 of file nlpsol_impl.hpp.

331  {
332  std::vector<Type> v = t;
333  v.push_back(el);
334  t = v;
335  }

◆ bound_consistency()

void casadi::Nlpsol::bound_consistency ( casadi_int  n,
double *  z,
double *  lam,
const double *  lbz,
const double *  ubz 
)
staticinherited

Definition at line 767 of file nlpsol.cpp.

768  {
769  casadi_assert_dev(z!=nullptr);
770  casadi_assert_dev(lam!=nullptr);
771  casadi_assert_dev(lbz!=nullptr);
772  casadi_assert_dev(ubz!=nullptr);
773  // Local variables
774  casadi_int i;
775  // Loop over variables
776  for (i=0; i<n; ++i) {
777  // Make sure bounds are respected
778  z[i] = std::fmin(std::fmax(z[i], lbz[i]), ubz[i]);
779  // Adjust multipliers
780  if (std::isinf(lbz[i]) && std::isinf(ubz[i])) {
781  // Both multipliers are infinite
782  lam[i] = 0.;
783  } else if (std::isinf(lbz[i]) || z[i] - lbz[i] > ubz[i] - z[i]) {
784  // Infinite lower bound or closer to upper bound than lower bound
785  lam[i] = std::fmax(0., lam[i]);
786  } else if (std::isinf(ubz[i]) || z[i] - lbz[i] < ubz[i] - z[i]) {
787  // Infinite upper bound or closer to lower bound than upper bound
788  lam[i] = std::fmin(0., lam[i]);
789  }
790  }
791  }

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

◆ 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_.

◆ calc_function()

int casadi::OracleFunction::calc_function ( OracleMemory m,
const std::string &  fcn,
const double *const *  arg = nullptr,
int  thread_id = 0 
) const
inherited

Definition at line 302 of file oracle_function.cpp.

304  {
305  auto *ml = m->thread_local_mem.at(thread_id);
306  // Is the function monitored?
307  bool monitored = this->monitored(fcn);
308 
309  // Print progress
310  if (monitored) casadi_message("Calling \"" + fcn + "\"");
311 
312  // Respond to a possible Crl+C signals
313  // Python interrupt checker needs the GIL.
314  // We may not have access to it in a multi-threaded context
315  // See issue #2955
317 
318  // Get function
319  const Function& f = get_function(fcn);
320 
321  // Get statistics structure
322  FStats& fstats = ml->fstats.at(fcn);
323 
324  // Number of inputs and outputs
325  casadi_int n_in = f.n_in(), n_out = f.n_out();
326 
327  // Prepare stats, start timer
328  ScopedTiming tic(fstats);
329 
330  // Input buffers
331  if (arg) {
332  std::fill_n(ml->arg, n_in, nullptr);
333  for (casadi_int i=0; i<n_in; ++i) ml->arg[i] = *arg++;
334  }
335 
336  // Print inputs nonzeros
337  if (monitored) {
338  std::stringstream s;
339  s << fcn << " input nonzeros:\n";
340  for (casadi_int i=0; i<n_in; ++i) {
341  s << " " << i << " (" << f.name_in(i) << "): ";
342  if (ml->arg[i]) {
343  // Print nonzeros
344  s << "[";
345  for (casadi_int k=0; k<f.nnz_in(i); ++k) {
346  if (k!=0) s << ", ";
347  DM::print_scalar(s, ml->arg[i][k]);
348  }
349  s << "]\n";
350  } else {
351  // All zero input
352  s << "0\n";
353  }
354  }
355  casadi_message(s.str());
356  }
357 
358  // Evaluate memory-less
359  try {
360  if (f(ml->arg, ml->res, ml->iw, ml->w)) {
361  // Recoverable error
362  if (monitored) casadi_message(name_ + ":" + fcn + " failed");
363  return 1;
364  }
365  } catch(std::exception& ex) {
366  // Fatal error: Generate stack trace
367  casadi_error("Error in " + name_ + ":" + fcn + ":" + std::string(ex.what()));
368  }
369 
370  // Print output nonzeros
371  if (monitored) {
372  std::stringstream s;
373  s << fcn << " output nonzeros:\n";
374  for (casadi_int i=0; i<n_out; ++i) {
375  s << " " << i << " (" << f.name_out(i) << "): ";
376  if (ml->res[i]) {
377  // Print nonzeros
378  s << "[";
379  for (casadi_int k=0; k<f.nnz_out(i); ++k) {
380  if (k!=0) s << ", ";
381  DM::print_scalar(s, ml->res[i][k]);
382  }
383  s << "]\n";
384  } else {
385  // Ignored output
386  s << " N/A\n";
387  }
388  }
389  casadi_message(s.str());
390  }
391 
392  // Make sure not NaN or Inf
393  for (casadi_int i=0; i<n_out; ++i) {
394  if (!ml->res[i]) continue;
395  if (!std::all_of(ml->res[i], ml->res[i]+f.nnz_out(i), [](double v) { return isfinite(v);})) {
396  std::stringstream ss;
397 
398  auto *it = std::find_if(ml->res[i], ml->res[i] + f.nnz_out(i),
399  [](double v) { return !isfinite(v);});
400  casadi_int k = std::distance(ml->res[i], it);
401  bool is_nan = isnan(ml->res[i][k]);
402  ss << name_ << ":" << fcn << " failed: " << (is_nan? "NaN" : "Inf") <<
403  " detected for output " << f.name_out(i) << ", at " << f.sparsity_out(i).repr_el(k) << ".";
404 
405  if (regularity_check_) {
406  casadi_error(ss.str());
407  } else {
408  if (show_eval_warnings_) casadi_warning(ss.str());
409  }
410  return -1;
411  }
412  }
413 
414  // Success
415  return 0;
416 }
static void check()
Raises an error if an interrupt was captured.
void print_scalar(std::ostream &stream) const
Print scalar.
virtual bool monitored(const std::string &name) const
bool show_eval_warnings_
Show evaluation warnings.
bool regularity_check_
Errors are thrown when NaN is produced.

References casadi::InterruptHandler::check(), casadi::OracleFunction::get_function(), casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::monitored(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::nnz_in(), casadi::Function::nnz_out(), casadi::Matrix< double >::print_scalar(), casadi::ProtoFunction::regularity_check_, casadi::Sparsity::repr_el(), casadi::OracleFunction::show_eval_warnings_, casadi::Function::sparsity_out(), and casadi::OracleMemory::thread_local_mem.

Referenced by casadi::KinsolInterface::bjac(), casadi::SundialsInterface::calc_daeB(), casadi::SundialsInterface::calc_daeF(), casadi::Integrator::calc_edot(), casadi::calc_function(), casadi::SundialsInterface::calc_jacF(), casadi::SundialsInterface::calc_jtimesF(), casadi::SundialsInterface::calc_quadB(), casadi::SundialsInterface::calc_quadF(), casadi::casadi_func_cons_jac(), casadi::casadi_func_cons_val(), casadi::casadi_func_hess_prod(), casadi::casadi_func_obj_grad(), casadi::casadi_func_obj_val(), cb_2dlagrval(), casadi::KinsolInterface::djac(), casadi::Nlpsol::eval(), casadi::AlpaqaProblem::eval_f(), casadi::BonminUserClass::eval_f(), casadi::IpoptUserClass::eval_f(), casadi::AlpaqaProblem::eval_f_grad_f(), casadi::AlpaqaProblem::eval_g(), casadi::BonminUserClass::eval_g(), casadi::IpoptUserClass::eval_g(), casadi::BonminUserClass::eval_grad_f(), casadi::IpoptUserClass::eval_grad_f(), casadi::AlpaqaProblem::eval_grad_L(), casadi::BonminUserClass::eval_h(), casadi::IpoptUserClass::eval_h(), casadi::AlpaqaProblem::eval_hess_L(), casadi::AlpaqaProblem::eval_hess_L_prod(), casadi::AlpaqaProblem::eval_hess_ψ(), casadi::AlpaqaProblem::eval_hess_ψ_prod(), casadi::AlpaqaProblem::eval_jac_g(), casadi::BonminUserClass::eval_jac_g(), casadi::IpoptUserClass::eval_jac_g(), casadi::AlpaqaProblem::eval_ψ(), casadi::AlpaqaProblem::eval_ψ_grad_ψ(), casadi::Blocksqp::evaluate(), casadi::Feasiblesqpmethod::feasibility_iterations(), casadi::KinsolInterface::psetup(), solve(), casadi::KnitroInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), casadi::Feasiblesqpmethod::solve(), casadi::Newton::solve(), casadi::Qrsqp::solve(), casadi::Sqpmethod::solve(), casadi::FixedStepIntegrator::stepB(), casadi::FixedStepIntegrator::stepF(), casadi::Integrator::trigger_event(), and casadi::SnoptInterface::userfun().

◆ calc_sp_forward()

int casadi::OracleFunction::calc_sp_forward ( const std::string &  fcn,
const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w 
) const
inherited

◆ calc_sp_reverse()

int casadi::OracleFunction::calc_sp_reverse ( const std::string &  fcn,
bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w 
) const
inherited

◆ 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.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.

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().

◆ callback()

int casadi::Nlpsol::callback ( NlpsolMemory m) const
inherited

Definition at line 1210 of file nlpsol.cpp.

1210  {
1211  // Quick return if no callback function
1212  if (fcallback_.is_null()) return 0;
1213  // Callback inputs
1214  std::fill_n(m->arg, fcallback_.n_in(), nullptr);
1215 
1216  auto *d_nlp = &m->d_nlp;
1217 
1218  m->arg[NLPSOL_X] = d_nlp->z;
1219  m->arg[NLPSOL_F] = &d_nlp->objective;
1220  m->arg[NLPSOL_G] = d_nlp->z + nx_;
1221  m->arg[NLPSOL_LAM_G] = d_nlp->lam + nx_;
1222  m->arg[NLPSOL_LAM_X] = d_nlp->lam;
1223 
1224  // Callback outputs
1225  std::fill_n(m->res, fcallback_.n_out(), nullptr);
1226  double ret = 0;
1227  m->res[0] = &ret;
1228 
1229  // Start timer
1230  m->fstats.at("callback_fun").tic();
1231  try {
1232  // Evaluate
1233  fcallback_(m->arg, m->res, m->iw, m->w, 0);
1234  } catch(KeyboardInterruptException& ex) {
1235  (void)ex; // unused
1236  throw;
1237  } catch(std::exception& ex) {
1238  print("WARNING: intermediate_callback error: %s\n", ex.what());
1240  }
1241 
1242  // User user interruption?
1243  if (static_cast<casadi_int>(ret)) return 1;
1244 
1245  // Stop timer
1246  m->fstats.at("callback_fun").toc();
1247 
1248  return 0;
1249  }
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
bool is_null() const
Is a null pointer?
bool iteration_callback_ignore_errors_
Options.
Definition: nlpsol_impl.hpp:95
Function fcallback_
callback function, executed at each iteration
Definition: nlpsol_impl.hpp:75
void print(const char *fmt,...) const
C-style formatted printing during evaluation.
@ NLPSOL_G
Constraints function at the optimal solution (ng x 1)
Definition: nlpsol.hpp:221
@ NLPSOL_X
Decision variables at the optimal solution (nx x 1)
Definition: nlpsol.hpp:217
@ NLPSOL_F
Cost function value at the optimal solution (1 x 1)
Definition: nlpsol.hpp:219
@ NLPSOL_LAM_G
Lagrange multipliers for bounds on G at the solution (ng x 1)
Definition: nlpsol.hpp:225
@ NLPSOL_LAM_X
Lagrange multipliers for bounds on X at the solution (nx x 1)
Definition: nlpsol.hpp:223

References casadi::OracleMemory::arg, casadi::NlpsolMemory::d_nlp, casadi::Nlpsol::fcallback_, casadi::ProtoFunctionMemory::fstats, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Nlpsol::iteration_callback_ignore_errors_, casadi::OracleMemory::iw, casadi::Function::n_in(), casadi::Function::n_out(), casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_X, casadi::NLPSOL_X, casadi::Nlpsol::nx_, casadi::ProtoFunction::print(), casadi::OracleMemory::res, casadi::OracleMemory::w, and casadi::CasadiException::what().

Referenced by casadi::Feasiblesqpmethod::solve(), casadi::Qrsqp::solve(), and casadi::Sqpmethod::solve().

◆ cb_2dlagrstr()

int COI_CALLCONV casadi::ConoptInterface::cb_2dlagrstr ( int  HSRW[],
int  HSCL[],
int *  NODRV,
int  NUMVAR,
int  NUMCON,
int  NHESS,
void *  USRMEM 
)
static

Definition at line 985 of file conopt_interface.cpp.

987  {
988  auto m = static_cast<ConoptMemory*>(USRMEM);
989  const ConoptInterface& self = m->self;
990  const casadi_int* colind = self.hesslag_sp_.colind();
991  const casadi_int* row = self.hesslag_sp_.row();
992 
993  int idx = 0;
994  for (int c = 0; c < NUMVAR; ++c) {
995  for (casadi_int el = colind[c]; el < colind[c+1]; ++el) {
996  HSRW[idx] = row[el];
997  HSCL[idx] = c;
998  idx++;
999  }
1000  }
1001  casadi_assert(idx == NHESS,
1002  "cb_2dlagrstr: idx != NHESS - Hessian nonzero count mismatch");
1003  return 0;
1004  }
ConoptInterface(const std::string &name, const Function &nlp)

References casadi::FunctionInternal::self().

Referenced by init_mem().

◆ cb_2dlagrval()

int COI_CALLCONV casadi::ConoptInterface::cb_2dlagrval ( const double  X[],
const double  U[],
const int  HSRW[],
const int  HSCL[],
double  HSVL[],
int *  NODRV,
int  NUMVAR,
int  NUMCON,
int  NHESS,
void *  USRMEM 
)
static

Definition at line 1006 of file conopt_interface.cpp.

1009  {
1010  auto m = static_cast<ConoptMemory*>(USRMEM);
1011  const ConoptInterface& self = m->self;
1012 
1013  // CONOPT's Lagrangian: L = SUM(r) U(r) * F(r), so d²L/dx² = SUM(r) U(r) * d²F(r)/dx².
1014  // CasADi computes lam_f*d²f/dx² + lam_g^T*d²g/dx², so lam_f = U[0], lam_g[ci] = U[row_ci].
1015  double obj_factor = U[0];
1016 
1017  for (int ci = 0; ci < self.ng_; ++ci) {
1018  int row1 = m->casadi_to_conopt_lb_row[ci];
1019  int row2 = m->casadi_to_conopt_ub_row[ci];
1020  m->hess_lam_g_[ci] = U[row1] + (row2 >= 0 ? U[row2] : 0.0);
1021  }
1022 
1023  if (self.debug_) {
1024  casadi::uout() << "Hessian lam_f=" << obj_factor << " lam_g:";
1025  for (int ci = 0; ci < self.ng_; ++ci)
1026  casadi::uout() << " " << m->hess_lam_g_[ci];
1027  casadi::uout() << "\n";
1028  }
1029 
1030  m->arg[0] = X;
1031  m->arg[1] = m->d_nlp.p;
1032  m->arg[2] = &obj_factor;
1033  m->arg[3] = m->hess_lam_g_.data();
1034  m->res[0] = HSVL;
1035 
1036  try {
1037  if (self.calc_function(m, "nlp_hess_l")) {
1038  *NODRV = 1;
1039  return 0;
1040  }
1041  if (self.debug_) {
1042  casadi::uout() << "Hessian values (HSVL):";
1043  for (int i = 0; i < NHESS; ++i)
1044  casadi::uout() << " " << HSVL[i];
1045  casadi::uout() << "\n";
1046  }
1047  } catch (std::exception& ex) {
1048  casadi::uerr() << "CONOPT: nlp_hess_l failed: " << ex.what() << std::endl;
1049  *NODRV = 1;
1050  } catch (...) {
1051  casadi::uerr() << "CONOPT: nlp_hess_l failed (unknown exception)" << std::endl;
1052  *NODRV = 1;
1053  }
1054  return 0;
1055  }
int calc_function(OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
std::ostream & uerr()
std::ostream & uout()

References casadi::OracleFunction::calc_function(), debug_, casadi::FunctionInternal::self(), casadi::U, casadi::uerr(), casadi::uout(), and casadi::X.

Referenced by init_mem().

◆ cb_errmsg()

int COI_CALLCONV casadi::ConoptInterface::cb_errmsg ( int  ROWNO,
int  COLNO,
int  POSNO,
const char *  MSG,
void *  USRMEM 
)
static

Definition at line 1162 of file conopt_interface.cpp.

1163  {
1164  if (MSG == nullptr) return 0;
1165 
1166  std::string prefix = "CONOPT Error: ";
1167  if (COLNO == -1 && ROWNO >= 0) {
1168  prefix += "Row " + std::to_string(ROWNO) + " - ";
1169  } else if (ROWNO == -1 && COLNO >= 0) {
1170  prefix += "Column " + std::to_string(COLNO) + " - ";
1171  } else if (ROWNO >= 0 && COLNO >= 0) {
1172  if (POSNO >= 0) {
1173  prefix += "Jacobian Pos " + std::to_string(POSNO) + " (Row " +
1174  std::to_string(ROWNO) + ", Col " + std::to_string(COLNO) + ") - ";
1175  } else if (POSNO == -1) {
1176  prefix += "Pair (Row " + std::to_string(ROWNO) + ", Col " +
1177  std::to_string(COLNO) + ") - ";
1178  }
1179  }
1180 
1181  casadi::uerr() << prefix << MSG << std::endl;
1182  return 0;
1183  }

References casadi::uerr().

Referenced by init_mem().

◆ cb_fd_eval()

int COI_CALLCONV casadi::ConoptInterface::cb_fd_eval ( const double  X[],
double *  G,
double  JAC[],
int  ROWNO,
const int  JACNUM[],
int  MODE,
int  IGNERR,
int *  ERRCNT,
int  NUMVAR,
int  NUMJAC,
int  THREAD,
void *  USRMEM 
)
static

Definition at line 905 of file conopt_interface.cpp.

908  {
909  auto m = static_cast<ConoptMemory*>(USRMEM);
910  const ConoptInterface& self = m->self;
911 
912  // Acquire load: establishes happens-before with the release store in cb_fdevalini,
913  // making all cache writes (including cached_jac_g and cache_valid_jac) visible here.
914  if (!m->cache_valid.load(std::memory_order_acquire)) {
915  *ERRCNT = 1;
916  return 0;
917  }
918 
919  if ((MODE == 2 || MODE == 3) &&
920  !m->cache_valid_jac.load(std::memory_order_relaxed)) {
921  *ERRCNT = 1;
922  return 0;
923  }
924 
925 #ifndef NDEBUG
926  casadi_assert(
927  std::memcmp(X, m->cached_x.data(), NUMVAR * sizeof(double)) == 0,
928  "cb_fd_eval: X does not match cached_x — CONOPT API contract violated");
929 #endif
930 
931  if (ROWNO == 0) {
932  if (MODE == 1 || MODE == 3) *G = m->cached_f;
933  if (MODE == 2 || MODE == 3) {
934  const casadi_int* f_row = self.gradf_sp_.row();
935  for (casadi_int k = 0; k < self.gradf_sp_.nnz(); ++k) {
936  if (self.gradf_nlflag_[k]) {
937  JAC[f_row[k]] = m->cached_grad_f[k];
938  if (self.debug_)
939  casadi::uout() << " df/dx[" << f_row[k] << "] = "
940  << m->cached_grad_f[k] << "\n";
941  }
942  }
943  }
944  } else {
945  casadi_assert(ROWNO >= 1 && ROWNO <= m->ng_expanded,
946  "cb_fd_eval: ROWNO out of range");
947  int ci = m->conopt_to_casadi[ROWNO - 1];
948  if (MODE == 1 || MODE == 3) {
949  *G = m->cached_g[ci];
950  if (self.debug_) {
951  ConoptRowType ctype = m->conopt_type[ROWNO - 1];
952  double rhs = m->conopt_rhs[ROWNO - 1];
953  const char* rel = (ctype == ConoptRowType::Equality) ? "=" :
954  (ctype == ConoptRowType::GreaterEqual) ? ">=" :
955  (ctype == ConoptRowType::LessEqual) ? "<=" : "free";
956  if (ctype == ConoptRowType::Free)
957  casadi::uout() << " g[" << ci << "](x) = " << *G << " (free)\n";
958  else
959  casadi::uout() << " g[" << ci << "](x) = " << *G << " "
960  << rel << " " << rhs << "\n";
961  }
962  }
963  if (MODE == 2 || MODE == 3) {
964  int base = self.jacg_rowstart_[ci];
965  int count = self.jacg_rowstart_[ci + 1] - self.jacg_rowstart_[ci];
966  for (int k = 0; k < count; ++k) {
967  int col = self.jacg_col_[base + k];
968  double val = m->cached_jac_g[self.jacg_nzidx_[base + k]];
969  JAC[col] = val;
970  if (self.debug_)
971  casadi::uout() << " dg[" << ci << "]/dx[" << col << "] = " << val << "\n";
972  }
973  }
974  }
975  return 0;
976  }

References debug_, casadi::Equality, casadi::Free, gradf_nlflag_, casadi::GreaterEqual, casadi::JAC, casadi::LessEqual, casadi::FunctionInternal::self(), casadi::uout(), and casadi::X.

Referenced by init_mem().

◆ cb_fdevalend()

int COI_CALLCONV casadi::ConoptInterface::cb_fdevalend ( int  IGNERR,
int *  ERRCNT,
void *  USRMEM 
)
static

Definition at line 978 of file conopt_interface.cpp.

978  {
979  auto m = static_cast<ConoptMemory*>(USRMEM);
980  m->cache_valid_jac.store(false, std::memory_order_relaxed);
981  m->cache_valid.store(false, std::memory_order_relaxed);
982  return 0;
983  }

References casadi::ConoptMemory::cache_valid_jac.

Referenced by init_mem().

◆ cb_fdevalini()

int COI_CALLCONV casadi::ConoptInterface::cb_fdevalini ( const double  X[],
const int  ROWLIST[],
int  MODE,
int  LISTSIZE,
int  NUMTHREAD,
int  IGNERR,
int *  ERRCNT,
int  NUMVAR,
void *  USRMEM 
)
static

Definition at line 853 of file conopt_interface.cpp.

856  {
857  auto m = static_cast<ConoptMemory*>(USRMEM);
858  const ConoptInterface& self = m->self;
859 
860  casadi_assert(NUMVAR == self.nx_, "cb_fdevalini: NUMVAR != nx_");
861  casadi_assert(static_cast<size_t>(NUMVAR) == m->cached_x.size(),
862  "cb_fdevalini: NUMVAR != cached_x size");
863 
864  std::memcpy(m->cached_x.data(), X, NUMVAR * sizeof(double));
865 
866  if (self.debug_) {
867  casadi::uout() << "FDEvalIni x:";
868  for (int i = 0; i < NUMVAR; ++i)
869  casadi::uout() << " " << X[i];
870  casadi::uout() << "\n";
871  }
872 
873  const bool need_jac = (MODE != 1);
874 
875  m->cache_valid_jac.store(false, std::memory_order_relaxed);
876  m->cache_valid.store(false, std::memory_order_relaxed);
877  try {
878  m->arg[0] = m->cached_x.data();
879  m->arg[1] = m->d_nlp.p;
880 
881  m->res[0] = &m->cached_f;
882  m->res[1] = need_jac ? m->cached_grad_f.data() : nullptr;
883  int ret = self.calc_function(m, "nlp_grad_f");
884  if (!ret) {
885  m->res[0] = m->cached_g.data();
886  m->res[1] = need_jac ? m->cached_jac_g.data() : nullptr;
887  ret = self.calc_function(m, "nlp_jac_g");
888  }
889  if (!ret) {
890  // Publish the cache only after both evaluations succeed.
891  m->cache_valid_jac.store(need_jac, std::memory_order_relaxed);
892  m->cache_valid.store(true, std::memory_order_release);
893  }
894  } catch (std::exception& ex) {
895  casadi::uerr() << ex.what() << std::endl;
896  } catch (...) {
897  }
898  if (!m->cache_valid.load(std::memory_order_relaxed)) {
899  *ERRCNT = 1;
900  m->nan_encountered = true;
901  }
902  return 0;
903  }

References debug_, casadi::Nlpsol::nx_, casadi::FunctionInternal::self(), casadi::uerr(), casadi::uout(), and casadi::X.

Referenced by init_mem().

◆ cb_message()

int COI_CALLCONV casadi::ConoptInterface::cb_message ( int  SMSG,
int  DMSG,
int  NMSG,
char *  MSGV[],
void *  USRMEM 
)
static

Definition at line 1147 of file conopt_interface.cpp.

1148  {
1149  auto m = static_cast<ConoptMemory*>(USRMEM);
1150 
1151  int message_length = SMSG;
1152  if (m->self.debug_) message_length = std::max(message_length, std::max(DMSG, NMSG));
1153 
1154  for (int i = 0; i < message_length; ++i) {
1155  if (MSGV[i] != nullptr) {
1156  casadi::uout() << MSGV[i] << std::endl;
1157  }
1158  }
1159  return 0;
1160  }

References casadi::uout().

Referenced by init_mem().

◆ cb_option()

int COI_CALLCONV casadi::ConoptInterface::cb_option ( int  NCALL,
double *  RVAL,
int *  IVAL,
int *  LVAL,
char *  NAME,
void *  USRMEM 
)
static

Definition at line 623 of file conopt_interface.cpp.

624  {
625  auto m = static_cast<ConoptMemory*>(USRMEM);
626 
627  if (NCALL >= static_cast<int>(m->custom_options.size())) {
628  NAME[0] = '\0';
629  return 0;
630  }
631 
632  auto& opt = m->custom_options[NCALL];
633  // NAME has a fixed-size buffer; init() validates the option-name length.
634  size_t name_len = std::min(opt.first.size(), conopt_max_option_name);
635  std::memcpy(NAME, opt.first.c_str(), name_len);
636  NAME[name_len] = '\0';
637 
638  if (opt.second.is_double()) {
639  *RVAL = opt.second.to_double();
640  if (m->self.debug_)
641  casadi::uout() << "CONOPT option: " << opt.first << " = " << *RVAL << std::endl;
642  } else if (opt.second.is_int()) {
643  *IVAL = opt.second.to_int();
644  if (m->self.debug_)
645  casadi::uout() << "CONOPT option: " << opt.first << " = " << *IVAL << std::endl;
646  } else if (opt.second.is_bool()) {
647  *LVAL = opt.second.to_bool() ? 1 : 0;
648  if (m->self.debug_) {
649  casadi::uout() << "CONOPT option: " << opt.first << " = "
650  << (opt.second.to_bool() ? "true" : "false") << std::endl;
651  }
652  } else if (opt.second.is_string()) {
653  // init_mem filters out all string options before they enter custom_options
654  // (with a casadi_warning directing the user to 'optfile'). Reaching this
655  // branch means custom_options was populated externally in a way that
656  // bypasses that filter, which is a programming error. Setting NAME[0]='\0'
657  // here would terminate the entire option enumeration, silently dropping
658  // all subsequent entries — so we assert rather than pretend to skip.
659  casadi_error("CONOPT option '" + opt.first + "' is a string type in cb_option. "
660  "String options cannot be passed via the CONOPT option callback "
661  "(COI_OPTION_t has no SVAL parameter). Use the 'optfile' option "
662  "instead. The init_mem filter should have removed this option "
663  "before it reached custom_options; reaching this branch is a "
664  "programming error.");
665  } else {
666  // Similarly, an option of unknown type must never reach this point.
667  casadi_error("CONOPT option '" + opt.first + "' has an unknown GenericType in "
668  "cb_option. Only double, int, and bool options are valid here. "
669  "Reaching this branch is a programming error.");
670  }
671 
672  return 0;
673  }
static const size_t conopt_max_option_name

References casadi::conopt_max_option_name, casadi::ConoptMemory::custom_options, and casadi::uout().

Referenced by init_mem().

◆ cb_progress()

int COI_CALLCONV casadi::ConoptInterface::cb_progress ( int  LEN_INT,
const int  INTX[],
int  LEN_RL,
const double  RL[],
const double  X[],
void *  USRMEM 
)
static

Definition at line 676 of file conopt_interface.cpp.

678  {
679  auto m = static_cast<ConoptMemory*>(USRMEM);
680  const ConoptInterface& self = m->self;
681 
682  if (!self.fcallback_.is_null()) {
683  int phase = (LEN_INT > 1) ? INTX[1] : -1;
684 
685  double obj_val = m->cached_f; // best available approximation for early phases
686  if (LEN_RL > 1 && phase >= 3) {
687  obj_val = RL[1]; // CONOPT-reported value once available
688  }
689 
690  std::fill_n(m->arg, self.fcallback_.n_in(), nullptr);
691  m->arg[NLPSOL_X] = X;
692  m->arg[NLPSOL_F] = &obj_val;
693 
694  std::fill_n(m->res, self.fcallback_.n_out(), nullptr);
695  double ret_double = 0;
696  m->res[0] = &ret_double;
697 
698  try {
699  self.fcallback_(m->arg, m->res, m->iw, m->w, 0);
700  if (ret_double != 0.0) return 1;
701  } catch (KeyboardInterruptException& ex) {
702  return 1;
703  } catch (std::exception& ex) {
704  casadi_warning(std::string("intermediate_callback: ") + ex.what());
705  if (!self.iteration_callback_ignore_errors_) return 1;
706  }
707  }
708  return 0;
709  }

References casadi::Nlpsol::fcallback_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Nlpsol::iteration_callback_ignore_errors_, casadi::NLPSOL_F, casadi::NLPSOL_X, casadi::FunctionInternal::self(), casadi::CasadiException::what(), and casadi::X.

Referenced by init_mem().

◆ cb_read_matrix()

int COI_CALLCONV casadi::ConoptInterface::cb_read_matrix ( double  LOWER[],
double  CURR[],
double  UPPER[],
int  VSTA[],
int  TYPEX[],
double  RHS[],
int  ESTA[],
int  COLSTA[],
int  ROWNO[],
double  VALUE[],
int  NLFLAG[],
int  NUMVAR,
int  NUMCON,
int  NUMNZ,
void *  USRMEM 
)
static

Definition at line 711 of file conopt_interface.cpp.

716  {
717  auto m = static_cast<ConoptMemory*>(USRMEM);
718  const ConoptInterface& self = m->self;
719 
720  // CONOPT is expected to echo back exactly what we told it via COIDEF_NumVar/
721  // COIDEF_NumCon in init_mem()/solve() — a mismatch means the interface's own
722  // bookkeeping (nx_, ng_expanded) is desynced from what CONOPT is using.
723  casadi_assert(NUMVAR == self.nx_, "cb_read_matrix: NUMVAR != nx_");
724  casadi_assert(NUMCON == m->ng_expanded + 1, "cb_read_matrix: NUMCON != ng_expanded + 1");
725 
726  // Variable bounds and initial point (clamped to [lb, ub])
727  for (int i = 0; i < NUMVAR; ++i) {
728  double lb = m->d_nlp.lbz[i];
729  double ub = m->d_nlp.ubz[i];
730  if (!std::isinf(lb)) LOWER[i] = lb;
731  if (!std::isinf(ub)) UPPER[i] = ub;
732  double x0 = m->d_nlp.z[i];
733  if (!std::isinf(ub)) x0 = std::min(x0, ub);
734  if (!std::isinf(lb)) x0 = std::max(x0, lb);
735  CURR[i] = x0;
736  }
737 
738  // Constraint types and RHS (row 0 = objective, rows 1..ng_expanded = constraints).
739  // conopt_type/conopt_rhs come from solve()'s range-constraint expansion —
740  // they depend on this call's numeric lbg/ubg, not just problem structure.
741  TYPEX[0] = static_cast<int>(ConoptRowType::Free);
742  RHS[0] = 0.0;
743  for (int r = 0; r < m->ng_expanded; ++r) {
744  TYPEX[r + 1] = static_cast<int>(m->conopt_type[r]);
745  RHS[r + 1] = m->conopt_rhs[r];
746  }
747 
748  if (self.warm_start_) {
749  // conopt_to_casadi/casadi_to_conopt_lb_row/ub_row (from solve()) map each
750  // expanded CONOPT row back to its CasADi constraint, to look up lam there.
751  ESTA[0] = static_cast<int>(ConoptBasisStatus::SuperBasic); // objective row always superbasic
752 
753  // lam is the prior solve's dual solution, length nx_+ng_. lam[0..nx_-1] are
754  // variable-bound multipliers, lam[nx_..] are constraint multipliers.
755  const double* lam = m->d_nlp.lam;
756  bool all_zero = std::all_of(lam, lam + self.nx_ + self.ng_,
757  [](double v) { return v == 0.0; });
758  if (!all_zero) {
759  for (int i = 0; i < NUMVAR; ++i) {
760  double lbi = m->d_nlp.lbz[i];
761  double ubi = m->d_nlp.ubz[i];
762  double xi = m->d_nlp.z[i];
763  double li = lam[i]; // nonzero multiplier => that bound is active, so nonbasic
764  if (!std::isinf(lbi) && std::fabs(xi - lbi) < 1e-8 && li <= 0.0)
765  VSTA[i] = static_cast<int>(ConoptBasisStatus::AtLower);
766  else if (!std::isinf(ubi) && std::fabs(xi - ubi) < 1e-8 && li >= 0.0)
767  VSTA[i] = static_cast<int>(ConoptBasisStatus::AtUpper);
768  else
769  VSTA[i] = static_cast<int>(ConoptBasisStatus::Basic);
770  }
771 
772  for (int r = 0; r < m->ng_expanded; ++r) {
773  int ci = m->conopt_to_casadi[r];
774  // this constraint's multiplier, same sign logic as above
775  double lam_ci = lam[NUMVAR + ci];
776  int row1 = m->casadi_to_conopt_lb_row[ci];
777  int row2 = m->casadi_to_conopt_ub_row[ci];
778  if (r + 1 == row1) {
779  ConoptRowType ctype = m->conopt_type[r]; // type of this CONOPT expanded row
780  if (ctype == ConoptRowType::Equality) { // equality: both sides, just mark basic
781  ESTA[r + 1] = static_cast<int>(ConoptBasisStatus::Basic);
782  } else if (ctype == ConoptRowType::GreaterEqual) { // >= row: active when lam_ci < 0
783  ESTA[r + 1] = static_cast<int>(
785  } else if (ctype == ConoptRowType::LessEqual) {
786  // <= row (pure <= stored as lb_row): active when lam_ci > 0
787  ESTA[r + 1] = static_cast<int>(
789  } else { // free row: superbasic
790  ESTA[r + 1] = static_cast<int>(ConoptBasisStatus::SuperBasic);
791  }
792  } else if (r + 1 == row2) {
793  // range ub side is active when lam_ci > 0
794  ESTA[r + 1] = static_cast<int>(
796  } else {
797  ESTA[r + 1] = static_cast<int>(ConoptBasisStatus::Basic);
798  }
799  }
800  }
801  }
802 
803  // Jacobian structure — built live from jacg_sp_ with range-row duplication.
804  // Column/sparsity/linearity data (jacg_sp_, gradf_col_flag_, gradf_col_to_nz_,
805  // gradf_nlflag_, jacg_nlflag_) is structural, fixed since init(). Row mapping
806  // (casadi_to_conopt_lb_row/ub_row) and numeric values (gradf_const_vals,
807  // const_jac_vals) are this solve()'s numeric data.
808  const casadi_int* g_colind = self.jacg_sp_.colind();
809  const casadi_int* g_row = self.jacg_sp_.row();
810  int nz = 0;
811  for (int c = 0; c < NUMVAR; ++c) {
812  COLSTA[c] = nz;
813  if (self.gradf_col_flag_[c]) {
814  // Objective-gradient entry in column c, if any (row 0 = objective).
815  casadi_int k = self.gradf_col_to_nz_[c];
816  if (self.gradf_nlflag_[k] == 1) {
817  ROWNO[nz] = 0;
818  NLFLAG[nz] = 1;
819  nz++;
820  } else if (m->gradf_const_vals[k] != 0.0) {
821  ROWNO[nz] = 0;
822  NLFLAG[nz] = 0;
823  VALUE[nz] = m->gradf_const_vals[k];
824  nz++;
825  }
826  }
827  // Constraint-Jacobian entries in column c; duplicated onto the ub row too
828  // when this CasADi row was split into a range constraint by solve().
829  for (casadi_int el = g_colind[c]; el < g_colind[c+1]; ++el) {
830  int ci = static_cast<int>(g_row[el]);
831  int nlflag = self.jacg_nlflag_[el];
832  ROWNO[nz] = m->casadi_to_conopt_lb_row[ci];
833  NLFLAG[nz] = nlflag;
834  if (nlflag == 0) VALUE[nz] = m->const_jac_vals[el];
835  nz++;
836  if (m->casadi_to_conopt_ub_row[ci] >= 0) {
837  ROWNO[nz] = m->casadi_to_conopt_ub_row[ci];
838  NLFLAG[nz] = nlflag;
839  if (nlflag == 0) VALUE[nz] = m->const_jac_vals[el];
840  nz++;
841  }
842  }
843  }
844  COLSTA[NUMVAR] = nz;
845 
846  casadi_assert(nz == NUMNZ,
847  "cb_read_matrix: nz != NUMNZ - Jacobian nonzero count mismatch "
848  "between solve()'s numnz computation and this callback's writes");
849 
850  return 0;
851  }

References casadi::AtLower, casadi::AtUpper, casadi::Basic, casadi::Equality, casadi::Free, gradf_col_flag_, gradf_nlflag_, casadi::GreaterEqual, casadi::LessEqual, casadi::Nlpsol::ng_, casadi::Nlpsol::nx_, casadi::FunctionInternal::self(), casadi::SuperBasic, casadi::VALUE, and warm_start_.

Referenced by init_mem().

◆ cb_solution()

int COI_CALLCONV casadi::ConoptInterface::cb_solution ( const double  XVAL[],
const double  XMAR[],
const int  XBAS[],
const int  XSTA[],
const double  YVAL[],
const double  YMAR[],
const int  YBAS[],
const int  YSTA[],
int  NUMVAR,
int  NUMCON,
void *  USRMEM 
)
static

Definition at line 1111 of file conopt_interface.cpp.

1115  {
1116  auto m = static_cast<ConoptMemory*>(USRMEM);
1117 
1118  casadi_copy(XVAL, NUMVAR, m->d_nlp.z);
1119 
1120  if (m->self.debug_) {
1121  casadi::uout() << "Solution x:";
1122  for (int i = 0; i < NUMVAR; ++i)
1123  casadi::uout() << " " << XVAL[i];
1124  casadi::uout() << "\n";
1125  }
1126 
1127  // Use the first row of each constraint and restore constants absorbed into the RHS.
1128  for (casadi_int ci = 0; ci < m->self.ng_; ++ci)
1129  m->d_nlp.z[NUMVAR + ci] = YVAL[m->casadi_to_conopt_lb_row[ci]] + m->row_const_[ci];
1130 
1131  // Variable marginals: CONOPT shadow prices = -CasADi lam_x
1132  for (int i = 0; i < NUMVAR; ++i)
1133  m->d_nlp.lam[i] = -XMAR[i];
1134 
1135  // Constraint marginals: for range constraints sum both rows' shadow prices
1136  // (only the active bound has a non-zero YMAR; summing is always safe)
1137  for (casadi_int ci = 0; ci < m->self.ng_; ++ci) {
1138  int row1 = m->casadi_to_conopt_lb_row[ci];
1139  int row2 = m->casadi_to_conopt_ub_row[ci];
1140  double ymar = YMAR[row1] + (row2 >= 0 ? YMAR[row2] : 0.0);
1141  m->d_nlp.lam[NUMVAR + ci] = -ymar;
1142  }
1143 
1144  return 0;
1145  }
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.

References casadi::casadi_copy(), and casadi::uout().

Referenced by init_mem().

◆ cb_status()

int COI_CALLCONV casadi::ConoptInterface::cb_status ( int  MODSTA,
int  SOLSTA,
int  ITER,
double  OBJVAL,
void *  USRMEM 
)
static

Definition at line 1057 of file conopt_interface.cpp.

1058  {
1059  auto m = static_cast<ConoptMemory*>(USRMEM);
1060  m->modsta = static_cast<ConoptModelStatus>(MODSTA);
1061  m->solsta = static_cast<ConoptSolverStatus>(SOLSTA);
1062  m->iter = ITER;
1063  m->d_nlp.objective = OBJVAL;
1064 
1065  const char* modsta_str;
1066  switch (m->modsta) {
1067  case ConoptModelStatus::Optimal: modsta_str = "Optimal"; break;
1068  case ConoptModelStatus::LocallyOptimal: modsta_str = "Locally optimal"; break;
1069  case ConoptModelStatus::Unbounded: modsta_str = "Unbounded"; break;
1070  case ConoptModelStatus::Infeasible: modsta_str = "Infeasible"; break;
1071  case ConoptModelStatus::LocallyInfeasible: modsta_str = "Locally infeasible"; break;
1072  case ConoptModelStatus::IntermediateInfeas: modsta_str = "Intermediate infeasible"; break;
1073  case ConoptModelStatus::IntermediateNonOpt: modsta_str = "Intermediate non-optimal"; break;
1074  case ConoptModelStatus::UnknownError: modsta_str = "Unknown error"; break;
1075  case ConoptModelStatus::ErrorNoSolution: modsta_str = "Error: no solution"; break;
1076  default: modsta_str = "Unknown model status"; break;
1077  }
1078 
1079  const char* solsta_str;
1080  switch (m->solsta) {
1082  solsta_str = "Normal completion"; break;
1084  solsta_str = "Iteration limit"; break;
1086  solsta_str = "Time limit"; break;
1088  solsta_str = "Terminated by solver"; break;
1090  solsta_str = "Evaluation error limit"; break;
1092  solsta_str = "User interrupt"; break;
1094  solsta_str = "Setup failure"; break;
1096  solsta_str = "Major solver error"; break;
1098  solsta_str = "Major solver error (feasible point)"; break;
1100  solsta_str = "System error"; break;
1102  solsta_str = "Quick Mode termination"; break;
1103  default:
1104  solsta_str = "Unknown solver status"; break;
1105  }
1106 
1107  m->return_status = std::string(modsta_str) + " / " + std::string(solsta_str);
1108  return 0;
1109  }

References casadi::ErrorNoSolution, casadi::EvalErrorLimit, casadi::Infeasible, casadi::IntermediateInfeas, casadi::IntermediateNonOpt, casadi::IterationLimit, casadi::LocallyInfeasible, casadi::LocallyOptimal, casadi::MajorSolverError, casadi::MajorSolverErrorFeas, casadi::ConoptMemory::modsta, casadi::NormalCompletion, casadi::Optimal, casadi::QuickModeTermination, casadi::SetupFailure, casadi::SystemError, casadi::TerminatedBySolver, casadi::TimeLimit, casadi::Unbounded, casadi::UnknownError, and casadi::UserInterrupt.

Referenced by init_mem().

◆ change_option()

void casadi::FunctionInternal::change_option ( const std::string &  option_name,
const GenericType option_value 
)
overridevirtualinherited

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

Reimplemented from casadi::ProtoFunction.

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

Definition at line 443 of file function_internal.cpp.

444  {
445  if (option_name == "print_in") {
446  print_in_ = option_value;
447  } else if (option_name == "print_out") {
448  print_out_ = option_value;
449  } else if (option_name == "print_canonical") {
450  print_canonical_ = option_value;
451  } else if (option_name=="ad_weight") {
452  ad_weight_ = option_value;
453  } else if (option_name=="ad_weight_sp") {
454  ad_weight_sp_ = option_value;
455  } else if (option_name=="dump") {
456  dump_ = option_value;
457  } else if (option_name=="dump_in") {
458  dump_in_ = option_value;
459  } else if (option_name=="dump_out") {
460  dump_out_ = option_value;
461  } else if (option_name=="dump_dir") {
462  dump_dir_ = option_value.to_string();
463  } else if (option_name=="dump_format") {
464  dump_format_ = option_value.to_string();
465  } else {
466  // Option not found - continue to base classes
467  ProtoFunction::change_option(option_name, option_value);
468  }
469  }
virtual void change_option(const std::string &option_name, const GenericType &option_value)
Change option after object creation for debugging.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::ad_weight_sp_, casadi::ProtoFunction::change_option(), casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_dir_, casadi::FunctionInternal::dump_format_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::print_canonical_, casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, and casadi::GenericType::to_string().

Referenced by casadi::FmuFunction::change_option(), casadi::MXFunction::change_option(), and casadi::SXFunction::change_option().

◆ 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::vector< std::string > name_in_
Input and output scheme.
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_inputs()

void casadi::Nlpsol::check_inputs ( void *  mem) const
virtualinherited

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

Definition at line 702 of file nlpsol.cpp.

702  {
703  auto *m = static_cast<NlpsolMemory*>(mem);
704  auto *d_nlp = &m->d_nlp;
705 
706  // Skip check?
707  if (!inputs_check_) return;
708 
709  const double inf = std::numeric_limits<double>::infinity();
710 
711  // Number of equality constraints
712  casadi_int n_eq = 0;
713 
714  // Detect ill-posed problems (simple bounds)
715  for (casadi_int i=0; i<nx_; ++i) {
716  double lb = d_nlp->lbx ? d_nlp->lbx[i] : get_default_in(NLPSOL_LBX);
717  double ub = d_nlp->ubx ? d_nlp->ubx[i] : get_default_in(NLPSOL_UBX);
718  double x0 = d_nlp->x0 ? d_nlp->x0[i] : get_default_in(NLPSOL_X0);
719  casadi_assert(lb <= ub && lb!=inf && ub!=-inf,
720  "Ill-posed problem detected: "
721  "LBX[" + str(i) + "] <= UBX[" + str(i) + "] was violated. "
722  "Got LBX[" + str(i) + "]=" + str(lb) + " and UBX[" + str(i) + "] = " + str(ub) + ".");
723  if (warn_initial_bounds_ && (x0>ub || x0<lb)) {
724  casadi_warning("Nlpsol: The initial guess does not satisfy LBX and UBX. "
725  "Option 'warn_initial_bounds' controls this warning.");
726  break;
727  }
728  if (lb==ub) n_eq++;
729  }
730 
731  // Detect ill-posed problems (nonlinear bounds)
732  for (casadi_int i=0; i<nnz_out(NLPSOL_G); ++i) {
733  double lb = d_nlp->lbg ? d_nlp->lbg[i] : get_default_in(NLPSOL_LBG);
734  double ub = d_nlp->ubg ? d_nlp->ubg[i] : get_default_in(NLPSOL_UBG);
735  casadi_assert(lb <= ub && lb!=inf && ub!=-inf,
736  "Ill-posed problem detected: "
737  "LBG[" + str(i) + "] <= UBG[" + str(i) + "] was violated. "
738  "Got LBG[" + str(i) + "] = " + str(lb) + " and UBG[" + str(i) + "] = " + str(ub) + ".");
739  if (lb==ub) n_eq++;
740  }
741 
742  // Make sure enough degrees of freedom
743  using casadi::str; // Workaround, MingGW bug, cf. CasADi issue #890
744  if (n_eq> nx_) {
745  casadi_warning("NLP is overconstrained: There are " + str(n_eq) +
746  " equality constraints but only " + str(nx_) + " variables.");
747  }
748  }
bool inputs_check_
Errors are thrown if numerical values of inputs look bad.
bool warn_initial_bounds_
Options.
Definition: nlpsol_impl.hpp:94
double get_default_in(casadi_int ind) const override
Get default input value.
@ NLPSOL_UBX
Decision variables upper bound (nx x 1), default +inf.
Definition: nlpsol.hpp:202
@ NLPSOL_X0
Decision variables, initial guess (nx x 1)
Definition: nlpsol.hpp:196
@ NLPSOL_UBG
Constraints upper bound (ng x 1), default +inf.
Definition: nlpsol.hpp:206
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
Definition: nlpsol.hpp:204
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
Definition: nlpsol.hpp:200
const double inf
infinity
Definition: calculus.hpp:50

References casadi::NlpsolMemory::d_nlp, casadi::Nlpsol::get_default_in(), casadi::inf, casadi::FunctionInternal::inputs_check_, casadi::NLPSOL_G, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X0, casadi::FunctionInternal::nnz_out(), casadi::Nlpsol::nx_, casadi::str(), and casadi::Nlpsol::warn_initial_bounds_.

Referenced by casadi::Nlpsol::eval(), casadi::AlpaqaInterface::set_work(), and casadi::SLEQPInterface::set_work().

◆ 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()

virtual void casadi::ProtoFunction::check_mem_count ( casadi_int  n) const
inlinevirtualinherited

Purpose if to allow more helpful error messages

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

Reimplemented in casadi::FmuFunction.

Definition at line 181 of file function_internal.hpp.

181 { }

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

◆ 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  }
std::vector< std::string > name_out_

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::ConoptInterface::class_name ( ) const
inlineoverridevirtual

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

Reimplemented from casadi::Nlpsol.

Definition at line 145 of file conopt_interface.hpp.

145 { return "ConoptInterface"; }

◆ 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(), ~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(), casadi::FmuFunction::~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_body_enter()

void casadi::Nlpsol::codegen_body_enter ( CodeGenerator g) const
overridevirtualinherited

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

Reimplemented from casadi::OracleFunction.

Definition at line 1268 of file nlpsol.cpp.

1268  {
1270  g.local("d_nlp", "struct casadi_nlpsol_data");
1271  g.local("p_nlp", "struct casadi_nlpsol_prob");
1272  codegen_setup_constants(g, "d_nlp", "p_nlp", "d_oracle");
1273  codegen_setup_per_call(g, "d_nlp");
1274  }
void codegen_setup_per_call(CodeGenerator &g, const std::string &d_nlp) const
Definition: nlpsol.cpp:1313
void codegen_setup_constants(CodeGenerator &g, const std::string &d_nlp, const std::string &p_nlp, const std::string &d_oracle) const
Definition: nlpsol.cpp:1281
virtual void codegen_body_enter(CodeGenerator &g) const
Generate code for the function body.

References casadi::OracleFunction::codegen_body_enter(), casadi::Nlpsol::codegen_setup_constants(), casadi::Nlpsol::codegen_setup_per_call(), and casadi::CodeGenerator::local().

Referenced by casadi::MadmpecInterface::codegen_body(), casadi::FatropInterface::codegen_body(), casadi::IpoptInterface::codegen_body(), casadi::MadnlpInterface::codegen_body(), casadi::Feasiblesqpmethod::codegen_body(), and casadi::Sqpmethod::codegen_body().

◆ codegen_body_exit()

void casadi::Nlpsol::codegen_body_exit ( CodeGenerator g) const
overridevirtualinherited

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

Reimplemented from casadi::OracleFunction.

Definition at line 1368 of file nlpsol.cpp.

1368  {
1369  codegen_post_solve(g, "d_nlp");
1371  }
void codegen_post_solve(CodeGenerator &g, const std::string &d_nlp) const
Definition: nlpsol.cpp:1373
virtual void codegen_body_exit(CodeGenerator &g) const
Generate code for the function body.

References casadi::OracleFunction::codegen_body_exit(), and casadi::Nlpsol::codegen_post_solve().

Referenced by casadi::MadmpecInterface::codegen_body(), casadi::FatropInterface::codegen_body(), casadi::IpoptInterface::codegen_body(), casadi::MadnlpInterface::codegen_body(), and casadi::Sqpmethod::codegen_body().

◆ 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::Nlpsol::codegen_declarations ( CodeGenerator g) const
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Reimplemented in casadi::Sqpmethod, casadi::Feasiblesqpmethod, casadi::UnoInterface, casadi::MadnlpInterface, casadi::IpoptInterface, casadi::FatropInterface, and casadi::MadmpecInterface.

Definition at line 1348 of file nlpsol.cpp.

1348  {
1349  g.add_auxiliary(CodeGenerator::AUX_FILL);
1350  g.add_auxiliary(CodeGenerator::AUX_INF);
1351  if (calc_f_ || calc_g_ || calc_lam_x_ || calc_lam_p_)
1352  g.add_dependency(get_function("nlp_grad"));
1353 
1354  if (detect_simple_bounds_is_simple_.size()) {
1355  g.add_dependency(detect_simple_bounds_parts_);
1356  std::string w =
1357  g.shorthand(g.wrapper(detect_simple_bounds_parts_, "detect_simple_bounds_wrapper"));
1358 
1359  g << "int " << w
1360  << "(const casadi_real** arg, casadi_real** res, "
1361  << "casadi_int* iw, casadi_real* w, void* callback_data) {\n";
1362  std::string flag = g(detect_simple_bounds_parts_, "arg", "res", "iw", "w");
1363  g << "return " + flag + ";\n";
1364  g << "}\n";
1365  }
1366  }
bool calc_lam_p_
Options.
Definition: nlpsol_impl.hpp:97
Function detect_simple_bounds_parts_
Definition: nlpsol_impl.hpp:85
bool calc_f_
Options.
Definition: nlpsol_impl.hpp:97
bool calc_g_
Options.
Definition: nlpsol_impl.hpp:97
std::vector< char > detect_simple_bounds_is_simple_
Definition: nlpsol_impl.hpp:84
bool calc_lam_x_
Options.
Definition: nlpsol_impl.hpp:97

References casadi::CodeGenerator::add_auxiliary(), casadi::CodeGenerator::add_dependency(), casadi::CodeGenerator::AUX_FILL, casadi::CodeGenerator::AUX_INF, casadi::Nlpsol::calc_f_, casadi::Nlpsol::calc_g_, casadi::Nlpsol::calc_lam_p_, casadi::Nlpsol::calc_lam_x_, casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Nlpsol::detect_simple_bounds_parts_, casadi::OracleFunction::get_function(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::wrapper().

Referenced by casadi::MadmpecInterface::codegen_declarations(), casadi::FatropInterface::codegen_declarations(), casadi::IpoptInterface::codegen_declarations(), casadi::MadnlpInterface::codegen_declarations(), casadi::UnoInterface::codegen_declarations(), casadi::Feasiblesqpmethod::codegen_declarations(), and casadi::Sqpmethod::codegen_declarations().

◆ 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_post_solve()

void casadi::Nlpsol::codegen_post_solve ( CodeGenerator g,
const std::string &  d_nlp 
) const
inherited

Definition at line 1373 of file nlpsol.cpp.

1373  {
1374  if (calc_f_ || calc_g_ || calc_lam_x_ || calc_lam_p_) {
1375  g.local("one", "const casadi_real");
1376  g.init_local("one", "1");
1377  g << "d->arg[0] = " << d_nlp << ".z;\n";
1378  g << "d->arg[1] = " << d_nlp << ".p;\n";
1379  g << "d->arg[2] = &one;\n";
1380  g << "d->arg[3] = " << d_nlp << ".lam+" << str(nx_) << ";\n";
1381  g << "d->res[0] = " << (calc_f_ ? "&" + d_nlp + ".objective" : "0") << ";\n";
1382  g << "d->res[1] = " << (calc_g_ ? d_nlp + ".z+" + str(nx_) : "0") << ";\n";
1383  g << "d->res[2] = " << (calc_lam_x_ ? d_nlp + ".lam+" + str(nx_) : "0") << ";\n";
1384  g << "d->res[3] = " << (calc_lam_p_ ? d_nlp + ".lam_p" : "0") << ";\n";
1385  std::string nlp_grad = g(get_function("nlp_grad"), "d->arg", "d->res", "d->iw", "d->w");
1386  g << "if (" << nlp_grad << ") return 1;\n";
1387  if (calc_lam_x_) g << g.scal(nx_, "-1.0", d_nlp + ".lam") << "\n";
1388  if (calc_lam_p_) g << g.scal(np_, "-1.0", d_nlp + ".lam_p") << "\n";
1389  }
1390  if (bound_consistency_) {
1391  g << g.bound_consistency(nx_+ng_, d_nlp + ".z", d_nlp + ".lam",
1392  d_nlp + ".lbz", d_nlp + ".ubz") << ";\n";
1393  }
1394 
1395  g << g.copy(d_nlp + ".z", nx_, d_nlp + ".x") << "\n";
1396 
1397  if (detect_simple_bounds_is_simple_.empty()) {
1398  g << g.copy(d_nlp + ".z + " + str(nx_), ng_, d_nlp + ".g") << "\n";
1399  g << g.copy(d_nlp + ".lam", nx_, d_nlp + ".lam_x") << "\n";
1400  g << g.copy(d_nlp + ".lam + " + str(nx_), ng_, d_nlp + ".lam_g") << "\n";
1401  } else {
1402  g << "if (casadi_nlpsol_detect_bounds_after(&" << d_nlp << ")) return 1;\n";
1403  }
1404 
1405  g.copy_check("&" + d_nlp + ".objective", 1, d_nlp + ".f", false, true);
1406  g.copy_check(d_nlp + ".lam_p", np_, d_nlp + ".lam_p", false, true);
1407  }
casadi_int np_
Number of parameters.
Definition: nlpsol_impl.hpp:72
bool bound_consistency_
Options.
Definition: nlpsol_impl.hpp:98

References casadi::CodeGenerator::bound_consistency(), casadi::Nlpsol::bound_consistency_, casadi::Nlpsol::calc_f_, casadi::Nlpsol::calc_g_, casadi::Nlpsol::calc_lam_p_, casadi::Nlpsol::calc_lam_x_, casadi::CodeGenerator::copy(), casadi::CodeGenerator::copy_check(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::OracleFunction::get_function(), casadi::CodeGenerator::init_local(), casadi::CodeGenerator::local(), casadi::Nlpsol::ng_, casadi::Nlpsol::np_, casadi::Nlpsol::nx_, casadi::CodeGenerator::scal(), and casadi::str().

Referenced by casadi::UnoInterface::codegen_body(), and casadi::Nlpsol::codegen_body_exit().

◆ 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_setup_constants()

void casadi::Nlpsol::codegen_setup_constants ( CodeGenerator g,
const std::string &  d_nlp,
const std::string &  p_nlp,
const std::string &  d_oracle 
) const
inherited

Definition at line 1281 of file nlpsol.cpp.

1283  {
1284  g << d_nlp << ".oracle = &" << d_oracle << ";\n";
1285  g << d_nlp << ".prob = &" << p_nlp << ";\n";
1286  g << p_nlp << ".nx = " << nx_ << ";\n";
1287  g << p_nlp << ".ng = " << ng_ << ";\n";
1288  g << p_nlp << ".np = " << np_ << ";\n";
1289  g << p_nlp << ".detect_bounds.ng = " << detect_simple_bounds_is_simple_.size() << ";\n";
1290  if (detect_simple_bounds_is_simple_.size()) {
1291  g << p_nlp << ".detect_bounds.sz_arg = " << detect_simple_bounds_parts_.sz_arg() << ";\n";
1292  g << p_nlp << ".detect_bounds.sz_res = " << detect_simple_bounds_parts_.sz_res() << ";\n";
1293  g << p_nlp << ".detect_bounds.sz_iw = " << detect_simple_bounds_parts_.sz_iw() << ";\n";
1294  g << p_nlp << ".detect_bounds.sz_w = " << detect_simple_bounds_parts_.sz_w() << ";\n";
1295 
1296  g << p_nlp << ".detect_bounds.nb = " << detect_simple_bounds_target_x_.size() << ";\n";
1297  g << p_nlp << ".detect_bounds.target_x = "
1298  << g.constant(detect_simple_bounds_target_x_) << ";\n";
1299  g << p_nlp << ".detect_bounds.target_g = "
1300  << g.constant(detect_simple_bounds_target_g_) << ";\n";
1301  g << p_nlp << ".detect_bounds.is_simple = "
1302  << g.constant(detect_simple_bounds_is_simple_) << ";\n";
1303  std::string w =
1304  g.shorthand(g.wrapper(detect_simple_bounds_parts_, "detect_simple_bounds_wrapper"));
1305  g << p_nlp << ".detect_bounds.callback = " << w << ";\n";
1306  g << p_nlp << ".detect_bounds.callback_data = 0;\n";
1307  }
1308  }
size_t sz_res() const
Get required length of res field.
Definition: function.cpp:1237
size_t sz_iw() const
Get required length of iw field.
Definition: function.cpp:1239
size_t sz_w() const
Get required length of w field.
Definition: function.cpp:1241
size_t sz_arg() const
Get required length of arg field.
Definition: function.cpp:1235
std::vector< casadi_int > detect_simple_bounds_target_g_
Definition: nlpsol_impl.hpp:87
std::vector< casadi_int > detect_simple_bounds_target_x_
Definition: nlpsol_impl.hpp:86

References casadi::CodeGenerator::constant(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Nlpsol::detect_simple_bounds_parts_, casadi::Nlpsol::detect_simple_bounds_target_g_, casadi::Nlpsol::detect_simple_bounds_target_x_, casadi::Nlpsol::ng_, casadi::Nlpsol::np_, casadi::Nlpsol::nx_, casadi::CodeGenerator::shorthand(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), casadi::Function::sz_w(), and casadi::CodeGenerator::wrapper().

Referenced by casadi::Nlpsol::codegen_body_enter(), and casadi::UnoInterface::codegen_init_mem().

◆ codegen_setup_per_call()

void casadi::Nlpsol::codegen_setup_per_call ( CodeGenerator g,
const std::string &  d_nlp 
) const
inherited

Definition at line 1313 of file nlpsol.cpp.

1313  {
1314  g << d_nlp << ".p = arg[" << NLPSOL_P << "];\n";
1315  g << d_nlp << ".lbx = arg[" << NLPSOL_LBX << "];\n";
1316  g << d_nlp << ".ubx = arg[" << NLPSOL_UBX << "];\n";
1317  g << d_nlp << ".lbg = arg[" << NLPSOL_LBG << "];\n";
1318  g << d_nlp << ".ubg = arg[" << NLPSOL_UBG << "];\n";
1319  g << d_nlp << ".x0 = arg[" << NLPSOL_X0 << "];\n";
1320  g << d_nlp << ".lam_x0 = arg[" << NLPSOL_LAM_X0 << "];\n";
1321  g << d_nlp << ".lam_g0 = arg[" << NLPSOL_LAM_G0 << "];\n";
1322  g << "arg += " << NLPSOL_NUM_IN << ";\n";
1323 
1324  g << d_nlp << ".x = res[" << NLPSOL_X << "];\n";
1325  g << d_nlp << ".f = res[" << NLPSOL_F << "];\n";
1326  g << d_nlp << ".g = res[" << NLPSOL_G << "];\n";
1327  g << d_nlp << ".lam_x = res[" << NLPSOL_LAM_X << "];\n";
1328  g << d_nlp << ".lam_g = res[" << NLPSOL_LAM_G << "];\n";
1329  g << d_nlp << ".lam_p = res[" << NLPSOL_LAM_P << "];\n";
1330  g << "res += " << NLPSOL_NUM_OUT << ";\n";
1331 
1332  g << "casadi_nlpsol_set_work(&" << d_nlp << ", &arg, &res, &iw, &w);\n";
1333 
1334  g.copy_default(d_nlp + ".x0", nx_, d_nlp + ".z", "0", false);
1335  g.copy_default(d_nlp + ".lbx", nx_, d_nlp + ".lbz", "-casadi_inf", false);
1336  g.copy_default(d_nlp + ".ubx", nx_, d_nlp + ".ubz", "casadi_inf", false);
1337  g.copy_default(d_nlp + ".lam_x0", nx_, d_nlp + ".lam", "0", false);
1338 
1339  if (detect_simple_bounds_is_simple_.empty()) {
1340  g.copy_default(d_nlp + ".lbg", ng_, d_nlp + ".lbz+" + str(nx_), "-casadi_inf", false);
1341  g.copy_default(d_nlp + ".ubg", ng_, d_nlp + ".ubz+" + str(nx_), "casadi_inf", false);
1342  g.copy_default(d_nlp + ".lam_g0", ng_, d_nlp + ".lam+" + str(nx_), "0", false);
1343  } else {
1344  g << "if (casadi_nlpsol_detect_bounds_before(&" << d_nlp << ")) return 1;\n";
1345  }
1346  }
@ NLPSOL_P
Value of fixed parameters (np x 1)
Definition: nlpsol.hpp:198
@ NLPSOL_LAM_G0
Lagrange multipliers for bounds on G, initial guess (ng x 1)
Definition: nlpsol.hpp:210
@ NLPSOL_LAM_X0
Lagrange multipliers for bounds on X, initial guess (nx x 1)
Definition: nlpsol.hpp:208
@ NLPSOL_NUM_IN
Definition: nlpsol.hpp:211
@ NLPSOL_NUM_OUT
Definition: nlpsol.hpp:228
@ NLPSOL_LAM_P
Lagrange multipliers for bounds on P at the solution (np x 1)
Definition: nlpsol.hpp:227

References casadi::CodeGenerator::copy_default(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::Nlpsol::nx_, and casadi::str().

Referenced by casadi::UnoInterface::codegen_body(), and casadi::Nlpsol::codegen_body_enter().

◆ 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(), casadi::FmuFunction::factory(), casadi::FmuFunction::get_forward(), casadi::FmuFunction::get_jacobian(), casadi::LinearInterpolant::get_jacobian(), and casadi::FmuFunction::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().

◆ create_forward()

Function casadi::OracleFunction::create_forward ( const std::string &  fname,
casadi_int  nfwd 
)
inherited

Create an oracle function as a forward derivative of a different function

Definition at line 278 of file oracle_function.cpp.

278  {
279  // Create derivative
280  Function ret = get_function(fname).forward(nfwd);
281  std::string fwd_name = forward_name(fname, nfwd); // may be different from ret.name()
282  if (!has_function(fwd_name)) set_function(ret, fwd_name, true);
283  return ret;
284 }
static std::string forward_name(const std::string &fcn, casadi_int nfwd)
Helper function: Get name of forward derivative function.
void set_function(const Function &fcn, const std::string &fname, bool jit=false)
bool has_function(const std::string &fname) const override

References casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::OracleFunction::has_function(), and casadi::OracleFunction::set_function().

Referenced by casadi::Integrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), casadi::UnoInterface::init(), and casadi::RungeKutta::setup_step().

◆ create_function() [1/3]

Function casadi::OracleFunction::create_function ( const Function oracle,
const std::string &  fname,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux = Function::AuxOut(),
const Dict opts = Dict() 
)
inherited

Create an oracle function, using a different oracle function Temporary addition to allow transition from one oracle formulation to another.

Definition at line 235 of file oracle_function.cpp.

239  {
240  // Print progress
241  if (verbose_) {
242  casadi_message(name_ + "::create_function " + fname + ":" + str(s_in) + "->" + str(s_out));
243  }
244 
245  // Check if function is already in cache
246  Function ret;
247  if (incache(fname, ret)) {
248  // Consistency checks
249  casadi_assert(ret.n_in() == s_in.size(), fname + " has wrong number of inputs");
250  casadi_assert(ret.n_out() == s_out.size(), fname + " has wrong number of outputs");
251  } else {
252  // Retrieve specific set of options if available
253  Dict specific_options;
254  auto it = specific_options_.find(fname);
255  if (it!=specific_options_.end()) specific_options = it->second;
256 
257  // Combine specific and common options
258  Dict opt = combine(specific_options, common_options_);
259  opt = combine(opts, opt);
260 
261  // Generate the function
262  ret = oracle.factory(fname, s_in, s_out, aux, opt);
263 
264  // Make sure that it's sound
265  if (ret.has_free()) {
266  casadi_error("Cannot create '" + fname + "' since " + str(ret.get_free()) + " are free.");
267  }
268 
269  // Add to cache
270  tocache_if_missing(ret);
271  }
272 
273  // Save and return
274  set_function(ret, fname, true);
275  return ret;
276 }
void tocache_if_missing(Function &f, const std::string &suffix="") const
Save function to cache, only if missing.
bool incache(const std::string &fname, Function &f, const std::string &suffix="") const
Get function in cache.
Function factory(const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const AuxOut &aux=AuxOut(), const Dict &opts=Dict()) const
Definition: function.cpp:2009
Dict common_options_
Options for creating functions.
const Function & oracle() const override
Get oracle.
bool verbose_
Verbose printout.
Dict combine(const Dict &first, const Dict &second, bool recurse)
Combine two dicts. First has priority.

References casadi::combine(), casadi::OracleFunction::common_options_, casadi::Function::factory(), casadi::Function::get_free(), casadi::Function::has_free(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::OracleFunction::oracle(), casadi::OracleFunction::set_function(), casadi::OracleFunction::specific_options_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::OracleFunction::create_function(), casadi::Integrator::init(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::SundialsInterface::init(), casadi::UnoInterface::init(), casadi::WorhpInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Qrsqp::init(), and casadi::Sqpmethod::init().

◆ create_function() [2/3]

Function casadi::OracleFunction::create_function ( const std::string &  fname,
const std::vector< MX > &  e_in,
const std::vector< MX > &  e_out,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Dict opts = Dict() 
)
inherited

Create an oracle function from MX

Definition at line 187 of file oracle_function.cpp.

192  {
193 
194  // Print progress
195  if (verbose_) {
196  casadi_message(name_ + "::create_function " + fname + ":" + str(s_in) + "->" + str(s_out));
197  }
198 
199  // Check if function is already in cache
200  Function ret;
201  if (incache(fname, ret)) {
202  // Consistency checks
203  casadi_assert(ret.n_in() == s_in.size(), fname + " has wrong number of inputs");
204  casadi_assert(ret.n_out() == s_out.size(), fname + " has wrong number of outputs");
205  } else {
206  // Retrieve specific set of options if available
207  Dict specific_options;
208  auto it = specific_options_.find(fname);
209  if (it!=specific_options_.end()) specific_options = it->second;
210 
211  // Combine specific and common options
212  Dict opt = combine(specific_options, common_options_);
213  opt = combine(opts, opt);
214 
215  // Generate the function
216  ret = Function(fname, e_in, e_out, s_in, s_out, opt);
217 
218  // Make sure that it's sound
219  if (ret.has_free()) {
220  casadi_error("Cannot create '" + fname + "' since " + str(ret.get_free()) + " are free.");
221  }
222 
223  // TODO(jgillis) Conditionally convert to SX
224 
225  // Add to cache
226  tocache_if_missing(ret);
227  }
228 
229  // Save and return
230  set_function(ret, fname, true);
231  return ret;
232 
233 }

References casadi::combine(), casadi::OracleFunction::common_options_, casadi::FunctionInternal::Function, casadi::Function::get_free(), casadi::Function::has_free(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::OracleFunction::set_function(), casadi::OracleFunction::specific_options_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::ProtoFunction::verbose_.

◆ create_function() [3/3]

Function casadi::OracleFunction::create_function ( const std::string &  fname,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux = Function::AuxOut(),
const Dict opts = Dict() 
)
inherited

Create an oracle function

Definition at line 179 of file oracle_function.cpp.

183  {
184  return create_function(oracle_, fname, s_in, s_out, aux, opts);
185 }
Function oracle_
Oracle: Used to generate other functions.
Function create_function(const Function &oracle, const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())

References casadi::OracleFunction::create_function(), and casadi::OracleFunction::oracle_.

◆ create_oracle()

template<typename XType >
Function casadi::Nlpsol::create_oracle ( const std::map< std::string, XType > &  d,
const Dict opts 
)
staticinherited

Definition at line 206 of file nlpsol.cpp.

207  {
208  std::vector<XType> nl_in(NL_NUM_IN), nl_out(NL_NUM_OUT);
209  for (auto&& i : d) {
210  if (i.first=="x") {
211  nl_in[NL_X]=i.second;
212  } else if (i.first=="p") {
213  nl_in[NL_P]=i.second;
214  } else if (i.first=="f") {
215  nl_out[NL_F]=i.second;
216  } else if (i.first=="g") {
217  nl_out[NL_G]=i.second;
218  } else {
219  casadi_error("No such field: " + i.first);
220  }
221  }
222  if (nl_out[NL_F].is_empty()) nl_out[NL_F] = 0;
223  if (nl_out[NL_G].is_empty()) nl_out[NL_G] = XType(0, 1);
224 
225  // Options for the oracle
226  Dict oracle_options;
227  Dict::const_iterator it = opts.find("oracle_options");
228  if (it != opts.end()) {
229  // "oracle_options" has been set
230  oracle_options = it->second;
231  } else {
232  // Propagate selected options from Nlpsol to oracle by default
233  for (const char* op : {"verbose", "regularity_check"}) {
234  it = opts.find(op);
235  if (it != opts.end()) {
236  oracle_options[op] = it->second;
237  }
238  }
239  }
240 
241  // Create oracle
242  return Function("nlp", nl_in, nl_out, NL_INPUTS, NL_OUTPUTS, oracle_options);
243  }
@ NL_X
Decision variable.
Definition: nlpsol.hpp:170
@ NL_P
Fixed parameter.
Definition: nlpsol.hpp:172
@ NL_NUM_IN
Number of NLP inputs.
Definition: nlpsol.hpp:174
@ NL_F
Objective function.
Definition: nlpsol.hpp:183
@ NL_G
Constraint function.
Definition: nlpsol.hpp:185
@ NL_NUM_OUT
Number of NLP outputs.
Definition: nlpsol.hpp:187
const std::vector< std::string > NL_INPUTS
Shortname for onput arguments of an NLP function.
Definition: nlpsol.hpp:178
const std::vector< std::string > NL_OUTPUTS
Shortname for output arguments of an NLP function.
Definition: nlpsol.hpp:191

References casadi::FunctionInternal::Function, casadi::NL_F, casadi::NL_G, casadi::NL_INPUTS, casadi::NL_NUM_IN, casadi::NL_NUM_OUT, casadi::NL_OUTPUTS, casadi::NL_P, and casadi::NL_X.

Referenced by casadi::construct_nlpsol().

◆ creator()

static Nlpsol* casadi::ConoptInterface::creator ( const std::string &  name,
const Function nlp 
)
inlinestatic

Definition at line 147 of file conopt_interface.hpp.

147  {
148  return new ConoptInterface(name, nlp);
149  }

Referenced by casadi::casadi_register_nlpsol_conopt().

◆ 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().

◆ deps_version_check()

virtual void casadi::PluginInterface< Nlpsol >::deps_version_check ( const std::string &  stage) const
inlinevirtualinherited

Definition at line 112 of file plugin_interface.hpp.

112 {}

◆ deserialize()

static ProtoFunction* casadi::ConoptInterface::deserialize ( DeserializingStream s)
inlinestatic

Definition at line 200 of file conopt_interface.hpp.

200 { return new ConoptInterface(s); }

Referenced by casadi::casadi_register_nlpsol_conopt().

◆ 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()

void casadi::Nlpsol::disp_more ( std::ostream &  stream) const
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 931 of file nlpsol.cpp.

931  {
932  stream << "minimize f(x;p) subject to lbx<=x<=ubx, lbg<=g(x;p)<=ubg defined by:\n";
933  oracle_.disp(stream, true);
934  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

References casadi::SharedObject::disp(), and casadi::OracleFunction::oracle_.

◆ 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_row_capacity()

void casadi::ConoptInterface::ensure_row_capacity ( ConoptMemory m,
casadi_int  remaining_rows 
) const

Definition at line 354 of file conopt_interface.cpp.

354  {
355  if (m->conopt_to_casadi.size() == m->conopt_to_casadi.capacity()) {
356  casadi_int growth = std::max<casadi_int>(
357  std::min<casadi_int>(remaining_rows, 10), remaining_rows / 4);
358  casadi_int new_cap = m->conopt_to_casadi.capacity() + growth;
359  m->conopt_to_casadi.reserve(new_cap);
360  m->conopt_type.reserve(new_cap);
361  m->conopt_rhs.reserve(new_cap);
362  }
363  }

References casadi::ConoptMemory::conopt_rhs, casadi::ConoptMemory::conopt_to_casadi, and casadi::ConoptMemory::conopt_type.

Referenced by solve().

◆ 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::Nlpsol::eval ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem 
) const
finalvirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 793 of file nlpsol.cpp.

793  {
794  auto *m = static_cast<NlpsolMemory*>(mem);
795 
796  auto *d_nlp = &m->d_nlp;
797 
798  // Reset the solver, prepare for solution
799  setup(m, arg, res, iw, w);
800  const auto *p_nlp = d_nlp->prob;
801 
802  // Set initial guess
803  casadi_copy(d_nlp->x0, nx_, d_nlp->z);
804 
805  // Read simple bounds and multiplier guesses
806  casadi_copy(d_nlp->lbx, nx_, d_nlp->lbz);
807  casadi_copy(d_nlp->ubx, nx_, d_nlp->ubz);
808  casadi_copy(d_nlp->lam_x0, nx_, d_nlp->lam);
809 
810  if (p_nlp->detect_bounds.ng==0) {
811  // Read constraint bounds and multiplier guesses
812  casadi_copy(d_nlp->lbg, ng_, d_nlp->lbz+nx_);
813  casadi_copy(d_nlp->ubg, ng_, d_nlp->ubz+nx_);
814  casadi_copy(d_nlp->lam_g0, ng_, d_nlp->lam+nx_);
815  } else {
816  if (casadi_nlpsol_detect_bounds_before(d_nlp)) return 1;
817  }
818 
819  // Set multipliers to nan
820  casadi_fill(d_nlp->lam_p, np_, nan);
821 
822  // Reset f, g
823  d_nlp->objective = nan;
824  casadi_fill(d_nlp->z + nx_, ng_, nan);
825 
826  // Check the provided inputs
827  check_inputs(m);
828 
829  // Solve the NLP
830  int flag = solve(m);
831 
832  // Join statistics (introduced for parallel oracle facilities)
833  join_results(m);
834 
835  // Calculate multiplers
836  if ((calc_f_ || calc_g_ || calc_lam_x_ || calc_lam_p_) && !flag) {
837  const double lam_f = 1.;
838  m->arg[0] = d_nlp->z;
839  m->arg[1] = d_nlp->p;
840  m->arg[2] = &lam_f;
841  m->arg[3] = d_nlp->lam + nx_;
842  m->res[0] = calc_f_ ? &d_nlp->objective : nullptr;
843  m->res[1] = calc_g_ ? d_nlp->z + nx_ : nullptr;
844  m->res[2] = calc_lam_x_ ? d_nlp->lam : nullptr;
845  m->res[3] = calc_lam_p_ ? d_nlp->lam_p : nullptr;
846  if (calc_function(m, "nlp_grad")) {
847  casadi_warning("Failed to calculate multipliers");
848  }
849  if (calc_lam_x_) casadi_scal(nx_, -1., d_nlp->lam);
850  if (calc_lam_p_) casadi_scal(np_, -1., d_nlp->lam_p);
851  }
852 
853  // Make sure that an optimal solution is consistant with bounds
854  if (bound_consistency_ && !flag) {
855  bound_consistency(nx_+ng_, d_nlp->z, d_nlp->lam, d_nlp->lbz, d_nlp->ubz);
856  }
857 
858  // Get optimal solution
859  casadi_copy(d_nlp->z, nx_, d_nlp->x);
860 
861  if (p_nlp->detect_bounds.ng==0) {
862  casadi_copy(d_nlp->z + nx_, ng_, d_nlp->g);
863  casadi_copy(d_nlp->lam, nx_, d_nlp->lam_x);
864  casadi_copy(d_nlp->lam + nx_, ng_, d_nlp->lam_g);
865  } else {
866  if (casadi_nlpsol_detect_bounds_after(d_nlp)) return 1;
867  }
868 
869  casadi_copy(d_nlp->lam_p, np_, d_nlp->lam_p);
870  casadi_copy(&d_nlp->objective, 1, d_nlp->f);
871 
872  if (m->success) m->unified_return_status = SOLVER_RET_SUCCESS;
873 
874  if (error_on_fail_ && !m->success)
875  casadi_error("nlpsol process failed. "
876  "Set 'error_on_fail' option to false to ignore this error.");
877 
878  if (m->unified_return_status==SOLVER_RET_EXCEPTION) {
879  casadi_error("An exception was raised in the solver.");
880  }
881  return flag;
882  }
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
virtual void check_inputs(void *mem) const
Check if the inputs correspond to a well-posed problem.
Definition: nlpsol.cpp:702
static void bound_consistency(casadi_int n, double *z, double *lam, const double *lbz, const double *ubz)
Definition: nlpsol.cpp:767
virtual int solve(void *mem) const =0
void join_results(OracleMemory *m) const
Combine results from different threads.
void casadi_fill(T1 *x, casadi_int n, T1 alpha)
FILL: x <- alpha.
const double nan
Not a number.
Definition: calculus.hpp:53
void casadi_scal(casadi_int n, T1 alpha, T1 *x)
SCAL: x <- alpha*x.
@ SOLVER_RET_SUCCESS
@ SOLVER_RET_EXCEPTION

References casadi::Nlpsol::bound_consistency(), casadi::Nlpsol::bound_consistency_, casadi::Nlpsol::calc_f_, casadi::OracleFunction::calc_function(), casadi::Nlpsol::calc_g_, casadi::Nlpsol::calc_lam_p_, casadi::Nlpsol::calc_lam_x_, casadi::casadi_copy(), casadi::casadi_fill(), casadi::casadi_scal(), casadi::Nlpsol::check_inputs(), casadi::NlpsolMemory::d_nlp, casadi::ProtoFunction::error_on_fail_, casadi::OracleFunction::join_results(), casadi::nan, casadi::Nlpsol::ng_, casadi::Nlpsol::np_, casadi::Nlpsol::nx_, casadi::FunctionInternal::setup(), casadi::Nlpsol::solve(), casadi::SOLVER_RET_EXCEPTION, and casadi::SOLVER_RET_SUCCESS.

◆ 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_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.
void print_time(const std::map< std::string, FStats > &fstats) const
Print timing statistics.

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().

◆ expand()

void casadi::OracleFunction::expand ( )
inherited

Definition at line 455 of file oracle_function.cpp.

455  {
456  oracle_ = oracle_.expand();
457 }
Function expand() const
Expand a function to SX.
Definition: function.cpp:312

References casadi::Function::expand(), and casadi::OracleFunction::oracle_.

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

◆ export_code()

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

◆ factory()

Function casadi::FunctionInternal::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
virtualinherited

◆ finalize()

void casadi::OracleFunction::finalize ( )
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 122 of file oracle_function.cpp.

122  {
123  if (post_expand_) {
124  for (auto&& e : all_functions_) {
125  Function& fcn = e.second.f;
126  fcn = fcn.expand();
127  }
128  }
129 
130  // Allocate space for (parallel) evaluations
131  // Lifted from set_function as max_num_threads_ is not known yet in that method
132  for (auto&& e : all_functions_) {
133  Function& fcn = e.second.f;
134  // Compute strides for multi threading
135  size_t sz_arg, sz_res, sz_iw, sz_w;
136  fcn.sz_work(sz_arg, sz_res, sz_iw, sz_w);
137  stride_arg_ = std::max(stride_arg_, sz_arg);
138  stride_res_ = std::max(stride_res_, sz_res);
139  stride_iw_ = std::max(stride_iw_, sz_iw);
140  stride_w_ = std::max(stride_w_, sz_w);
141  bool persistent = false;
142  alloc(fcn, persistent, max_num_threads_);
143  }
144 
145  // Set corresponding monitors
146  for (const std::string& fname : monitor_) {
147  auto it = all_functions_.find(fname);
148  if (it==all_functions_.end()) {
149  casadi_warning("Ignoring monitor '" + fname + "'."
150  " Available functions: " + join(get_function()) + ".");
151  } else {
152  if (it->second.monitored) casadi_warning("Duplicate monitor " + fname);
153  it->second.monitored = true;
154  }
155  }
156 
157  // Check specific options
158  for (auto&& i : specific_options_) {
159  if (all_functions_.find(i.first)==all_functions_.end())
160  casadi_warning("Ignoring specific_options entry '" + i.first+"'."
161  " Available functions: " + join(get_function()) + ".");
162  }
163 
164  // Recursive call
166 }
void finalize() override
Finalize the object creation.
void alloc(const Function &f, bool persistent=false, int num_threads=1)
Ensure work vectors long enough to evaluate function.
std::map< std::string, RegFun > all_functions_
std::vector< std::string > monitor_
std::string join(const std::vector< std::string > &l, const std::string &delim)

References casadi::OracleFunction::all_functions_, casadi::FunctionInternal::alloc(), casadi::Function::expand(), casadi::FunctionInternal::finalize(), casadi::OracleFunction::get_function(), casadi::join(), casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::monitor_, casadi::OracleFunction::post_expand_, casadi::OracleFunction::specific_options_, casadi::OracleFunction::stride_arg_, casadi::OracleFunction::stride_iw_, casadi::OracleFunction::stride_res_, casadi::OracleFunction::stride_w_, casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::Function::sz_work().

◆ find()

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

Reimplemented from casadi::FunctionInternal.

Definition at line 548 of file oracle_function.cpp.

549  {
550  // Call to base class
551  FunctionInternal::find(all_fun, max_depth);
552  for (auto&& e : all_functions_) {
553  add_embedded(all_fun, e.second.f, max_depth);
554  }
555 }
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

References casadi::FunctionInternal::add_embedded(), casadi::OracleFunction::all_functions_, and casadi::FunctionInternal::find().

◆ 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.
casadi_int size1_out(casadi_int ind) const
Input/output dimensions.
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

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::ConoptInterface::free_mem ( void *  mem) const
overridevirtual

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

Reimplemented from casadi::Nlpsol.

Definition at line 257 of file conopt_interface.cpp.

257 { delete static_cast<ConoptMemory*>(mem); }

◆ 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.

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::OracleFunction::generate_dependencies ( const std::string &  fname,
const Dict opts 
) const
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 428 of file oracle_function.cpp.

429  {
430  CodeGenerator gen(fname, opts);
431  gen.add(oracle_);
432  for (auto&& e : all_functions_) {
433  if (e.second.jit) gen.add(e.second.f);
434  }
435  return gen.generate();
436 }

References casadi::CodeGenerator::add(), casadi::OracleFunction::all_functions_, casadi::CodeGenerator::generate(), and casadi::OracleFunction::oracle_.

Referenced by casadi::OracleFunction::jit_dependencies().

◆ 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.
std::string compiler_plugin_
Just-in-time compiler.
void * user_data_
User-set field.
bool jit_
Use just-in-time compiler.
bool jit_temp_suffix_
Use a temporary name.
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.

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()

double casadi::Nlpsol::get_default_in ( casadi_int  ind) const
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 204 of file nlpsol_impl.hpp.

204 { return nlpsol_default_in(ind);}
double nlpsol_default_in(casadi_int ind)
Default input for an NLP solver.
Definition: nlpsol.cpp:291

References casadi::nlpsol_default_in().

Referenced by casadi::Nlpsol::check_inputs().

◆ 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::Nlpsol::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
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 957 of file nlpsol.cpp.

961  {
962  casadi_assert(detect_simple_bounds_is_simple_.empty(),
963  "Simple bound detection not compatible with get_forward");
964 
965  // Symbolic expression for the input
966  std::vector<MX> arg = mx_in(), res = mx_out();
967 
968  // Initial guesses not used for derivative calculations
970  std::string name = arg[i].is_symbolic() ? arg[i].name() : "tmp_get_forward";
971  arg[i] = MX::sym(name, Sparsity(arg[i].size()));
972  }
973 
974  // Optimal solution
975  MX x = res[NLPSOL_X];
976  MX lam_g = res[NLPSOL_LAM_G];
977  MX lam_x = res[NLPSOL_LAM_X];
978  MX lam_p = res[NLPSOL_LAM_P];
979  MX f = res[NLPSOL_F];
980  MX g = res[NLPSOL_G];
981 
982  // Inputs used
983  MX lbx = arg[NLPSOL_LBX];
984  MX ubx = arg[NLPSOL_UBX];
985  MX lbg = arg[NLPSOL_LBG];
986  MX ubg = arg[NLPSOL_UBG];
987  MX p = arg[NLPSOL_P];
988 
989  // Get KKT function
990  Function kkt = this->kkt();
991 
992  // Hessian of the Lagrangian, Jacobian of the constraints
993  std::vector<MX> HJ_res = kkt({x, p, 1, lam_g});
994  MX JG = HJ_res.at(0);
995  MX HL = HJ_res.at(1);
996 
997  // Active set (assumed known and given by the multiplier signs)
998  MX ubIx = lam_x > min_lam_;
999  MX lbIx = lam_x < -min_lam_;
1000  MX bIx = ubIx + lbIx;
1001  MX iIx = 1-bIx;
1002  MX ubIg = lam_g > min_lam_;
1003  MX lbIg = lam_g < -min_lam_;
1004  MX bIg = ubIg + lbIg;
1005  MX iIg = 1-bIg;
1006 
1007  // KKT matrix
1008  MX H_11 = mtimes(diag(iIx), HL) + diag(bIx);
1009  MX H_12 = mtimes(diag(iIx), JG.T());
1010  MX H_21 = mtimes(diag(bIg), JG);
1011  MX H_22 = diag(-iIg);
1012  MX H = MX::blockcat({{H_11, H_12}, {H_21, H_22}});
1013 
1014  // Sensitivity inputs
1015  std::vector<MX> fseed(NLPSOL_NUM_IN);
1016  MX fwd_lbx = fseed[NLPSOL_LBX] = MX::sym("fwd_lbx", repmat(x.sparsity(), 1, nfwd));
1017  MX fwd_ubx = fseed[NLPSOL_UBX] = MX::sym("fwd_ubx", repmat(x.sparsity(), 1, nfwd));
1018  MX fwd_lbg = fseed[NLPSOL_LBG] = MX::sym("fwd_lbg", repmat(g.sparsity(), 1, nfwd));
1019  MX fwd_ubg = fseed[NLPSOL_UBG] = MX::sym("fwd_ubg", repmat(g.sparsity(), 1, nfwd));
1020  MX fwd_p = fseed[NLPSOL_P] = MX::sym("fwd_p", repmat(p.sparsity(), 1, nfwd));
1021 
1022  // Guesses are unused
1024  fseed[i] = MX(repmat(Sparsity(arg[i].size()), 1, nfwd));
1025  }
1026 
1027  // nlp_grad has the signature
1028  // (x, p, lam_f, lam_g) -> (f, g, grad_x, grad_p)
1029  // with lam_f=1 and lam_g=lam_g, grad_x = -lam_x, grad_p=-lam_p
1030  Function nlp_grad = get_function("nlp_grad");
1031 
1032  // fwd_nlp_grad has the signature
1033  // (x, p, lam_f, lam_g, f, g, grad_x, grad_p,
1034  // fwd_x, fwd_p, fwd_lam_f, fwd_lam_g)
1035  // -> (fwd_f, fwd_g, fwd_grad_x, fwd_grad_p)
1036  Function fwd_nlp_grad = nlp_grad.forward(nfwd);
1037 
1038  // Calculate sensitivities from fwd_p
1039  std::vector<MX> vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p, 0., fwd_p, 0., 0.};
1040  vv = fwd_nlp_grad(vv);
1041  MX fwd_g_p = vv.at(1);
1042  MX fwd_gL_p = vv.at(2);
1043 
1044  // Propagate forward seeds
1045  MX fwd_alpha_x = (if_else(lbIx, fwd_lbx, 0) + if_else(ubIx, fwd_ubx, 0))
1046  - if_else(iIx, fwd_gL_p, 0);
1047  MX fwd_alpha_g = (if_else(ubIg, fwd_ubg, 0) + if_else(lbIg, fwd_lbg, 0))
1048  - if_else(bIg, fwd_g_p, 0);
1049  MX v = MX::vertcat({fwd_alpha_x, fwd_alpha_g});
1050 
1051  // Solve
1053 
1054  // Extract sensitivities in x, lam_x and lam_g
1055  std::vector<MX> v_split = vertsplit(v, {0, nx_, nx_+ng_});
1056  MX fwd_x = v_split.at(0);
1057  MX fwd_lam_g = v_split.at(1);
1058 
1059  // Calculate sensitivities in lam_x, lam_g
1060  vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p,
1061  fwd_x, fwd_p, 0, fwd_lam_g};
1062  vv = fwd_nlp_grad(vv);
1063  MX fwd_f = vv.at(0);
1064  MX fwd_g = vv.at(1);
1065  MX fwd_lam_x = -vv.at(2);
1066  MX fwd_lam_p = -vv.at(3);
1067 
1068  // Forward sensitivities
1069  std::vector<MX> fsens(NLPSOL_NUM_OUT);
1070  fsens[NLPSOL_X] = fwd_x;
1071  fsens[NLPSOL_F] = fwd_f;
1072  fsens[NLPSOL_G] = fwd_g;
1073  fsens[NLPSOL_LAM_X] = fwd_lam_x;
1074  fsens[NLPSOL_LAM_G] = fwd_lam_g;
1075  fsens[NLPSOL_LAM_P] = fwd_lam_p;
1076 
1077  // Gather return values
1078  arg.insert(arg.end(), res.begin(), res.end());
1079  arg.insert(arg.end(), fseed.begin(), fseed.end());
1080  res = fsens;
1081 
1082  Dict options = opts;
1083  options["allow_duplicate_io_names"] = true;
1084 
1085  return Function(name, arg, res, inames, onames, options);
1086  }
virtual const std::vector< MX > mx_in() const
Get function input(s) and output(s)
virtual const std::vector< MX > mx_out() const
Get function input(s) and output(s)
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
static MX blockcat(const std::vector< std::vector< MX > > &v)
Definition: mx.cpp:1263
static MX solve(const MX &a, const MX &b)
Definition: mx.cpp:2115
static MX vertcat(const std::vector< MX > &x)
Definition: mx.cpp:1165
Function kkt() const
Definition: nlpsol.cpp:936
Dict sens_linsol_options_
Definition: nlpsol_impl.hpp:82
double min_lam_
Options.
Definition: nlpsol_impl.hpp:99
std::string sens_linsol_
Linear solver and options.
Definition: nlpsol_impl.hpp:81
NlpsolInput
Input arguments of an NLP Solver.
Definition: nlpsol.hpp:194
double if_else(double x, double y, double z)
Definition: calculus.hpp:296

References casadi::MX::blockcat(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Function::forward(), casadi::FunctionInternal::Function, casadi::OracleFunction::get_function(), casadi::if_else(), casadi::Nlpsol::kkt(), casadi::Nlpsol::min_lam_, casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::mx_out(), casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::Nlpsol::nx_, casadi::Nlpsol::sens_linsol_, casadi::Nlpsol::sens_linsol_options_, casadi::MX::solve(), casadi::MX::sparsity(), casadi::GenericMatrix< MX >::sym(), and casadi::MX::vertcat().

◆ 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::OracleFunction::get_function ( ) const
overridevirtualinherited

-1 Indicates irregularity

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

Reimplemented from casadi::FunctionInternal.

Definition at line 531 of file oracle_function.cpp.

531  {
532  std::vector<std::string> ret;
533  ret.reserve(all_functions_.size());
534  for (auto&& e : all_functions_) {
535  ret.push_back(e.first);
536  }
537  return ret;
538 }

References casadi::OracleFunction::all_functions_.

Referenced by casadi::Rootfinder::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::SundialsInterface::calc_daeB(), casadi::OracleFunction::calc_function(), casadi::SundialsInterface::calc_quadB(), casadi::OracleFunction::calc_sp_forward(), casadi::OracleFunction::calc_sp_reverse(), casadi::FastNewton::codegen_body(), casadi::Feasiblesqpmethod::codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Nlpsol::codegen_declarations(), casadi::MadmpecInterface::codegen_declarations(), casadi::FatropInterface::codegen_declarations(), casadi::IpoptInterface::codegen_declarations(), casadi::MadnlpInterface::codegen_declarations(), casadi::UnoInterface::codegen_declarations(), casadi::FastNewton::codegen_declarations(), casadi::Feasiblesqpmethod::codegen_declarations(), casadi::Sqpmethod::codegen_declarations(), casadi::Feasiblesqpmethod::codegen_feasibility_iterations(), casadi::Nlpsol::codegen_post_solve(), ConoptInterface(), casadi::FixedStepIntegrator::create_advanced(), casadi::OracleFunction::create_forward(), casadi::AlpaqaProblem::eval_hess_L(), casadi::AlpaqaProblem::eval_hess_ψ(), casadi::OracleFunction::finalize(), casadi::Nlpsol::get_forward(), casadi::OracleFunction::get_function(), casadi::AlpaqaProblem::get_hess_L_num_nonzeros(), casadi::AlpaqaProblem::get_hess_ψ_num_nonzeros(), casadi::Nlpsol::get_reverse(), casadi::FixedStepIntegrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), casadi::FastNewton::init(), casadi::Feasiblesqpmethod::init(), casadi::Sqpmethod::init(), casadi::OracleFunction::monitored(), casadi::MadmpecInterface::set_ccopt_prob(), casadi::FatropInterface::set_fatrop_prob(), casadi::IpoptInterface::set_ipopt_prob(), casadi::MadnlpInterface::set_madnlp_prob(), casadi::SundialsInterface::set_work(), casadi::Collocation::setup_step(), casadi::RungeKutta::setup_step(), casadi::Integrator::sp_jac_dae(), casadi::Integrator::sp_jac_rdae(), and casadi::FixedStepIntegrator::stepB().

◆ get_function() [2/2]

const Function & casadi::OracleFunction::get_function ( const std::string &  name) const
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 540 of file oracle_function.cpp.

540  {
541  auto it = all_functions_.find(name);
542  casadi_assert(it!=all_functions_.end(),
543  "No function \"" + name + "\" in " + name_ + ". " +
544  "Available functions: " + join(get_function()) + ".");
545  return it->second.f;
546 }

References casadi::OracleFunction::all_functions_, casadi::OracleFunction::get_function(), casadi::join(), and casadi::ProtoFunction::name_.

◆ get_jac_sparsity()

Sparsity casadi::FunctionInternal::get_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  symmetric 
) const
virtualinherited

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

Reimplemented in casadi::FmuFunction, casadi::GenericExternal, casadi::Expm, and casadi::CallbackInternal.

Definition at line 1986 of file function_internal.cpp.

1987  {
1988  if (symmetric) {
1989  casadi_assert(sparsity_out_[oind].is_dense(),
1990  "Symmetry exploitation in Jacobian assumes dense expression. "
1991  "A potential workaround is to apply densify().");
1992  }
1993  // Check if we are able to propagate dependencies through the function
1994  if (has_spfwd() || has_sprev()) {
1995  // Get weighting factor
1996  double w = sp_weight();
1997 
1998  // Skip generation, assume dense
1999  if (w == -1) return Sparsity();
2000 
2001  Sparsity sp;
2002  if (nnz_in(iind) > 3*bvec_size && nnz_out(oind) > 3*bvec_size &&
2004  if (symmetric) {
2005  sp = get_jac_sparsity_hierarchical_symm(oind, iind);
2006  } else {
2007  sp = get_jac_sparsity_hierarchical(oind, iind);
2008  }
2009  } else {
2010  // Number of nonzero inputs and outputs
2011  casadi_int nz_in = nnz_in(iind);
2012  casadi_int nz_out = nnz_out(oind);
2013 
2014  // Number of forward sweeps we must make
2015  casadi_int nsweep_fwd = nz_in/bvec_size;
2016  if (nz_in%bvec_size) nsweep_fwd++;
2017 
2018  // Number of adjoint sweeps we must make
2019  casadi_int nsweep_adj = nz_out/bvec_size;
2020  if (nz_out%bvec_size) nsweep_adj++;
2021 
2022  // Use forward mode?
2023  if (w*static_cast<double>(nsweep_fwd) <= (1-w)*static_cast<double>(nsweep_adj)) {
2024  sp = get_jac_sparsity_gen<true>(oind, iind);
2025  } else {
2026  sp = get_jac_sparsity_gen<false>(oind, iind);
2027  }
2028  }
2029  return sp;
2030  } else {
2031  // Not calculated
2032  return Sparsity();
2033  }
2034  }
virtual bool has_sprev() const
Is the class able to propagate seeds through the algorithm?
Sparsity get_jac_sparsity_hierarchical_symm(casadi_int oind, casadi_int iind) const
virtual double sp_weight() const
Weighting factor for chosing forward/reverse mode,.
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.
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.
virtual bool has_spfwd() const
Is the class able to propagate seeds through the algorithm?
static bool hierarchical_sparsity
const int bvec_size

References casadi::bvec_size, casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::FunctionInternal::has_spfwd(), casadi::FunctionInternal::has_sprev(), casadi::GlobalOptions::hierarchical_sparsity, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::FunctionInternal::sp_weight(), and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::Expm::get_jac_sparsity(), casadi::GenericExternal::get_jac_sparsity(), and casadi::FunctionInternal::jac_sparsity().

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

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

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::FunctionInternal::get_jacobian ( const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
virtualinherited

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

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::Nlpsol::get_n_in ( )
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 145 of file nlpsol_impl.hpp.

145 { return NLPSOL_NUM_IN;}

References casadi::NLPSOL_NUM_IN.

◆ get_n_out()

size_t casadi::Nlpsol::get_n_out ( )
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 146 of file nlpsol_impl.hpp.

146 { return NLPSOL_NUM_OUT;}

References casadi::NLPSOL_NUM_OUT.

◆ get_name_in()

std::string casadi::Nlpsol::get_name_in ( casadi_int  i)
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 161 of file nlpsol_impl.hpp.

161 { return nlpsol_in(i);}
std::vector< std::string > nlpsol_in()
Get input scheme of NLP solvers.
Definition: nlpsol.cpp:279

References casadi::nlpsol_in().

◆ get_name_out()

std::string casadi::Nlpsol::get_name_out ( casadi_int  i)
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 162 of file nlpsol_impl.hpp.

162 { return nlpsol_out(i);}
std::vector< std::string > nlpsol_out()
Get NLP solver output scheme of NLP solvers.
Definition: nlpsol.cpp:285

References casadi::nlpsol_out().

◆ get_nominal_in()

virtual std::vector<double> casadi::FunctionInternal::get_nominal_in ( casadi_int  ind) const
inlinevirtualinherited

Reimplemented in casadi::FmuFunction.

Definition at line 1117 of file function_internal.hpp.

1117  {
1118  return std::vector<double>(nnz_in(ind), 1.);
1119  }

Referenced by casadi::FmuFunction::get_nominal_in().

◆ get_nominal_out()

virtual std::vector<double> casadi::FunctionInternal::get_nominal_out ( casadi_int  ind) const
inlinevirtualinherited

Reimplemented in casadi::FmuFunction.

Definition at line 1121 of file function_internal.hpp.

1121  {
1122  return std::vector<double>(nnz_out(ind), 1.);
1123  }

Referenced by casadi::FmuFunction::get_nominal_out().

◆ get_options()

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

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

Reimplemented from casadi::Nlpsol.

Definition at line 152 of file conopt_interface.hpp.

152 { return options_; }
static const 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::Nlpsol::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
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1088 of file nlpsol.cpp.

1092  {
1093  casadi_assert(detect_simple_bounds_is_simple_.empty(),
1094  "Simple bound detection not compatible with get_reverse");
1095 
1096  // Symbolic expression for the input
1097  std::vector<MX> arg = mx_in(), res = mx_out();
1098 
1099  // Initial guesses not used for derivative calculations
1101  std::string name = arg[i].is_symbolic() ? arg[i].name() : "tmp_get_reverse";
1102  arg[i] = MX::sym(name, Sparsity(arg[i].size()));
1103  }
1104 
1105  // Optimal solution
1106  MX x = res[NLPSOL_X];
1107  MX lam_g = res[NLPSOL_LAM_G];
1108  MX lam_x = res[NLPSOL_LAM_X];
1109  MX lam_p = res[NLPSOL_LAM_P];
1110  MX f = res[NLPSOL_F];
1111  MX g = res[NLPSOL_G];
1112 
1113  // Inputs used
1114  MX lbx = arg[NLPSOL_LBX];
1115  MX ubx = arg[NLPSOL_UBX];
1116  MX lbg = arg[NLPSOL_LBG];
1117  MX ubg = arg[NLPSOL_UBG];
1118  MX p = arg[NLPSOL_P];
1119 
1120  // Get KKT function
1121  Function kkt = this->kkt();
1122 
1123  // Hessian of the Lagrangian, Jacobian of the constraints
1124  std::vector<MX> HJ_res = kkt({x, p, 1, lam_g});
1125  MX JG = HJ_res.at(0);
1126  MX HL = HJ_res.at(1);
1127 
1128  // Active set (assumed known and given by the multiplier signs)
1129  MX ubIx = lam_x > min_lam_;
1130  MX lbIx = lam_x < -min_lam_;
1131  MX bIx = ubIx + lbIx;
1132  MX iIx = 1-bIx;
1133  MX ubIg = lam_g > min_lam_;
1134  MX lbIg = lam_g < -min_lam_;
1135  MX bIg = ubIg + lbIg;
1136  MX iIg = 1-bIg;
1137 
1138  // KKT matrix
1139  MX H_11 = mtimes(diag(iIx), HL) + diag(bIx);
1140  MX H_12 = mtimes(diag(iIx), JG.T());
1141  MX H_21 = mtimes(diag(bIg), JG);
1142  MX H_22 = diag(-iIg);
1143  MX H = MX::blockcat({{H_11, H_12}, {H_21, H_22}});
1144 
1145  // Sensitivity inputs
1146  std::vector<MX> aseed(NLPSOL_NUM_OUT);
1147  MX adj_x = aseed[NLPSOL_X] = MX::sym("adj_x", repmat(x.sparsity(), 1, nadj));
1148  MX adj_lam_g = aseed[NLPSOL_LAM_G] = MX::sym("adj_lam_g", repmat(g.sparsity(), 1, nadj));
1149  MX adj_lam_x = aseed[NLPSOL_LAM_X] = MX::sym("adj_lam_x", repmat(x.sparsity(), 1, nadj));
1150  MX adj_lam_p = aseed[NLPSOL_LAM_P] = MX::sym("adj_lam_p", repmat(p.sparsity(), 1, nadj));
1151  MX adj_f = aseed[NLPSOL_F] = MX::sym("adj_f", Sparsity::dense(1, nadj));
1152  MX adj_g = aseed[NLPSOL_G] = MX::sym("adj_g", repmat(g.sparsity(), 1, nadj));
1153 
1154  // nlp_grad has the signature
1155  // (x, p, lam_f, lam_g) -> (f, g, grad_x, grad_p)
1156  // with lam_f=1 and lam_g=lam_g, grad_x = -lam_x, grad_p=-lam_p
1157  Function nlp_grad = get_function("nlp_grad");
1158 
1159  // rev_nlp_grad has the signature
1160  // (x, p, lam_f, lam_g, f, g, grad_x, grad_p,
1161  // adj_f, adj_g, adj_grad_x, adj_grad_p)
1162  // -> (adj_x, adj_p, adj_lam_f, adj_lam_g)
1163  Function rev_nlp_grad = nlp_grad.reverse(nadj);
1164 
1165  // Calculate sensitivities from f, g and lam_x
1166  std::vector<MX> vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p,
1167  adj_f, adj_g, -adj_lam_x, -adj_lam_p};
1168  vv = rev_nlp_grad(vv);
1169  MX adj_x0 = vv.at(0);
1170  MX adj_p0 = vv.at(1);
1171  MX adj_lam_g0 = vv.at(3);
1172 
1173  // Solve to get beta_x_bar, beta_g_bar
1174  MX v = MX::vertcat({adj_x + adj_x0, adj_lam_g + adj_lam_g0});
1176  std::vector<MX> v_split = vertsplit(v, {0, nx_, nx_+ng_});
1177  MX beta_x_bar = v_split.at(0);
1178  MX beta_g_bar = v_split.at(1);
1179 
1180  // Calculate sensitivities in p
1181  vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p,
1182  0, bIg*beta_g_bar, iIx*beta_x_bar, 0};
1183  vv = rev_nlp_grad(vv);
1184  MX adj_p = vv.at(1);
1185 
1186  // Reverse sensitivities
1187  std::vector<MX> asens(NLPSOL_NUM_IN);
1188  asens[NLPSOL_UBX] = if_else(ubIx, beta_x_bar, 0);
1189  asens[NLPSOL_LBX] = if_else(lbIx, beta_x_bar, 0);
1190  asens[NLPSOL_UBG] = if_else(ubIg, beta_g_bar, 0);
1191  asens[NLPSOL_LBG] = if_else(lbIg, beta_g_bar, 0);
1192  asens[NLPSOL_P] = adj_p0 - adj_p;
1193 
1194  // Guesses are unused
1196  asens[i] = MX(repmat(Sparsity(arg[i].size()), 1, nadj));
1197  }
1198 
1199  // Gather return values
1200  arg.insert(arg.end(), res.begin(), res.end());
1201  arg.insert(arg.end(), aseed.begin(), aseed.end());
1202  res = asens;
1203 
1204  Dict options = opts;
1205  options["allow_duplicate_io_names"] = true;
1206 
1207  return Function(name, arg, res, inames, onames, options);
1208  }

References casadi::MX::blockcat(), casadi::Sparsity::dense(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::FunctionInternal::Function, casadi::OracleFunction::get_function(), casadi::if_else(), casadi::Nlpsol::kkt(), casadi::Nlpsol::min_lam_, casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::mx_out(), casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::Nlpsol::nx_, casadi::Function::reverse(), casadi::Nlpsol::sens_linsol_, casadi::Nlpsol::sens_linsol_options_, casadi::MX::solve(), casadi::MX::sparsity(), casadi::GenericMatrix< MX >::sym(), casadi::MX::T(), and casadi::MX::vertcat().

◆ get_sparsity_in()

Sparsity casadi::Nlpsol::get_sparsity_in ( casadi_int  i)
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 373 of file nlpsol.cpp.

373  {
374  switch (static_cast<NlpsolInput>(i)) {
375  case NLPSOL_X0:
376  case NLPSOL_LBX:
377  case NLPSOL_UBX:
378  case NLPSOL_LAM_X0:
379  return get_sparsity_out(NLPSOL_X);
380  case NLPSOL_LBG:
381  case NLPSOL_UBG:
382  case NLPSOL_LAM_G0:
383  return get_sparsity_out(NLPSOL_G);
384  case NLPSOL_P:
385  return oracle_.sparsity_in(NL_P);
386  case NLPSOL_NUM_IN: break;
387  }
388  return Sparsity();
389  }
const Sparsity & sparsity_in(casadi_int ind) const
Get sparsity of a given input.
Definition: function.cpp:1167
Sparsity get_sparsity_out(casadi_int i) override
Sparsities of function inputs and outputs.
Definition: nlpsol.cpp:391

References casadi::Nlpsol::get_sparsity_out(), casadi::NL_P, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::OracleFunction::oracle_, and casadi::Function::sparsity_in().

Referenced by casadi::Nlpsol::get_sparsity_out().

◆ get_sparsity_out()

Sparsity casadi::Nlpsol::get_sparsity_out ( casadi_int  i)
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 391 of file nlpsol.cpp.

391  {
392  switch (static_cast<NlpsolOutput>(i)) {
393  case NLPSOL_F:
394  return oracle_.sparsity_out(NL_F);
395  case NLPSOL_X:
396  case NLPSOL_LAM_X:
397  return oracle_.sparsity_in(NL_X);
398  case NLPSOL_LAM_G:
399  case NLPSOL_G:
400  if (detect_simple_bounds_is_simple_.empty()) {
401  return oracle_.sparsity_out(NL_G);
402  } else {
404  }
405  case NLPSOL_LAM_P:
406  return get_sparsity_in(NLPSOL_P);
407  case NLPSOL_NUM_OUT: break;
408  }
409  return Sparsity();
410  }
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
Definition: function.cpp:1183
Sparsity get_sparsity_in(casadi_int i) override
Sparsities of function inputs and outputs.
Definition: nlpsol.cpp:373
NlpsolOutput
Output arguments of an NLP Solver.
Definition: nlpsol.hpp:215

References casadi::Sparsity::dense(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Nlpsol::get_sparsity_in(), casadi::NL_F, casadi::NL_G, casadi::NL_X, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_X, casadi::OracleFunction::oracle_, casadi::Function::sparsity_in(), and casadi::Function::sparsity_out().

Referenced by casadi::Nlpsol::get_sparsity_in().

◆ get_stats()

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

Reimplemented from casadi::Nlpsol.

Definition at line 612 of file conopt_interface.cpp.

612  {
613  Dict stats = Nlpsol::get_stats(mem);
614  auto m = static_cast<ConoptMemory*>(mem);
615  stats["return_status"] = m->return_status;
616  stats["modsta"] = static_cast<int>(m->modsta);
617  stats["solsta"] = static_cast<int>(m->solsta);
618  stats["iter_count"] = m->iter;
619  return stats;
620  }
Dict get_stats(void *mem) const override
Get all statistics.
Definition: nlpsol.cpp:1251

References casadi::Nlpsol::get_stats(), and casadi::ConoptMemory::return_status.

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

◆ getPlugin()

PluginInterface< Nlpsol >::Plugin & casadi::PluginInterface< Nlpsol >::getPlugin ( const std::string &  pname)
staticinherited

Definition at line 102 of file plugin_interface.hpp.

295  {
296 
297 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
298  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
299 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
300 
301  // Check if the solver has been loaded
302  auto it=Derived::solvers_.find(pname);
303 
304  // Load the solver if needed
305  if (it==Derived::solvers_.end()) {
306  load_plugin(pname, true, false);
307  it=Derived::solvers_.find(pname);
308  }
309  casadi_assert_dev(it!=Derived::solvers_.end());
310  return it->second;
311  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

◆ getReducedHessian()

DM casadi::Nlpsol::getReducedHessian ( )
virtualinherited

Definition at line 758 of file nlpsol.cpp.

758  {
759  casadi_error("getReducedHessian not defined for class " + class_name());
760  return DM();
761  }
std::string class_name() const override
Get type name.
Matrix< double > DM
Definition: dm_fwd.hpp:33

References casadi::Nlpsol::class_name().

◆ 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::Nlpsol::has_forward ( casadi_int  nfwd) const
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 267 of file nlpsol_impl.hpp.

267 { return true;}

◆ 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()

bool casadi::OracleFunction::has_function ( const std::string &  fname) const
overridevirtualinherited

◆ has_jac_sparsity()

virtual bool casadi::FunctionInternal::has_jac_sparsity ( casadi_int  oind,
casadi_int  iind 
) const
inlinevirtualinherited

◆ has_jacobian()

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

◆ 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_plugin()

bool casadi::PluginInterface< Nlpsol >::has_plugin ( const std::string &  pname,
bool  verbose = false 
)
staticinherited

Definition at line 76 of file plugin_interface.hpp.

134  {
135 
136 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
137  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
138 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
139 
140  // Quick return if available
141  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
142  return true;
143  }
144 
145  // Try loading the plugin
146  try {
147  (void)load_plugin(pname, false, false);
148  return true;
149  } catch (CasadiException& ex) {
150  if (verbose) {
151  casadi_warning(ex.what());
152  }
153  return false;
154  }
155  }
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros

◆ has_reverse()

bool casadi::Nlpsol::has_reverse ( casadi_int  nadj) const
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 278 of file nlpsol_impl.hpp.

278 { return true;}

◆ has_spfwd()

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

◆ has_sprev()

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

◆ 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::ConoptInterface::init ( const Dict opts)
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 71 of file conopt_interface.cpp.

71  {
72  Nlpsol::init(opts);
73 
74  // Extract native options
75  warm_start_ = false;
76  debug_ = false;
77  for (auto&& op : opts) {
78  if (op.first == "conopt") opts_ = op.second;
79  else if (op.first == "optfile") optfile_ = op.second.to_string();
80  else if (op.first == "warm_start") warm_start_ = op.second.to_bool();
81  else if (op.first == "debug") debug_ = op.second.to_bool();
82  }
83 
84  for (auto&& op : opts_) {
85  casadi_assert(op.first.size() <= conopt_max_option_name,
86  "CONOPT option name '" + op.first + "' is " + str(op.first.size()) +
87  " characters; CONOPT accepts at most " + str(conopt_max_option_name) + ".");
88  }
89 
90  Function gradf_fcn = create_function("nlp_grad_f", {"x", "p"}, {"f", "grad:f:x"});
91  gradf_sp_ = gradf_fcn.sparsity_out(1);
92 
93  Function jacg_fcn = create_function("nlp_jac_g", {"x", "p"}, {"g", "jac:g:x"});
94  jacg_sp_ = jacg_fcn.sparsity_out(1);
95 
96  // Detect linear (constant) Jacobian entries using second-order sparsity:
97  // d(jac:g:x_compact)/dx has shape (nnz_g, nx_); if row k is empty,
98  // the k-th Jacobian nonzero is constant in x (linear entry).
99  {
100  Sparsity djac_dx = jacg_fcn.sparsity_jac(0, 1, true);
101  jacg_nlflag_.assign(jacg_sp_.nnz(), 0);
102  const casadi_int* dj_row = djac_dx.row();
103  for (casadi_int el = 0; el < djac_dx.nnz(); ++el)
104  jacg_nlflag_[dj_row[el]] = 1;
105  has_linear_jac_ = std::any_of(jacg_nlflag_.begin(), jacg_nlflag_.end(),
106  [](int f) { return f == 0; });
107  }
108 
109  // Setup 2nd Order Info
110  exact_hessian_ = true;
111  if (opts.find("exact_hessian") != opts.end()) exact_hessian_ = opts.at("exact_hessian");
112 
113  if (exact_hessian_) {
114  Function hl_fcn = create_function("nlp_hess_l", {"x", "p", "lam:f", "lam:g"},
115  {"tril:hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
116  hesslag_sp_ = hl_fcn.sparsity_out(0);
117  }
118 
119  // Per-column objective-gradient flag (used in cb_read_matrix)
120  const casadi_int* f_row = gradf_sp_.row();
121  gradf_col_flag_.assign(nx_, false);
122  gradf_col_to_nz_.assign(nx_, -1);
123  for (casadi_int k = 0; k < gradf_sp_.nnz(); ++k) {
124  gradf_col_flag_[f_row[k]] = true;
125  gradf_col_to_nz_[f_row[k]] = k;
126  }
127 
128  // Detect constant (linear) objective gradient entries using second-order sparsity
129  {
130  Sparsity dgradf_dx = gradf_fcn.sparsity_jac(0, 1, true);
131  gradf_nlflag_.assign(gradf_sp_.nnz(), 0);
132  const casadi_int* dg_row = dgradf_dx.row();
133  for (casadi_int el = 0; el < dgradf_dx.nnz(); ++el) {
134  gradf_nlflag_[dg_row[el]] = 1;
135  }
136  has_linear_gradf_ = std::any_of(gradf_nlflag_.begin(), gradf_nlflag_.end(),
137  [](int f) { return f == 0; });
138  }
139 
140  const casadi_int* g_colind = jacg_sp_.colind();
141  const casadi_int* g_row = jacg_sp_.row();
142 
143  // Build row-indexed CSR structure over nonlinear entries for fast
144  // Jacobian scatter in cb_fd_eval
145  casadi_int nnz_g = jacg_sp_.nnz();
146  jacg_rowstart_.assign(ng_ + 1, 0);
147  for (casadi_int el = 0; el < nnz_g; ++el)
148  if (jacg_nlflag_[el]) jacg_rowstart_[g_row[el] + 1]++;
149  for (int r = 0; r < ng_; ++r)
150  jacg_rowstart_[r + 1] += jacg_rowstart_[r];
151  jacg_nzidx_.resize(jacg_rowstart_[ng_]);
152  jacg_col_.resize(jacg_rowstart_[ng_]);
153  std::vector<int> fill_pos(ng_, 0);
154  for (int c = 0; c < nx_; ++c) {
155  for (casadi_int el = g_colind[c]; el < g_colind[c+1]; ++el) {
156  if (!jacg_nlflag_[el]) continue;
157  int r = static_cast<int>(g_row[el]);
158  casadi_assert(fill_pos[r] < jacg_rowstart_[r + 1] - jacg_rowstart_[r],
159  "CSR fill overflow for row r - count/fill pass mismatch in jacg_rowstart_");
160  int pos = jacg_rowstart_[r] + fill_pos[r]++;
161  jacg_nzidx_[pos] = static_cast<int>(el);
162  jacg_col_[pos] = c;
163  }
164  }
165  }
void init(const Dict &opts) override
Initialize.
Definition: nlpsol.cpp:499

References casadi::Sparsity::colind(), casadi::conopt_max_option_name, casadi::OracleFunction::create_function(), debug_, exact_hessian_, gradf_col_flag_, gradf_col_to_nz_, gradf_nlflag_, gradf_sp_, has_linear_gradf_, has_linear_jac_, hesslag_sp_, casadi::Nlpsol::init(), jacg_col_, jacg_nlflag_, jacg_nzidx_, jacg_rowstart_, jacg_sp_, casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::Nlpsol::nx_, optfile_, opts_, casadi::Sparsity::row(), casadi::Function::sparsity_jac(), casadi::Function::sparsity_out(), casadi::str(), and warm_start_.

◆ init_mem()

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

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

Reimplemented from casadi::Nlpsol.

Definition at line 259 of file conopt_interface.cpp.

259  {
260  if (Nlpsol::init_mem(mem)) return 1;
261  auto m = static_cast<ConoptMemory*>(mem);
262 
263  m->cached_x.resize(nx_, 0.0);
264  m->cached_grad_f.resize(gradf_sp_.nnz(), 0.0);
265  m->cached_g.resize(ng_, 0.0);
266  m->cached_jac_g.resize(jacg_sp_.nnz(), 0.0);
267  m->casadi_to_conopt_lb_row.resize(ng_);
268  m->casadi_to_conopt_ub_row.assign(ng_, -1);
269  m->hess_lam_g_.resize(ng_, 0.0);
270  m->row_const_.assign(ng_, 0.0);
271  m->row_nnz.assign(ng_, 0);
272  // Every CasADi row contributes at least one entry (range constraints add a
273  // second), so ng_ is a guaranteed lower bound on the final size — reserving
274  // less would force a reallocation on essentially every solve. solve() grows
275  // these vectors further on demand only for the range-constraint rows.
276  casadi_int initial_row_reserve = ng_;
277  m->conopt_to_casadi.reserve(initial_row_reserve);
278  m->conopt_type.reserve(initial_row_reserve);
279  m->conopt_rhs.reserve(initial_row_reserve);
280  if (has_linear_jac_) {
281  m->const_jac_vals.resize(jacg_sp_.nnz(), 0.0);
282  }
283  m->linear_at_x0.resize(ng_, 0.0);
284  if (has_linear_gradf_)
285  m->gradf_const_vals.resize(gradf_sp_.nnz(), 0.0);
286 
287  if (COI_Create(&m->cntvect) != 0 || m->cntvect == nullptr) {
288  casadi::uerr() << "CONOPT: COI_Create failed" << std::endl;
289  return 1;
290  }
291 
292  if (warm_start_) COIDEF_IniStat(m->cntvect, 2);
293 
294  COIDEF_NumVar(m->cntvect, nx_);
295  // NumCon, NumNz, NumNlNz are set in solve() because range-constraint expansion
296  // can change them between calls.
297 
298  COIDEF_ObjCon(m->cntvect, 0);
299  COIDEF_OptDir(m->cntvect, -1);
300 
301  // Handle Options
302  m->custom_options.clear();
303  for (auto&& op : opts_) {
304  // Explictly catch C API options defined in conopt.h
305  if (op.first == "itlim") COIDEF_ItLim(m->cntvect, op.second.to_int());
306  else if (op.first == "errlim") COIDEF_ErrLim(m->cntvect, op.second.to_int());
307  else if (op.first == "reslim" || op.first == "timelim")
308  COIDEF_ResLim(m->cntvect, op.second.to_double());
309  else if (op.first == "maxheap") COIDEF_MaxHeap(m->cntvect, op.second.to_double());
310  else if (op.second.is_string()) {
311  casadi_warning("CONOPT option '" + op.first + "' is a string; string options cannot be "
312  "passed via the CONOPT option callback (no SVAL parameter). "
313  "Use the 'optfile' option instead.");
314  } else {
315  m->custom_options.push_back(op);
316  }
317  }
318  if (!optfile_.empty()) COIDEF_Optfile(m->cntvect, optfile_.c_str());
319  COIDEF_Option(m->cntvect, &ConoptInterface::cb_option);
320  COIDEF_Progress(m->cntvect, &ConoptInterface::cb_progress);
321 
322  // Register Callbacks
323  COIDEF_ReadMatrix(m->cntvect, &ConoptInterface::cb_read_matrix);
324  COIDEF_FDEvalIni(m->cntvect, &ConoptInterface::cb_fdevalini);
325  COIDEF_FDEval(m->cntvect, &ConoptInterface::cb_fd_eval);
326  COIDEF_FDEvalEnd(m->cntvect, &ConoptInterface::cb_fdevalend);
327 
328  if (exact_hessian_ && hesslag_sp_.nnz() > 0) {
329  COIDEF_NumHess(m->cntvect, hesslag_sp_.nnz());
330  COIDEF_2DLagrStr(m->cntvect, &ConoptInterface::cb_2dlagrstr);
331  COIDEF_2DLagrVal(m->cntvect, &ConoptInterface::cb_2dlagrval);
332  }
333 
334  COIDEF_FVincLin(m->cntvect, 1);
335 
336  COIDEF_Status(m->cntvect, &ConoptInterface::cb_status);
337  COIDEF_Solution(m->cntvect, &ConoptInterface::cb_solution);
338  COIDEF_Message(m->cntvect, &ConoptInterface::cb_message);
339  COIDEF_ErrMsg(m->cntvect, &ConoptInterface::cb_errmsg);
340  COIDEF_UsrMem(m->cntvect, m);
341 
342  return 0;
343  }
static int COI_CALLCONV cb_fdevalini(const double X[], const int ROWLIST[], int MODE, int LISTSIZE, int NUMTHREAD, int IGNERR, int *ERRCNT, int NUMVAR, void *USRMEM)
static int COI_CALLCONV cb_read_matrix(double LOWER[], double CURR[], double UPPER[], int VSTA[], int TYPEX[], double RHS[], int ESTA[], int COLSTA[], int ROWNO[], double VALUE[], int NLFLAG[], int NUMVAR, int NUMCON, int NUMNZ, void *USRMEM)
static int COI_CALLCONV cb_solution(const double XVAL[], const double XMAR[], const int XBAS[], const int XSTA[], const double YVAL[], const double YMAR[], const int YBAS[], const int YSTA[], int NUMVAR, int NUMCON, void *USRMEM)
static int COI_CALLCONV cb_fdevalend(int IGNERR, int *ERRCNT, void *USRMEM)
static int COI_CALLCONV cb_status(int MODSTA, int SOLSTA, int ITER, double OBJVAL, void *USRMEM)
static int COI_CALLCONV cb_progress(int LEN_INT, const int INTX[], int LEN_RL, const double RL[], const double X[], void *USRMEM)
static int COI_CALLCONV cb_2dlagrstr(int HSRW[], int HSCL[], int *NODRV, int NUMVAR, int NUMCON, int NHESS, void *USRMEM)
static int COI_CALLCONV cb_option(int NCALL, double *RVAL, int *IVAL, int *LVAL, char *NAME, void *USRMEM)
static int COI_CALLCONV cb_2dlagrval(const double X[], const double U[], const int HSRW[], const int HSCL[], double HSVL[], int *NODRV, int NUMVAR, int NUMCON, int NHESS, void *USRMEM)
static int COI_CALLCONV cb_message(int SMSG, int DMSG, int NMSG, char *MSGV[], void *USRMEM)
static int COI_CALLCONV cb_fd_eval(const double X[], double *G, double JAC[], int ROWNO, const int JACNUM[], int MODE, int IGNERR, int *ERRCNT, int NUMVAR, int NUMJAC, int THREAD, void *USRMEM)
static int COI_CALLCONV cb_errmsg(int ROWNO, int COLNO, int POSNO, const char *MSG, void *USRMEM)
int init_mem(void *mem) const override
Initalize memory block.
Definition: nlpsol.cpp:692

References casadi::ConoptMemory::cached_x, cb_2dlagrstr(), cb_2dlagrval(), cb_errmsg(), cb_fd_eval(), cb_fdevalend(), cb_fdevalini(), cb_message(), cb_option(), cb_progress(), cb_read_matrix(), cb_solution(), cb_status(), exact_hessian_, gradf_sp_, has_linear_gradf_, has_linear_jac_, hesslag_sp_, casadi::Nlpsol::init_mem(), jacg_sp_, casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::Nlpsol::nx_, optfile_, opts_, casadi::uerr(), and warm_start_.

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

◆ instantiate()

Nlpsol * casadi::PluginInterface< Nlpsol >::instantiate ( const std::string &  fname,
const std::string &  pname,
Problem  problem 
)
staticinherited

Definition at line 106 of file plugin_interface.hpp.

317  {
318 
319  // Assert the plugin exists (needed for adaptors)
320  if (!has_plugin(pname, true)) {
321  casadi_error("Plugin '" + pname + "' is not found.");
322  }
323  return getPlugin(pname).creator(fname, problem);
324  }
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.

◆ 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().

◆ integer_support()

virtual bool casadi::Nlpsol::integer_support ( ) const
inlinevirtualinherited

Reimplemented in casadi::KnitroInterface, and casadi::BonminInterface.

Definition at line 207 of file nlpsol_impl.hpp.

207 { return false;}

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

◆ is_a()

bool casadi::Nlpsol::is_a ( const std::string &  type,
bool  recursive 
) const
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 369 of file nlpsol.cpp.

369  {
370  return type=="Nlpsol" || (recursive && OracleFunction::is_a(type, recursive));
371  }
virtual bool is_a(const std::string &type, bool recursive) const
Check if the function is of a particular type.

References casadi::FunctionInternal::is_a().

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

◆ 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  }
const std::string & name() const
Name of the function.
Definition: function.cpp:1504

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  }
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()

void casadi::OracleFunction::jit_dependencies ( const std::string &  fname)
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 438 of file oracle_function.cpp.

438  {
439  if (compiler_.is_null()) {
440  if (verbose_) casadi_message("compiling to "+ fname+"'.");
441  // JIT dependent functions
442  compiler_ = Importer(generate_dependencies(fname, Dict()),
444  }
445  // Replace the Oracle functions with generated functions
446  for (auto&& e : all_functions_) {
447  if (verbose_) casadi_message("loading '" + e.second.f.name() + "' from '" + fname + "'.");
448  if (e.second.jit) {
449  e.second.f_original = e.second.f;
450  e.second.f = external(e.second.f.name(), compiler_);
451  }
452  }
453 }
std::string generate_dependencies(const std::string &fname, const Dict &opts) const override
Export / Generate C code for the generated functions.
Function external(const std::string &name, const Importer &li, const Dict &opts)
Load a just-in-time compiled external function.
Definition: external.cpp:42

References casadi::OracleFunction::all_functions_, casadi::FunctionInternal::compiler_, casadi::FunctionInternal::compiler_plugin_, casadi::external(), casadi::OracleFunction::generate_dependencies(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jit_options_, and casadi::ProtoFunction::verbose_.

◆ join_results()

void casadi::OracleFunction::join_results ( OracleMemory m) const
inherited

Definition at line 168 of file oracle_function.cpp.

168  {
169  // Combine runtime statistics
170  // Note: probably not correct to simply add wall times
171  for (int i = 0; i < max_num_threads_; ++i) {
172  auto* ml = m->thread_local_mem[i];
173  for (auto&& s : ml->fstats) {
174  m->fstats.at(s.first).join(s.second);
175  }
176  }
177 }

References casadi::ProtoFunctionMemory::fstats, casadi::OracleFunction::max_num_threads_, and casadi::OracleMemory::thread_local_mem.

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

◆ kkt()

Function casadi::Nlpsol::kkt ( ) const
inherited

Definition at line 936 of file nlpsol.cpp.

936  {
937 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
938  // Safe access to kkt_
939  std::lock_guard<std::mutex> lock(kkt_mtx_);
940 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
941  // Quick return if cached
942  SharedObject temp;
943  if (kkt_.shared_if_alive(temp)) {
944  return shared_cast<Function>(temp);
945  }
946 
947  // Generate KKT function
948  Function ret = oracle_.factory("kkt", {"x", "p", "lam:f", "lam:g"},
949  {"jac:g:x", "hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
950 
951  // Cache and return
952  kkt_ = ret;
953  return ret;
954  }
bool shared_if_alive(Shared &shared) const
Thread-safe alternative to alive()/shared()
WeakRef kkt_
Cache for KKT function.

References casadi::Function::factory(), casadi::Nlpsol::kkt_, casadi::OracleFunction::oracle_, and casadi::GenericWeakRef< Shared, Internal >::shared_if_alive().

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

◆ load_library()

handle_t casadi::PluginInterface< Nlpsol >::load_library ( const std::string &  libname,
std::string &  resultpath,
bool  global 
)
staticinherited

Definition at line 92 of file plugin_interface.hpp.

187  {
188 
189 #ifndef WITH_DL
190  casadi_error("WITH_DL option needed for dynamic loading");
191 #else // WITH_DL
192 
193  // Get the name of the shared library
194  std::string lib = std::string(CasadiMeta::shared_library_prefix()) + libname +
195  CasadiMeta::shared_library_suffix();
196 
197  // Build up search paths;
198  std::vector<std::string> search_paths = get_search_paths();
199  return open_shared_library(lib, search_paths, resultpath,
200  "PluginInterface::load_plugin", global);
201 
202 #endif // WITH_DL
203  }
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:79

◆ load_plugin()

PluginInterface< Nlpsol >::Plugin casadi::PluginInterface< Nlpsol >::load_plugin ( const std::string &  pname,
bool  register_plugin = true,
bool  needs_lock = true 
)
staticinherited

Definition at line 88 of file plugin_interface.hpp.

208  {
209 
210 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
211  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
212 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
213 
214  // Issue warning and quick return if already loaded
215  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
216  casadi_warning("PluginInterface: Solver " + pname + " is already in use. Ignored.");
217  return Plugin();
218  }
219 
220  // Logger singletons are lazily instantiated on first uout()/uerr() calls
221  // This instantation may lead to a data race with potential instatiations in plugin
222  // To be safe, trigger instantatin before any plugin loading
223  uout();
224  uerr();
225 
226 #ifndef WITH_DL
227  casadi_error("WITH_DL option needed for dynamic loading");
228 #else // WITH_DL
229  // Retrieve the registration function
230  RegFcn reg;
231 
232  // Load the dll
233  std::string regName = "casadi_register_" + Derived::infix_ + "_" + pname;
234 
235  std::string searchpath;
236  handle_t handle = load_library("casadi_" + Derived::infix_ + "_" + pname, searchpath,
237  false);
238 
239 #ifdef _WIN32
240 
241 #if __GNUC__
242 #pragma GCC diagnostic push
243 #pragma GCC diagnostic ignored "-Wcast-function-type"
244 #endif
245  reg = reinterpret_cast<RegFcn>(GetProcAddress(handle, TEXT(regName.c_str())));
246 #if __GNUC__
247 #pragma GCC diagnostic pop
248 #endif
249 
250 #else // _WIN32
251  // Reset error
252  dlerror();
253 
254  // Load creator
255  reg = reinterpret_cast<RegFcn>(dlsym(handle, regName.c_str()));
256 #endif // _WIN32
257  casadi_assert(reg!=nullptr,
258  "PluginInterface::load_plugin: no \"" + regName + "\" found in " + searchpath + ".");
259 
260  // Create a temporary struct
261  Plugin plugin = pluginFromRegFcn(reg);
262  // Register the plugin
263  if (register_plugin) {
264  registerPlugin(plugin, false);
265  }
266 
267  return plugin;
268 
269 #endif // WITH_DL
270  }
static handle_t load_library(const std::string &libname, std::string &resultpath, bool global)
Load a library dynamically.
static Plugin pluginFromRegFcn(RegFcn regfcn)
Instantiate a Plugin struct from a factory function.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void * handle_t
Definition: casadi_os.hpp:109

◆ local_init_mem()

int casadi::OracleFunction::local_init_mem ( void *  mem) const
inherited

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

Definition at line 465 of file oracle_function.cpp.

465  {
466  if (ProtoFunction::init_mem(mem)) return 1;
467  if (!mem) return 1;
468  auto *m = static_cast<LocalOracleMemory*>(mem);
469 
470  // Create statistics
471  for (auto&& e : all_functions_) {
472  m->add_stat(e.first);
473  }
474 
475  return 0;
476 }

References casadi::ProtoFunctionMemory::add_stat(), casadi::OracleFunction::all_functions_, and casadi::ProtoFunction::init_mem().

Referenced by casadi::OracleFunction::init_mem().

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

◆ monitored()

bool casadi::OracleFunction::monitored ( const std::string &  name) const
virtualinherited

Definition at line 557 of file oracle_function.cpp.

557  {
558  auto it = all_functions_.find(name);
559  casadi_assert(it!=all_functions_.end(),
560  "No function \"" + name + "\" in " + name_+ ". " +
561  "Available functions: " + join(get_function()) + ".");
562  return it->second.monitored;
563 }

References casadi::OracleFunction::all_functions_, casadi::OracleFunction::get_function(), casadi::join(), and casadi::ProtoFunction::name_.

Referenced by casadi::OracleFunction::calc_function().

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

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

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

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(), casadi::FmuFunction::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  }

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::OracleFunction::oracle ( ) const
inlineoverridevirtualinherited

◆ plugin_deserialize()

Deserialize casadi::PluginInterface< Nlpsol >::plugin_deserialize ( const std::string &  pname)
staticinherited

Definition at line 82 of file plugin_interface.hpp.

165  {
166  Deserialize m = getPlugin(pname).deserialize;
167  casadi_assert(m, "Plugin \"" + pname + "\" does not support deserialize");
168  return m;
169  }
ProtoFunction *(* Deserialize)(DeserializingStream &)

◆ plugin_name()

const char* casadi::ConoptInterface::plugin_name ( ) const
inlineoverridevirtual

Implements casadi::PluginInterface< Nlpsol >.

Definition at line 144 of file conopt_interface.hpp.

144 { return "conopt"; }

◆ plugin_options()

const Options & casadi::PluginInterface< Nlpsol >::plugin_options ( const std::string &  pname)
staticinherited

Definition at line 79 of file plugin_interface.hpp.

158  {
159  const Options *op = getPlugin(pname).options;
160  casadi_assert(op!=nullptr, "Plugin \"" + pname + "\" does not support options");
161  return *op;
162  }

◆ pluginFromRegFcn()

PluginInterface< Nlpsol >::Plugin casadi::PluginInterface< Nlpsol >::pluginFromRegFcn ( RegFcn  regfcn)
staticinherited

Definition at line 85 of file plugin_interface.hpp.

173  {
174  // Create a temporary struct
175  Plugin plugin;
176 
177  // Set the fields
178  int flag = regfcn(&plugin);
179  casadi_assert(flag==0, "Registration of plugin failed.");
180 
181  return plugin;
182  }

◆ 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(), casadi::FmuFunction::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().

◆ registerPlugin() [1/2]

void casadi::PluginInterface< Nlpsol >::registerPlugin ( const Plugin &  plugin,
bool  needs_lock = true 
)
staticinherited

Definition at line 96 of file plugin_interface.hpp.

278  {
279 
280 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
281  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
282 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
283 
284  // Check if the solver name is in use
285  typename std::map<std::string, Plugin>::iterator it=Derived::solvers_.find(plugin.name);
286  casadi_assert(it==Derived::solvers_.end(),
287  "Solver " + str(plugin.name) + " is already in use");
288 
289  // Add to list of solvers
290  Derived::solvers_[plugin.name] = plugin;
291  }

◆ registerPlugin() [2/2]

void casadi::PluginInterface< Nlpsol >::registerPlugin ( RegFcn  regfcn,
bool  needs_lock = true 
)
staticinherited

Definition at line 99 of file plugin_interface.hpp.

273  {
274  registerPlugin(pluginFromRegFcn(regfcn), needs_lock);
275  }

◆ 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()

std::string casadi::Nlpsol::serialize_base_function ( ) const
inlineoverridevirtualinherited

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

Reimplemented from casadi::ProtoFunction.

Definition at line 133 of file nlpsol_impl.hpp.

133 { return "Nlpsol"; }

◆ serialize_body()

void casadi::ConoptInterface::serialize_body ( SerializingStream s) const
overridevirtual

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

Reimplemented from casadi::Nlpsol.

Definition at line 232 of file conopt_interface.cpp.

232  {
234  s.version("ConoptInterface", 1);
235  s.pack("ConoptInterface::exact_hessian", exact_hessian_);
236  s.pack("ConoptInterface::opts", opts_);
237  s.pack("ConoptInterface::gradf_sp", gradf_sp_);
238  s.pack("ConoptInterface::jacg_sp", jacg_sp_);
239  s.pack("ConoptInterface::hesslag_sp", hesslag_sp_);
240  s.pack("ConoptInterface::optfile", optfile_);
241  s.pack("ConoptInterface::warm_start", warm_start_);
242  s.pack("ConoptInterface::debug", debug_);
243  // Derived arrays (gradf_col_flag_, CSR) are rebuilt on deserialization
244  }
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Definition: nlpsol.cpp:1409

References debug_, exact_hessian_, gradf_sp_, hesslag_sp_, jacg_sp_, optfile_, opts_, casadi::SerializingStream::pack(), casadi::Nlpsol::serialize_body(), casadi::SerializingStream::version(), and warm_start_.

◆ serialize_type()

void casadi::Nlpsol::serialize_type ( SerializingStream s) const
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 1439 of file nlpsol.cpp.

1439  {
1442  }
void serialize_type(SerializingStream &s) const override
Serialize type information.
void serialize_type(SerializingStream &s) const
Serialize type information.

References casadi::PluginInterface< Derived >::serialize_type(), and casadi::FunctionInternal::serialize_type().

◆ set_function() [1/2]

void casadi::OracleFunction::set_function ( const Function fcn)
inlineinherited

Register the function for evaluation and statistics gathering

Definition at line 183 of file oracle_function.hpp.

183 { set_function(fcn, fcn.name()); }

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

Referenced by casadi::OracleFunction::set_function().

◆ set_function() [2/2]

void casadi::OracleFunction::set_function ( const Function fcn,
const std::string &  fname,
bool  jit = false 
)
inherited

◆ 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()

void casadi::OracleFunction::set_temp ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
overridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 505 of file oracle_function.cpp.

506  {
507 
508  auto *m = static_cast<OracleMemory*>(mem);
509  m->arg = arg;
510  m->res = res;
511  m->iw = iw;
512  m->w = w;
513  m->d_oracle.arg = arg;
514  m->d_oracle.res = res;
515  m->d_oracle.iw = iw;
516  m->d_oracle.w = w;
517  for (int i = 0; i < max_num_threads_; ++i) {
518  auto* ml = m->thread_local_mem[i];
519  for (auto&& s : ml->fstats) s.second.reset();
520  ml->arg = arg;
521  ml->res = res;
522  ml->iw = iw;
523  ml->w = w;
524  arg += stride_arg_;
525  res += stride_res_;
526  iw += stride_iw_;
527  w += stride_w_;
528  }
529 }

References casadi::OracleMemory::arg, casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::stride_arg_, casadi::OracleFunction::stride_iw_, casadi::OracleFunction::stride_res_, and casadi::OracleFunction::stride_w_.

◆ set_work()

void casadi::ConoptInterface::set_work ( void *  mem,
const double **&  arg,
double **&  res,
casadi_int *&  iw,
double *&  w 
) const
overridevirtual

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

Reimplemented from casadi::Nlpsol.

Definition at line 345 of file conopt_interface.cpp.

346  {
347  Nlpsol::set_work(mem, arg, res, iw, w);
348  }
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
Definition: nlpsol.cpp:884

References casadi::Nlpsol::set_work().

◆ setOptionsFromFile()

void casadi::Nlpsol::setOptionsFromFile ( const std::string &  file)
virtualinherited

Definition at line 763 of file nlpsol.cpp.

763  {
764  casadi_error("setOptionsFromFile not defined for class " + class_name());
765  }

References casadi::Nlpsol::class_name().

◆ 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(), casadi::FmuFunction::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  }

◆ shortname()

static std::string casadi::Nlpsol::shortname ( )
inlinestaticinherited

Definition at line 312 of file nlpsol_impl.hpp.

312 { return "nlpsol";}

◆ 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().

◆ solve()

int casadi::ConoptInterface::solve ( void *  mem) const
overridevirtual

Implements casadi::Nlpsol.

Definition at line 365 of file conopt_interface.cpp.

365  {
366  auto m = static_cast<ConoptMemory*>(mem);
367  m->cache_valid = false;
368  m->cache_valid_jac = false;
369  m->cached_f = 0.0;
370  m->nan_encountered = false;
371  m->modsta = ConoptModelStatus::Unset;
372  m->solsta = ConoptSolverStatus::Unset;
373  m->iter = 0;
374  m->return_status = "Unset";
375 
376  // Build the per-solve constraint expansion (splits range constraints into two rows)
377  std::fill(m->row_const_.begin(), m->row_const_.end(), 0.0);
378  m->obj_const_lin_ = 0.0;
379  m->conopt_to_casadi.clear();
380  m->casadi_to_conopt_ub_row.assign(ng_, -1);
381  m->conopt_type.clear();
382  m->conopt_rhs.clear();
383 
384  // Compute total nnz per CasADi row (needed for range-constraint NZ duplication)
385  std::fill(m->row_nnz.begin(), m->row_nnz.end(), 0);
386  {
387  const casadi_int* g_row_s = jacg_sp_.row();
388  for (casadi_int el = 0; el < (casadi_int)jacg_sp_.nnz(); ++el)
389  m->row_nnz[g_row_s[el]]++;
390  }
391 
392  casadi_int ng_expanded = 0;
393  // Objective gradient NZs are added to numnz after nlp_grad_f is evaluated
394  // (so that gradf_const_vals is populated before we check for non-zero linear entries).
395  casadi_int numnz = (casadi_int)jacg_sp_.nnz();
396 
397  for (casadi_int i = 0; i < ng_; ++i) {
398  double lbg = m->d_nlp.lbz[nx_ + i];
399  double ubg = m->d_nlp.ubz[nx_ + i];
400  bool is_range = !std::isinf(lbg) && !std::isinf(ubg) && lbg != ubg;
401 
402  // CONOPT row 0 is reserved for the objective, so constraint rows start at 1
403  // (arrays are still plain 0-based C arrays; only the row *numbering* is offset).
404  m->casadi_to_conopt_lb_row[i] = static_cast<int>(ng_expanded + 1);
405  ensure_row_capacity(m, ng_ - i);
406  m->conopt_to_casadi.push_back(static_cast<int>(i));
407  if (lbg == ubg) {
408  m->conopt_type.push_back(ConoptRowType::Equality); m->conopt_rhs.push_back(lbg);
409  } else if (!std::isinf(lbg) && std::isinf(ubg)) {
410  m->conopt_type.push_back(ConoptRowType::GreaterEqual); m->conopt_rhs.push_back(lbg);
411  } else if (std::isinf(lbg) && !std::isinf(ubg)) {
412  m->conopt_type.push_back(ConoptRowType::LessEqual); m->conopt_rhs.push_back(ubg);
413  } else if (std::isinf(lbg) && std::isinf(ubg)) {
414  m->conopt_type.push_back(ConoptRowType::Free); m->conopt_rhs.push_back(0.0);
415  } else {
416  // range: >= row
417  m->conopt_type.push_back(ConoptRowType::GreaterEqual);
418  m->conopt_rhs.push_back(lbg);
419  }
420  ng_expanded++;
421 
422  if (is_range) {
423  m->casadi_to_conopt_ub_row[i] = static_cast<int>(ng_expanded + 1);
424  ensure_row_capacity(m, ng_ - i);
425  m->conopt_to_casadi.push_back(static_cast<int>(i)); // <= row
426  m->conopt_type.push_back(ConoptRowType::LessEqual);
427  m->conopt_rhs.push_back(ubg);
428  ng_expanded++;
429  numnz += m->row_nnz[i];
430  }
431  }
432  casadi_assert(ng_expanded <= std::numeric_limits<int>::max(), "ng_expanded overflows int");
433  m->ng_expanded = static_cast<int>(ng_expanded);
434 
435  // Empty Jacobian rows also need their constant terms moved into the RHS.
436  bool has_affine_g = has_linear_jac_ ||
437  std::any_of(m->row_nnz.begin(), m->row_nnz.end(), [](int n) { return n == 0; });
438  if (has_affine_g) {
439  m->arg[0] = m->d_nlp.z;
440  m->arg[1] = m->d_nlp.p;
441  m->res[0] = m->cached_g.data();
442  m->res[1] = has_linear_jac_ ? m->const_jac_vals.data() : nullptr;
443  try {
444  if (calc_function(m, "nlp_jac_g")) {
445  m->success = false;
446  m->unified_return_status = SOLVER_RET_NAN;
447  m->return_status = "Initial evaluation failed";
448  return 0;
449  }
450  } catch (std::exception& ex) {
451  casadi::uerr() << "CONOPT: initial evaluation failed: " << ex.what() << std::endl;
452  return 1;
453  } catch (...) {
454  casadi::uerr() << "CONOPT: initial evaluation failed (unknown exception)" << std::endl;
455  return 1;
456  }
457  }
458 
459  // CONOPT evaluates affine rows internally; absorb their constants into the RHS.
460  if (has_affine_g) {
461  const casadi_int* g_colind_c = jacg_sp_.colind();
462  const casadi_int* g_row_c = jacg_sp_.row();
463 
464  // Accumulate the linear part of G at x0 per row: sum_j a_j * x0_j
465  std::fill(m->linear_at_x0.begin(), m->linear_at_x0.end(), 0.0);
466  for (int c = 0; c < nx_; ++c) {
467  for (casadi_int el = g_colind_c[c]; el < g_colind_c[c + 1]; ++el) {
468  if (jacg_nlflag_[el] == 0)
469  m->linear_at_x0[g_row_c[el]] += m->const_jac_vals[el] * m->d_nlp.z[c];
470  }
471  }
472 
473  for (int ci = 0; ci < ng_; ++ci) {
474  // Only adjust fully linear rows (no nonlinear Jacobian entries)
475  if (jacg_rowstart_[ci + 1] != jacg_rowstart_[ci]) continue;
476  double constant = m->cached_g[ci] - m->linear_at_x0[ci];
477  if (std::abs(constant) < 1e-14) continue;
478  m->row_const_[ci] = constant;
479  int lb_row = m->casadi_to_conopt_lb_row[ci];
480  m->conopt_rhs[lb_row - 1] -= constant;
481  int ub_row = m->casadi_to_conopt_ub_row[ci];
482  if (ub_row >= 0) m->conopt_rhs[ub_row - 1] -= constant;
483  }
484  }
485 
486  // Evaluate objective gradient at initial point for constant (linear) entries,
487  // or to capture the function value when the gradient is structurally empty.
488  m->obj_const_ = std::numeric_limits<double>::quiet_NaN();
489  if (has_linear_gradf_ || gradf_sp_.nnz() == 0) {
490  m->arg[0] = m->d_nlp.z;
491  m->arg[1] = m->d_nlp.p;
492  m->res[0] = &m->cached_f;
493  m->res[1] = has_linear_gradf_ ? m->gradf_const_vals.data() : nullptr;
494  try {
495  if (calc_function(m, "nlp_grad_f")) {
496  m->success = false;
497  m->unified_return_status = SOLVER_RET_NAN;
498  m->return_status = "Initial evaluation failed";
499  return 0;
500  }
501  } catch (std::exception& ex) {
502  casadi::uerr() << "CONOPT: initial evaluation failed: " << ex.what() << std::endl;
503  return 1;
504  } catch (...) {
505  casadi::uerr() << "CONOPT: initial evaluation failed (unknown exception)" << std::endl;
506  return 1;
507  }
508  }
509 
510  // Detect constant objective at solve time: no nonlinear gradient entries and
511  // all linear-gradient values are zero (objective has no x-dependence).
512  // Switch to feasibility mode so CONOPT doesn't report OBJVAL=0 for an empty row.
513  {
514  bool has_nl_gradf = std::any_of(gradf_nlflag_.begin(), gradf_nlflag_.end(),
515  [](int f) { return f == 1; });
516  bool all_const_zero = has_linear_gradf_ &&
517  std::all_of(m->gradf_const_vals.begin(), m->gradf_const_vals.end(),
518  [](double v) { return v == 0.0; });
519  if (!has_nl_gradf && (gradf_sp_.nnz() == 0 || all_const_zero)) {
520  m->obj_const_ = m->cached_f;
521  COIDEF_OptDir(m->cntvect, 0);
522  } else {
523  if (!has_nl_gradf) {
524  // CONOPT omits the affine objective's constant term; recover it at x0.
525  const casadi_int* f_row_c = gradf_sp_.row();
526  double lin_at_x0 = 0.0;
527  for (casadi_int k = 0; k < gradf_sp_.nnz(); ++k)
528  lin_at_x0 += m->gradf_const_vals[k] * m->d_nlp.z[f_row_c[k]];
529  m->obj_const_lin_ = m->cached_f - lin_at_x0;
530  }
531  // cntvect persists across solves, so explicitly reset OptDir in case a
532  // prior solve on this instance (e.g. with different parameters) hit the
533  // constant-objective branch above and left it at 0.
534  COIDEF_OptDir(m->cntvect, -1);
535  }
536  }
537 
538  // Count nonlinear NZ: nonlinear objective gradient entries + nonlinear constraint entries
539  const casadi_int* g_colind_s = jacg_sp_.colind();
540  const casadi_int* g_row_s = jacg_sp_.row();
541  casadi_int num_nl_nz = 0;
542  for (casadi_int k = 0; k < (casadi_int)gradf_sp_.nnz(); ++k)
543  if (gradf_nlflag_[k]) num_nl_nz++;
544  for (casadi_int c = 0; c < nx_; ++c) {
545  for (casadi_int el = g_colind_s[c]; el < g_colind_s[c+1]; ++el) {
546  if (jacg_nlflag_[el]) {
547  int ci = static_cast<int>(g_row_s[el]);
548  num_nl_nz += (m->casadi_to_conopt_ub_row[ci] >= 0) ? 2 : 1;
549  }
550  }
551  }
552 
553  casadi_assert(num_nl_nz <= std::numeric_limits<int>::max(), "num_nl_nz overflows int");
554 
555  // Count objective gradient NZs now that gradf_const_vals has been populated.
556  // Nonlinear entries are always included; linear (constant) entries only when
557  // non-zero — a zero constant gradient contributes nothing to the objective row
558  // and must not occupy a slot in the CONOPT matrix structure.
559  {
560  casadi_int numnz_f = 0;
561  for (casadi_int k = 0; k < (casadi_int)gradf_sp_.nnz(); ++k) {
562  if (gradf_nlflag_[k] == 1 ||
563  (has_linear_gradf_ && m->gradf_const_vals[k] != 0.0))
564  numnz_f++;
565  }
566  numnz += numnz_f;
567  }
568  casadi_assert(numnz <= std::numeric_limits<int>::max(), "numnz overflows int");
569  m->numnz_expanded = static_cast<int>(numnz);
570 
571  COIDEF_NumCon(m->cntvect, static_cast<int>(ng_expanded + 1));
572  COIDEF_NumNz(m->cntvect, static_cast<int>(numnz));
573  COIDEF_NumNlNz(m->cntvect, static_cast<int>(num_nl_nz));
574 
575  int ret = COI_Solve(m->cntvect);
576 
577  // Restore the affine objective's constant term (cb_status only saw grad'x).
578  m->d_nlp.objective += m->obj_const_lin_;
579 
580  // Restore constant objective value when CONOPT ran in feasibility mode.
581  if (!std::isnan(m->obj_const_)) m->d_nlp.objective = m->obj_const_;
582 
583  if (ret != 0) {
584  m->success = false;
585  m->unified_return_status = m->nan_encountered ? SOLVER_RET_NAN : SOLVER_RET_UNKNOWN;
586  return 0;
587  }
588 
589  m->success = !m->nan_encountered &&
590  (m->modsta == ConoptModelStatus::Optimal ||
591  m->modsta == ConoptModelStatus::LocallyOptimal) &&
593 
594  if (m->nan_encountered || m->solsta == ConoptSolverStatus::EvalErrorLimit) {
595  m->unified_return_status = SOLVER_RET_NAN;
596  } else if (m->success) {
597  m->unified_return_status = SOLVER_RET_SUCCESS;
598  } else {
599  if (m->solsta == ConoptSolverStatus::IterationLimit ||
600  m->solsta == ConoptSolverStatus::TimeLimit ||
601  m->solsta == ConoptSolverStatus::UserInterrupt ||
603  m->unified_return_status = SOLVER_RET_LIMITED;
604  } else if (m->modsta == ConoptModelStatus::Infeasible ||
606  m->unified_return_status = SOLVER_RET_INFEASIBLE;
607  }
608  }
609  return 0;
610  }
void ensure_row_capacity(ConoptMemory *m, casadi_int remaining_rows) const
bool is_range(const std::vector< casadi_int > &v, casadi_int start, casadi_int stop, casadi_int step)
Check if a vector matches a range.
Definition: casadi_misc.cpp:95
@ SOLVER_RET_NAN
@ SOLVER_RET_INFEASIBLE
@ SOLVER_RET_LIMITED
@ SOLVER_RET_UNKNOWN

References casadi::ConoptMemory::cache_valid, casadi::OracleFunction::calc_function(), casadi::Sparsity::colind(), ensure_row_capacity(), casadi::Equality, casadi::EvalErrorLimit, casadi::Free, gradf_nlflag_, gradf_sp_, casadi::GreaterEqual, has_linear_gradf_, has_linear_jac_, casadi::Infeasible, casadi::is_range(), casadi::IterationLimit, jacg_nlflag_, jacg_rowstart_, jacg_sp_, casadi::LessEqual, casadi::LocallyInfeasible, casadi::LocallyOptimal, casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::NormalCompletion, casadi::Nlpsol::nx_, casadi::Optimal, casadi::QuickModeTermination, casadi::Sparsity::row(), casadi::SOLVER_RET_INFEASIBLE, casadi::SOLVER_RET_LIMITED, casadi::SOLVER_RET_NAN, casadi::SOLVER_RET_SUCCESS, casadi::SOLVER_RET_UNKNOWN, casadi::TimeLimit, casadi::uerr(), casadi::Unset, and casadi::UserInterrupt.

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

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()

bool casadi::Nlpsol::uses_output ( ) const
inlineoverridevirtualinherited

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

Reimplemented from casadi::FunctionInternal.

Definition at line 258 of file nlpsol_impl.hpp.

258 {return true;}

◆ 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

◆ ad_weight_

double casadi::FunctionInternal::ad_weight_
inherited

◆ ad_weight_sp_

double casadi::FunctionInternal::ad_weight_sp_
inherited

◆ all_functions_

std::map<std::string, RegFun> casadi::OracleFunction::all_functions_
protectedinherited

◆ always_inline_

bool casadi::FunctionInternal::always_inline_
inherited

◆ bound_consistency_

bool casadi::Nlpsol::bound_consistency_
inherited

◆ cache_

WeakCache<std::string, Function> casadi::FunctionInternal::cache_
mutableinherited

◆ cache_init_

Dict casadi::FunctionInternal::cache_init_
inherited

◆ calc_f_

bool casadi::Nlpsol::calc_f_
inherited

◆ calc_g_

bool casadi::Nlpsol::calc_g_
inherited

◆ calc_lam_p_

bool casadi::Nlpsol::calc_lam_p_
inherited

◆ calc_lam_x_

bool casadi::Nlpsol::calc_lam_x_
inherited

◆ calc_multipliers_

bool casadi::Nlpsol::calc_multipliers_
inherited

◆ callback_step_

casadi_int casadi::Nlpsol::callback_step_
inherited

◆ checkout_

casadi_checkout_t casadi::FunctionInternal::checkout_
inherited

◆ common_options_

Dict casadi::OracleFunction::common_options_
protectedinherited

◆ compiler_

Importer casadi::FunctionInternal::compiler_
inherited

◆ compiler_plugin_

std::string casadi::FunctionInternal::compiler_plugin_
inherited

◆ custom_jacobian_

Function casadi::FunctionInternal::custom_jacobian_
inherited

◆ debug_

bool casadi::ConoptInterface::debug_

◆ 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().

◆ detect_simple_bounds_is_simple_

std::vector<char> casadi::Nlpsol::detect_simple_bounds_is_simple_
inherited

◆ detect_simple_bounds_parts_

Function casadi::Nlpsol::detect_simple_bounds_parts_
inherited

◆ detect_simple_bounds_target_g_

std::vector<casadi_int> casadi::Nlpsol::detect_simple_bounds_target_g_
inherited

◆ detect_simple_bounds_target_x_

std::vector<casadi_int> casadi::Nlpsol::detect_simple_bounds_target_x_
inherited

◆ discrete_

std::vector<bool> casadi::Nlpsol::discrete_
inherited

◆ 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_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_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

◆ equality_

std::vector<bool> casadi::Nlpsol::equality_
inherited

◆ error_on_fail_

bool casadi::ProtoFunction::error_on_fail_
inherited

◆ eval_

eval_t casadi::FunctionInternal::eval_
inherited

◆ eval_errors_fatal_

bool casadi::Nlpsol::eval_errors_fatal_
inherited

◆ exact_hessian_

bool casadi::ConoptInterface::exact_hessian_

Definition at line 174 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), and serialize_body().

◆ fcallback_

Function casadi::Nlpsol::fcallback_
inherited

◆ 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

◆ forward_options_

Dict casadi::FunctionInternal::forward_options_
inherited

◆ gradf_col_flag_

std::vector<bool> casadi::ConoptInterface::gradf_col_flag_

Definition at line 181 of file conopt_interface.hpp.

Referenced by cb_read_matrix(), ConoptInterface(), and init().

◆ gradf_col_to_nz_

std::vector<casadi_int> casadi::ConoptInterface::gradf_col_to_nz_

Definition at line 196 of file conopt_interface.hpp.

Referenced by ConoptInterface(), and init().

◆ gradf_nlflag_

std::vector<int> casadi::ConoptInterface::gradf_nlflag_

Definition at line 193 of file conopt_interface.hpp.

Referenced by cb_fd_eval(), cb_read_matrix(), ConoptInterface(), init(), and solve().

◆ gradf_sp_

Sparsity casadi::ConoptInterface::gradf_sp_

Definition at line 171 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), serialize_body(), and solve().

◆ has_linear_gradf_

bool casadi::ConoptInterface::has_linear_gradf_

Definition at line 194 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), and solve().

◆ has_linear_jac_

bool casadi::ConoptInterface::has_linear_jac_

Definition at line 190 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), and solve().

◆ has_refcount_

bool casadi::FunctionInternal::has_refcount_
inherited

◆ has_refcount_in_deps_

bool casadi::FunctionInternal::has_refcount_in_deps_
inherited

◆ hesslag_sp_

Sparsity casadi::ConoptInterface::hesslag_sp_

Definition at line 173 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), and serialize_body().

◆ incref_

signal_t casadi::FunctionInternal::incref_
inherited

◆ infix_

const std::string casadi::Nlpsol::infix_ = "nlpsol"
staticinherited

Definition at line 309 of file nlpsol_impl.hpp.

◆ 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

◆ iteration_callback_ignore_errors_

bool casadi::Nlpsol::iteration_callback_ignore_errors_
inherited

◆ jac_penalty_

double casadi::FunctionInternal::jac_penalty_
inherited

◆ jac_sparsity_

std::vector<Sparsity> casadi::FunctionInternal::jac_sparsity_[2]
mutableinherited

◆ jacg_col_

std::vector<int> casadi::ConoptInterface::jacg_col_

Definition at line 186 of file conopt_interface.hpp.

Referenced by ConoptInterface(), and init().

◆ jacg_nlflag_

std::vector<int> casadi::ConoptInterface::jacg_nlflag_

Definition at line 189 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), and solve().

◆ jacg_nzidx_

std::vector<int> casadi::ConoptInterface::jacg_nzidx_

Definition at line 185 of file conopt_interface.hpp.

Referenced by ConoptInterface(), and init().

◆ jacg_rowstart_

std::vector<int> casadi::ConoptInterface::jacg_rowstart_

Definition at line 184 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), and solve().

◆ jacg_sp_

Sparsity casadi::ConoptInterface::jacg_sp_

Definition at line 172 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), serialize_body(), and solve().

◆ 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

◆ kkt_

WeakRef casadi::Nlpsol::kkt_
mutableinherited

Definition at line 109 of file nlpsol_impl.hpp.

Referenced by casadi::Nlpsol::kkt().

◆ max_io_

casadi_int casadi::FunctionInternal::max_io_
inherited

◆ max_num_dir_

casadi_int casadi::FunctionInternal::max_num_dir_
inherited

◆ max_num_threads_

int casadi::OracleFunction::max_num_threads_
protectedinherited

◆ meta_doc

const std::string casadi::ConoptInterface::meta_doc
static

Definition at line 155 of file conopt_interface.hpp.

Referenced by casadi::casadi_register_nlpsol_conopt().

◆ mi_

bool casadi::Nlpsol::mi_
inherited

◆ min_lam_

double casadi::Nlpsol::min_lam_
inherited

◆ monitor_

std::vector<std::string> casadi::OracleFunction::monitor_
protectedinherited

◆ 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(), casadi::FmuFunction::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(), casadi::FmuFunction::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(), casadi::FmuFunction::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(), casadi::FmuFunction::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().

◆ 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(), casadi::FmuFunction::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

◆ ng_

casadi_int casadi::Nlpsol::ng_
inherited

Definition at line 69 of file nlpsol_impl.hpp.

Referenced by casadi::Blocksqp::acceptStep(), casadi::AlpaqaProblem::AlpaqaProblem(), casadi::BonminUserClass::BonminUserClass(), casadi::Blocksqp::calcOptTol(), cb_read_matrix(), casadi::Feasiblesqpmethod::codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Feasiblesqpmethod::codegen_feasibility_iterations(), casadi::Nlpsol::codegen_post_solve(), casadi::Sqpmethod::codegen_qp_ela_solve(), casadi::Nlpsol::codegen_setup_constants(), casadi::Nlpsol::codegen_setup_per_call(), casadi::Sqpmethod::codegen_solve_elastic_mode(), casadi::Feasiblesqpmethod::codegen_step_update(), ConoptInterface(), casadi::Nlpsol::eval(), casadi::Scpgen::eval_vec(), casadi::Blocksqp::evaluate(), casadi::Feasiblesqpmethod::feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::IpoptUserClass::finalize_metadata(), casadi::BonminInterface::finalize_solution(), casadi::IpoptInterface::finalize_solution(), casadi::BonminInterface::get_bounds_info(), casadi::BonminUserClass::get_bounds_info(), casadi::IpoptUserClass::get_bounds_info(), casadi::IpoptInterface::get_bounds_info(), casadi::Nlpsol::get_forward(), casadi::BonminInterface::get_nlp_info(), casadi::IpoptInterface::get_nlp_info(), casadi::Nlpsol::get_reverse(), casadi::BonminInterface::get_starting_point(), casadi::BonminUserClass::get_starting_point(), casadi::IpoptUserClass::get_starting_point(), casadi::IpoptInterface::get_starting_point(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::AmplInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::UnoInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), init_mem(), casadi::IpoptInterface::init_mem(), casadi::SnoptInterface::init_mem(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::IpoptUserClass::IpoptUserClass(), casadi::Blocksqp::kktErrorReduction(), casadi::Scpgen::line_search(), casadi::Blocksqp::lInfConstraintNorm(), casadi::Nlpsol::Nlpsol(), casadi::Scpgen::primalInfeasibility(), casadi::Blocksqp::reduceSOCStepsize(), casadi::Blocksqp::reset_sqp(), casadi::Blocksqp::secondOrderCorrection(), casadi::Nlpsol::serialize_body(), casadi::Blocksqp::set_work(), casadi::BonminInterface::set_work(), casadi::IpoptInterface::set_work(), casadi::KnitroInterface::set_work(), casadi::SLEQPInterface::set_work(), casadi::SnoptInterface::set_work(), casadi::WorhpInterface::set_work(), casadi::Qrsqp::set_work(), casadi::Scpgen::set_work(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::Blocksqp::solve(), casadi::BonminInterface::solve(), solve(), casadi::IpoptInterface::solve(), casadi::KnitroInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), casadi::Feasiblesqpmethod::solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Sqpmethod::solve_elastic_mode(), casadi::Scpgen::solve_qp(), casadi::Blocksqp::solveQP(), casadi::Feasiblesqpmethod::step_update(), casadi::UnoInterface::UnoInterface(), and casadi::Blocksqp::updateStepBounds().

◆ no_nlp_grad_

bool casadi::Nlpsol::no_nlp_grad_
inherited

◆ np_

casadi_int casadi::Nlpsol::np_
inherited

◆ nx_

casadi_int casadi::Nlpsol::nx_
inherited

Definition at line 66 of file nlpsol_impl.hpp.

Referenced by casadi::Blocksqp::acceptStep(), casadi::AlpaqaProblem::AlpaqaProblem(), casadi::Feasiblesqpmethod::anderson_acc_init_memory(), casadi::Feasiblesqpmethod::anderson_acc_step_update(), casadi::Feasiblesqpmethod::anderson_acc_update_memory(), casadi::BonminUserClass::BonminUserClass(), casadi::Sqpmethod::calc_gamma_1(), casadi::Blocksqp::calcHessianUpdateLimitedMemory(), casadi::Blocksqp::calcLagrangeGradient(), casadi::Blocksqp::calcOptTol(), casadi::Nlpsol::callback(), cb_fdevalini(), cb_read_matrix(), casadi::Nlpsol::check_inputs(), casadi::Feasiblesqpmethod::codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Sqpmethod::codegen_calc_gamma_1(), casadi::Feasiblesqpmethod::codegen_eval_m_k(), casadi::Feasiblesqpmethod::codegen_feasibility_iterations(), casadi::Nlpsol::codegen_post_solve(), casadi::Sqpmethod::codegen_qp_ela_solve(), casadi::Feasiblesqpmethod::codegen_qp_solve(), casadi::Sqpmethod::codegen_qp_solve(), casadi::Nlpsol::codegen_setup_constants(), casadi::Nlpsol::codegen_setup_per_call(), casadi::Sqpmethod::codegen_solve_elastic_mode(), casadi::Feasiblesqpmethod::codegen_step_update(), casadi::Feasiblesqpmethod::codegen_tr_update(), ConoptInterface(), casadi::Blocksqp::convertHessian(), casadi::Scpgen::dualInfeasibility(), casadi::Nlpsol::eval(), casadi::Scpgen::eval_exp(), casadi::Feasiblesqpmethod::eval_m_k(), casadi::Scpgen::eval_mat(), casadi::Scpgen::eval_res(), casadi::Scpgen::eval_vec(), casadi::Blocksqp::evaluate(), casadi::Feasiblesqpmethod::feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationHeuristic(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::Blocksqp::filterLineSearch(), casadi::IpoptUserClass::finalize_metadata(), casadi::BonminInterface::finalize_solution(), casadi::IpoptInterface::finalize_solution(), casadi::Blocksqp::fullstep(), casadi::BonminInterface::get_bounds_info(), casadi::BonminUserClass::get_bounds_info(), casadi::IpoptUserClass::get_bounds_info(), casadi::IpoptInterface::get_bounds_info(), casadi::Nlpsol::get_forward(), casadi::BonminInterface::get_nlp_info(), casadi::IpoptInterface::get_nlp_info(), casadi::Nlpsol::get_reverse(), casadi::BonminInterface::get_starting_point(), casadi::BonminUserClass::get_starting_point(), casadi::IpoptUserClass::get_starting_point(), casadi::IpoptInterface::get_starting_point(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::AmplInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::WorhpInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), init_mem(), casadi::IpoptInterface::init_mem(), casadi::SnoptInterface::init_mem(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::IpoptUserClass::IpoptUserClass(), casadi::Blocksqp::kktErrorReduction(), casadi::Scpgen::line_search(), casadi::Blocksqp::lInfConstraintNorm(), casadi::Nlpsol::Nlpsol(), casadi::Scpgen::primalInfeasibility(), casadi::Blocksqp::printProgress(), casadi::Blocksqp::reduceSOCStepsize(), casadi::Scpgen::regularize(), casadi::Blocksqp::reset_sqp(), casadi::Blocksqp::resetHessian(), casadi::Blocksqp::secondOrderCorrection(), casadi::Nlpsol::serialize_body(), casadi::Blocksqp::set_work(), casadi::BonminInterface::set_work(), casadi::IpoptInterface::set_work(), casadi::KnitroInterface::set_work(), casadi::SLEQPInterface::set_work(), casadi::SnoptInterface::set_work(), casadi::WorhpInterface::set_work(), casadi::Qrsqp::set_work(), casadi::Scpgen::set_work(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::Blocksqp::solve(), casadi::BonminInterface::solve(), solve(), casadi::IpoptInterface::solve(), casadi::KnitroInterface::solve(), casadi::SLEQPInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), casadi::Feasiblesqpmethod::solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Sqpmethod::solve_elastic_mode(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Scpgen::solve_qp(), casadi::Sqpmethod::solve_QP(), casadi::Blocksqp::solveQP(), casadi::Feasiblesqpmethod::step_update(), casadi::Feasiblesqpmethod::tr_update(), casadi::Blocksqp::updateDeltaGamma(), casadi::Blocksqp::updateStepBounds(), and casadi::SnoptInterface::userfun().

◆ optfile_

std::string casadi::ConoptInterface::optfile_

Definition at line 178 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), and serialize_body().

◆ options_

const Options casadi::ConoptInterface::options_
static
Initial value:
=
{"exact_hessian", {OT_BOOL, "Provide exact Hessian to CONOPT"}},
{"warm_start", {OT_BOOL,
"Warm-start CONOPT using multipliers from a prior solve to infer "
"basis status (IniStat=2)"}},
{"conopt", {OT_DICT, "Options to be passed to CONOPT"}},
{"optfile", {OT_STRING,
"Path to a CONOPT option file (for string-valued CR-cells such as Algorithm)"}},
{"debug", {OT_BOOL,
"Print debug output: constraint values at each FDEval, solution vector, "
"and option echo"}}
}}
static const Options options_
Options.

Definition at line 151 of file conopt_interface.hpp.

Referenced by casadi::casadi_register_nlpsol_conopt().

◆ opts_

Dict casadi::ConoptInterface::opts_

Definition at line 177 of file conopt_interface.hpp.

Referenced by ConoptInterface(), init(), init_mem(), and serialize_body().

◆ oracle_

Function casadi::OracleFunction::oracle_
protectedinherited

◆ p_nlp_

casadi_nlpsol_prob<double> casadi::Nlpsol::p_nlp_
inherited

◆ post_expand_

bool casadi::OracleFunction::post_expand_
protectedinherited

◆ 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_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

◆ reverse_options_

Dict casadi::FunctionInternal::reverse_options_
inherited

◆ sens_linsol_

std::string casadi::Nlpsol::sens_linsol_
inherited

◆ sens_linsol_options_

Dict casadi::Nlpsol::sens_linsol_options_
inherited

◆ show_eval_warnings_

bool casadi::OracleFunction::show_eval_warnings_
protectedinherited

◆ solvers_

std::map< std::string, Nlpsol::Plugin > casadi::Nlpsol::solvers_
staticinherited

Definition at line 302 of file nlpsol_impl.hpp.

◆ sparsity_in_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_in_
inherited

◆ sparsity_out_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_out_
inherited

◆ specific_options_

Dict casadi::OracleFunction::specific_options_
protectedinherited

◆ stats_

Dict casadi::FunctionInternal::stats_
inherited

◆ stride_arg_

size_t casadi::OracleFunction::stride_arg_
protectedinherited

◆ stride_iw_

size_t casadi::OracleFunction::stride_iw_
protectedinherited

◆ stride_res_

size_t casadi::OracleFunction::stride_res_
protectedinherited

◆ stride_w_

size_t casadi::OracleFunction::stride_w_
protectedinherited

◆ user_data_

void* casadi::FunctionInternal::user_data_
inherited

◆ 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(), casadi::FmuFunction::factory(), casadi::FunctionInternal::finalize(), casadi::KinsolInterface::func(), casadi::CodeGenerator::generate_dump(), casadi::ProtoFunction::generate_options(), casadi::FmuFunction::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(), casadi::FmuFunction::get_jacobian(), casadi::FunctionInternal::get_partition(), casadi::FmuFunction::get_reverse(), casadi::Integrator::get_reverse(), casadi::ProtoFunction::init(), casadi::FiniteDiff::init(), casadi::FmuFunction::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().

◆ warm_start_

bool casadi::ConoptInterface::warm_start_

Definition at line 175 of file conopt_interface.hpp.

Referenced by cb_read_matrix(), ConoptInterface(), init(), init_mem(), and serialize_body().

◆ warn_initial_bounds_

bool casadi::Nlpsol::warn_initial_bounds_
inherited

The documentation for this class was generated from the following files: