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::FatropInterface Class Reference

'fatrop' plugin for Nlpsol More...

#include <fatrop_interface.hpp>

Detailed Description


List of available options
IdTypeDescription
NOT_INTOCP horizon
convexify_marginOT_DOUBLEWhen using a convexification strategy, make sure that the smallest eigenvalue is at least this (default: 1e-7).
convexify_strategyOT_STRINGNONE|regularize|eigen-reflect|eigen-clip. Strategy to convexify the Lagrange Hessian before passing it to the solver.
debugOT_BOOLProduce debug information (default: false)
fatropOT_DICTOptions to be passed to fatrop
ngOT_INTVECTORNumber of non-dynamic constraints, length N+1
nuOT_INTVECTORNumber of controls, length N+1
nxOT_INTVECTORNumber of states, length N+1
structure_detectionOT_STRINGNONE | auto | manual


List of available options
IdTypeDescriptionUsed in
NOT_INTOCP horizoncasadi::FatropInterface
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
codegen_optionsOT_DICTOptions to be passed to the code generator of jit, e.g. {"stats": true} to record statistics inside the compiled code. Default: nonecasadi::FunctionInternal
common_optionsOT_DICTOptions for auto-generated functionscasadi::OracleFunction
compilerOT_STRINGJust-in-time compiler plugin to be used.casadi::FunctionInternal
convexify_marginOT_DOUBLEWhen using a convexification strategy, make sure that the smallest eigenvalue is at least this (default: 1e-7).casadi::FatropInterface
convexify_strategyOT_STRINGNONE|regularize|eigen-reflect|eigen-clip. Strategy to convexify the Lagrange Hessian before passing it to the solver.casadi::FatropInterface
custom_jacobianOT_FUNCTIONOverride CasADi's AD. Use together with 'jac_penalty': 0. Note: Highly experimental. Syntax may break often.casadi::FunctionInternal
debugOT_BOOLProduce debug information (default: false)casadi::FatropInterface
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
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
fatropOT_DICTOptions to be passed to fatropcasadi::FatropInterface
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
ngOT_INTVECTORNumber of non-dynamic constraints, length N+1casadi::FatropInterface
no_nlp_gradOT_BOOLPrevent the creation of the 'nlp_grad' functioncasadi::Nlpsol
nuOT_INTVECTORNumber of controls, length N+1casadi::FatropInterface
nxOT_INTVECTORNumber of states, length N+1casadi::FatropInterface
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_force_equalityOT_BOOLTreat constraints with equal bounds as active in parametric sensitivities, regardless of the multiplier, see issue #2545 [false].casadi::Nlpsol
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
structure_detectionOT_STRINGNONE | auto | manualcasadi::FatropInterface
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
warn_initial_boundsOT_BOOLWarn if the initial guess does not satisfy LBX and UBXcasadi::Nlpsol

Definition at line 98 of file fatrop_interface.hpp.

Inheritance diagram for casadi::FatropInterface:
Inheritance graph
[legend]
Collaboration diagram for casadi::FatropInterface:
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

 FatropInterface (const std::string &name, const Function &nlp)
 
 ~FatropInterface () override
 
const char * plugin_name () const override
 
std::string class_name () const override
 Get type name. 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...
 
Dict get_stats (void *mem) const override
 Get all statistics. 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
 
void set_fatrop_prob ()
 
void set_fatrop_prob (CodeGenerator &g) const
 
void codegen_body (CodeGenerator &g) const override
 Generate code for the function body. More...
 
void codegen_declarations (CodeGenerator &g) const override
 Generate code for the declarations of the C function. More...
 
void codegen_init_mem (CodeGenerator &g) const override
 Codegen alloc_mem. More...
 
void codegen_free_mem (CodeGenerator &g) const override
 Codegen free_mem. More...
 
std::string codegen_mem_type () const override
 Thread-local memory object type. More...
 
bool codegen_needs_mem () const override
 Is thread-local memory object needed? More...
 
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_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 Function & oracle () 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 Function & get_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< MX > mapsum_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< MX > free_mx () const
 Get free variables (MX) More...
 
virtual std::vector< SX > free_sx () const
 Get free variables (SX) More...
 
virtual bool has_free () const
 Does the function have free variables. More...
 
virtual void generate_lifted (Function &vdef_fcn, Function &vinit_fcn) const
 Extract the functions needed for the Lifted Newton method. More...
 
virtual casadi_int n_instructions () const
 Get the number of atomic operations. More...
 
virtual casadi_int instruction_id (casadi_int k) const
 Get an atomic operation operator index. More...
 
virtual std::vector< casadi_int > instruction_input (casadi_int k) const
 Get the (integer) input arguments of an atomic operation. More...
 
virtual double instruction_constant (casadi_int k) const
 Get the floating point output argument of an atomic operation. More...
 
virtual std::vector< casadi_int > instruction_output (casadi_int k) const
 Get the (integer) output argument of an atomic operation. More...
 
virtual casadi_int n_nodes () const
 Number of nodes in the algorithm. More...
 
virtual MX instruction_MX (casadi_int k) const
 get MX expression associated with instruction More...
 
virtual SX instructions_sx () const
 get SX expression associated with instructions More...
 
Dict cache () const
 Get all functions in the cache. More...
 
bool incache (const std::string &fname, Function &f, const std::string &suffix="") const
 Get function in cache. More...
 
void tocache (const Function &f, const std::string &suffix="") const
 Save function to cache. More...
 
void tocache_if_missing (Function &f, const std::string &suffix="") const
 Save function to cache, only if missing. More...
 
void codegen (CodeGenerator &g, const std::string &fname) const
 Generate code the function. More...
 
void codegen_meta (CodeGenerator &g) const
 Generate meta-information allowing a user to evaluate a generated function. More...
 
void codegen_sparsities (CodeGenerator &g) const
 Codegen sparsities. More...
 
virtual std::string codegen_name (const CodeGenerator &g, bool ns=true) const
 Get name in codegen. More...
 
std::string codegen_mem (CodeGenerator &g, const std::string &index="mem") const
 Get thread-local memory object. More...
 
virtual void codegen_incref (CodeGenerator &g) const
 Codegen incref for dependencies. More...
 
virtual void codegen_decref (CodeGenerator &g) const
 Codegen decref for dependencies. More...
 
virtual void codegen_alloc_mem (CodeGenerator &g) const
 Codegen decref for alloc_mem. More...
 
virtual void codegen_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 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< DM > eval_dm (const std::vector< DM > &arg) const
 Evaluate with DM matrices. More...
 
virtual bool has_eval_dm () const
 Evaluate with DM matrices. More...
 
void call_gen (const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename D >
void call_gen (const std::vector< Matrix< D > > &arg, std::vector< Matrix< D > > &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename M >
void check_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments have correct length and dimensions. More...
 
template<typename M >
void check_res (const std::vector< M > &res, casadi_int &npar) const
 Check if output arguments have correct length and dimensions. More...
 
template<typename M >
std::map< std::string, M > convert_arg (const std::vector< M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_arg (const std::map< std::string, M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::map< std::string, M > convert_res (const std::vector< M > &res) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_res (const std::map< std::string, M > &res) const
 Convert from/to input/output lists/map. More...
 
std::vector< double > nz_in (const std::vector< DM > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DM > nz_in (const std::vector< double > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< double > nz_out (const std::vector< DM > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DM > nz_out (const std::vector< double > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
virtual void call_forward (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_forward (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &fseed, std::vector< std::vector< SX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &aseed, std::vector< std::vector< SX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
Function jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
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...
 
Sparsity & jac_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< SX > sx_in () const
 Get function input(s) and output(s) More...
 
virtual const SX sx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SX > sx_out () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MX > mx_in () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MX > mx_out () const
 Get function input(s) and output(s) More...
 
const DM dm_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DM > dm_in () const
 Get function input(s) and output(s) More...
 
const DM dm_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DM > dm_out () const
 Get function input(s) and output(s) More...
 
Function wrap (const std::string &name) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap () const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const std::string &name, const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
casadi_int nnz_in () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_in (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int numel_in () const
 Number of input/output elements. More...
 
casadi_int numel_in (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out () const
 Number of input/output elements. More...
 
casadi_int size1_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size1_out (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_out (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_in (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_out (casadi_int ind) const
 Input/output dimensions. More...
 
const Sparsity & sparsity_in (casadi_int ind) const
 Input/output sparsity. More...
 
const Sparsity & sparsity_out (casadi_int ind) const
 Input/output sparsity. More...
 
bool all_scalar () const
 Are all inputs and outputs scalar. More...
 
virtual bool jac_is_symm (casadi_int oind, casadi_int iind) const
 Is a Jacobian block known to be symmetric a priori? More...
 
Sparsity to_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert to compact Jacobian sparsity pattern. More...
 
Sparsity from_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert from compact Jacobian sparsity pattern. More...
 
template<bool fwd>
Sparsity get_jac_sparsity_gen (casadi_int oind, casadi_int iind) const
 Get the sparsity pattern via sparsity seed propagation. More...
 
Sparsity get_jac_sparsity_hierarchical (casadi_int oind, casadi_int iind) const
 A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition. More...
 
Sparsity get_jac_sparsity_hierarchical_symm (casadi_int oind, casadi_int iind) const
 
virtual std::vector< MX > symbolic_output (const std::vector< MX > &arg) const
 Get a vector of symbolic variables corresponding to the outputs. More...
 
virtual 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 Nlpsol * creator (const std::string &name, const Function &nlp)
 Create a new NLP Solver. More...
 
static ProtoFunction * deserialize (DeserializingStream &s)
 Deserialize into MX. More...
 
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 Options & plugin_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 Nlpsol * instantiate (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 jacg_sp_
 
Sparsity hesslag_sp_
 
bool exact_hessian_
 Exact Hessian? More...
 
Dict opts_
 All FATROP options. More...
 
ConvexifyData convexify_data_
 Data for convexification. More...
 
bool convexify_
 convexify? More...
 
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< Sparsity > sparsity_in_
 Input and output sparsity. More...
 
std::vector< Sparsity > sparsity_out_
 
std::vector< std::string > name_in_
 Input and output scheme. More...
 
std::vector< std::string > name_out_
 
bool jit_
 Use just-in-time compiler. More...
 
bool jit_cleanup_
 Cleanup jit source file. More...
 
std::string jit_serialize_
 Serialize behaviour. More...
 
std::string jit_name_
 Name if jit source file. More...
 
std::string jit_directory_
 
std::string jit_base_name_
 
bool jit_temp_suffix_
 Use a temporary name. More...
 
eval_t eval_
 Numerical evaluation redirected to a C function. More...
 
casadi_checkout_t checkout_
 Checkout redirected to a C function. More...
 
casadi_release_t release_
 Release redirected to a C function. More...
 
signal_t incref_
 Incref/decref redirected to C functions. More...
 
signal_t decref_
 
Dict stats_
 Dict of statistics (resulting from evaluate) More...
 
bool has_refcount_
 Reference counting in codegen? More...
 
bool has_refcount_in_deps_
 Reference counting in dependent functions. More...
 
Dict cache_init_
 Values to prepopulate the function cache with. More...
 
WeakCache< std::string, Function > cache_
 Function cache. More...
 
std::vector< Sparsity > jac_sparsity_ [2]
 Cache for sparsities of the Jacobian blocks. More...
 
Function derivative_of_
 If the function is the derivative of another function. More...
 
void * user_data_
 User-set field. More...
 
std::string compiler_plugin_
 Just-in-time compiler. More...
 
Importer compiler_
 
Dict jit_options_
 
Dict codegen_options_
 Options of the code generator of jit. More...
 
double jac_penalty_
 Penalty factor for using a complete Jacobian to calculate directional derivatives. More...
 
bool enable_forward_
 
bool enable_reverse_
 
bool enable_jacobian_
 
bool enable_fd_
 
bool enable_forward_op_
 
bool enable_reverse_op_
 
bool enable_jacobian_op_
 
bool enable_fd_op_
 
double ad_weight_
 Weighting factor for derivative calculation and sparsity pattern calculation. More...
 
double ad_weight_sp_
 
casadi_int max_num_dir_
 Maximum number of sensitivity directions. More...
 
bool inputs_check_
 Errors are thrown if numerical values of inputs look bad. More...
 
Dict fd_options_
 
double fd_step_
 
std::string fd_method_
 
bool print_in_
 
bool print_out_
 
bool print_canonical_
 
casadi_int max_io_
 
bool dump_in_
 
bool dump_out_
 
bool dump_
 
std::string dump_dir_
 
std::string dump_format_
 
Dict forward_options_
 
Dict reverse_options_
 
Dict jacobian_options_
 
Dict der_options_
 
Function custom_jacobian_
 
std::vector< Function > registered_functions_
 
casadi_int dump_count_
 
std::string name_
 Name. More...
 
bool verbose_
 Verbose printout. More...
 
bool print_time_
 
bool record_time_
 
bool regularity_check_
 Errors are thrown when NaN is produced. More...
 
bool error_on_fail_
 Throw an exception on failure? More...
 
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 sens_force_equality_
 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 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

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

Static Protected Member Functions

static void trace_values (std::ostream &trace, const double *values, casadi_int nnz)
 

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, RegFun > all_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_
 
static const Options options_
 Options. More...
 
const Options & get_options () const override
 Options. More...
 

Member Typedef Documentation

◆ Creator

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

Definition at line 297 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

◆ FatropInterface() [1/2]

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

Definition at line 68 of file fatrop_interface.cpp.

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

◆ ~FatropInterface()

casadi::FatropInterface::~FatropInterface ( )
override

Definition at line 72 of file fatrop_interface.cpp.

72  {
73  clear_mem();
74  }
void clear_mem()
Clear all memory (called from destructor)

References casadi::ProtoFunction::clear_mem().

◆ FatropInterface() [2/2]

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

Definition at line 881 of file fatrop_interface.cpp.

881  : Nlpsol(s) {
882  s.version("FatropInterface", 1);
883  s.unpack("FatropInterface::jacg_sp", jacg_sp_);
884  s.unpack("FatropInterface::hesslag_sp", hesslag_sp_);
885  s.unpack("FatropInterface::exact_hessian", exact_hessian_);
886  s.unpack("FatropInterface::opts", opts_);
887  s.unpack("FatropInterface::convexify", convexify_);
888 
889 
890  s.unpack("FatropInterface::Isp", Isp_);
891  s.unpack("FatropInterface::ABsp", ABsp_);
892  s.unpack("FatropInterface::CDsp", CDsp_);
893  s.unpack("FatropInterface::RSQsp", RSQsp_);
894 
895  std::vector<casadi_int> AB_blocks;
896  s.unpack("FatropInterface::AB_blocks", AB_blocks);
897  unpack_block(AB_blocks, AB_blocks_);
898  std::vector<casadi_int> CD_blocks;
899  s.unpack("FatropInterface::CD_blocks", CD_blocks);
900  unpack_block(CD_blocks, CD_blocks_);
901  std::vector<casadi_int> RSQ_blocks;
902  s.unpack("FatropInterface::RSQ_blocks", RSQ_blocks);
903  unpack_block(RSQ_blocks, RSQ_blocks_);
904  std::vector<casadi_int> I_blocks;
905  s.unpack("FatropInterface::I_blocks", I_blocks);
906  unpack_block(I_blocks, I_blocks_);
907 
908  s.unpack("FatropInterface::nxs", nxs_);
909  s.unpack("FatropInterface::nus", nus_);
910  s.unpack("FatropInterface::ngs", ngs_);
911  s.unpack("FatropInterface::N", N_);
912 
913  casadi_int structure_detection;
914  s.unpack("FatropInterface::structure_detection", structure_detection);
915  structure_detection_ = static_cast<StructureDetection>(structure_detection);
916 
917 
918  s.unpack("FatropInterface::AB_offsets", AB_offsets_);
919  s.unpack("FatropInterface::CD_offsets", CD_offsets_);
920  s.unpack("FatropInterface::RSQ_offsets", RSQ_offsets_);
921  s.unpack("FatropInterface::I_offsets", I_offsets_);
922  s.unpack("FatropInterface::debug", debug_);
923 
924  set_fatrop_prob();
925 }
Dict opts_
All FATROP options.
bool exact_hessian_
Exact Hessian?
void unpack_block(const std::vector< casadi_int > &p, std::vector< casadi_ocp_block > &blocks)

References convexify_, exact_hessian_, hesslag_sp_, jacg_sp_, opts_, set_fatrop_prob(), casadi::DeserializingStream::unpack(), casadi::unpack_block(), and casadi::DeserializingStream::version().

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 3529 of file function_internal.cpp.

3529  {
3530  // If reverse mode derivatives unavailable, use forward
3531  if (!enable_reverse_) return 0;
3532 
3533  // If forward mode derivatives unavailable, use reverse
3534  if (!enable_forward_ && !enable_fd_) return 1;
3535 
3536  // Use the (potentially user set) option
3537  return ad_weight_;
3538  }
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 3976 of file function_internal.cpp.

3978  {
3979  // Add, if not already in graph and not null
3980  if (!dep.is_null() && all_fun.find(dep.get()) == all_fun.end()) {
3981  size_t index = all_fun.size();
3982  all_fun[dep.get()] = std::make_pair(dep, index);
3983  // Also add its dependencies
3984  if (max_depth > 0) dep->find(all_fun, max_depth - 1);
3985  }
3986  }

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 3262 of file function_internal.cpp.

3262  {
3263  if (!enable_reverse_) return true;
3264  if (jac_penalty_==-1) return false;
3265 
3266  // Heuristic 1: Jac calculated via reverse mode likely cheaper
3267  if (jac_penalty_*static_cast<double>(nnz_out())<nadj) return true;
3268 
3269  // Heuristic 2: Jac calculated via forward mode likely cheaper
3270  double w = ad_weight();
3271  if ((enable_forward_ || enable_fd_) &&
3272  jac_penalty_*w*static_cast<double>(nnz_in())<(1-w)*static_cast<double>(nadj))
3273  return true; // NOLINT
3274 
3275  return false;
3276  }
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 4021 of file function_internal.cpp.

4021  {
4022  // Check inputs
4023  for (casadi_int i=0; i<n_in_; ++i) {
4024  if (!sparsity_in_[i].is_scalar()) return false;
4025  }
4026  // Check outputs
4027  for (casadi_int i=0; i<n_out_; ++i) {
4028  if (!sparsity_out_[i].is_scalar()) return false;
4029  }
4030  // All are scalar
4031  return true;
4032  }
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 3210 of file function_internal.cpp.

3210  {
3211  if (f.is_null()) return;
3212  size_t sz_arg, sz_res, sz_iw, sz_w;
3213  f.sz_work(sz_arg, sz_res, sz_iw, sz_w);
3214  alloc_arg(sz_arg*num_threads, persistent);
3215  alloc_res(sz_res*num_threads, persistent);
3216  alloc_iw(sz_iw*num_threads, persistent);
3217  alloc_w(sz_w*num_threads, persistent);
3218  registered_functions_.push_back(f);
3219  }
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::FatropInterface::alloc_mem ( ) const
inlineoverridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 127 of file fatrop_interface.hpp.

127 { return new FatropMemory();}

◆ 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 3202 of file function_internal.cpp.

3202  {
3203  if (persistent) {
3204  sz_w_per_ += sz_w;
3205  } else {
3206  sz_w_tmp_ = std::max(sz_w_tmp_, sz_w);
3207  }
3208  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::alloc(), casadi::RuntimeIntegrator::alloc_ivp_work(), 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::RuntimeIntegrator::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(), 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::Rosenbrock::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 332 of file nlpsol_impl.hpp.

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

◆ bound_consistency()

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

Definition at line 779 of file nlpsol.cpp.

780  {
781  casadi_assert_dev(z!=nullptr);
782  casadi_assert_dev(lam!=nullptr);
783  casadi_assert_dev(lbz!=nullptr);
784  casadi_assert_dev(ubz!=nullptr);
785  // Local variables
786  casadi_int i;
787  // Loop over variables
788  for (i=0; i<n; ++i) {
789  // Make sure bounds are respected
790  z[i] = std::fmin(std::fmax(z[i], lbz[i]), ubz[i]);
791  // Adjust multipliers
792  if (std::isinf(lbz[i]) && std::isinf(ubz[i])) {
793  // Both multipliers are infinite
794  lam[i] = 0.;
795  } else if (std::isinf(lbz[i]) || z[i] - lbz[i] > ubz[i] - z[i]) {
796  // Infinite lower bound or closer to upper bound than lower bound
797  lam[i] = std::fmax(0., lam[i]);
798  } else if (std::isinf(ubz[i]) || z[i] - lbz[i] < ubz[i] - z[i]) {
799  // Infinite upper bound or closer to lower bound than upper bound
800  lam[i] = std::fmin(0., lam[i]);
801  }
802  }
803  }

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 1170 of file function_internal.cpp.

1170  {
1171  // Return value
1172  Dict ret;
1173 
1174  // Retrieve all Function instances that haven't been deleted
1175  std::vector<std::string> keys;
1176  std::vector<Function> entries;
1177  cache_.cache(keys, entries);
1178 
1179  for (size_t i=0; i<keys.size(); ++i) {
1180  // Get the name of the key
1181  std::string s = keys[i];
1182  casadi_assert_dev(s.size() > 0);
1183  // Replace ':' with '_'
1184  std::replace(s.begin(), s.end(), ':', '_');
1185  // Remove trailing underscore, if any
1186  if (s.back() == '_') s.resize(s.size() - 1);
1187  // Add entry to function return
1188  ret[s] = entries[i];
1189  }
1190 
1191  return ret;
1192  }
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 303 of file oracle_function.cpp.

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

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

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

3507  {
3508  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3509  if (fseed.empty()) { // Quick return if no seeds
3510  fsens.clear();
3511  return;
3512  }
3513  casadi_error("'forward' (SX) not defined for " + class_name());
3514  }

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 4195 of file function_internal.cpp.

4197  {
4198  if (npar==1) {
4199  eval_mx(arg, res, always_inline, never_inline);
4200  } else {
4201  // Split it up arguments
4202  std::vector<std::vector<MX>> v(npar, arg);
4203  std::vector<MX> t;
4204  for (int i=0; i<n_in_; ++i) {
4205  if (arg[i].size2()!=size2_in(i)) {
4206  t = horzsplit(arg[i], size2_in(i));
4207  casadi_assert_dev(t.size()==npar);
4208  for (int p=0; p<npar; ++p) v[p][i] = t[p];
4209  }
4210  }
4211  // Unroll the loop
4212  for (int p=0; p<npar; ++p) {
4213  eval_mx(v[p], t, always_inline, never_inline);
4214  v[p] = t;
4215  }
4216  // Concatenate results
4217  t.resize(npar);
4218  res.resize(n_out_);
4219  for (int i=0; i<n_out_; ++i) {
4220  for (int p=0; p<npar; ++p) t[p] = v[p][i];
4221  res[i] = horzcat(t);
4222  }
4223  }
4224  }
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 1729 of file function_internal.hpp.

1731  {
1732  std::vector< Matrix<D> > arg2 = project_arg(arg, npar);
1733 
1734  // Which arguments require mapped evaluation
1735  std::vector<bool> mapped(n_in_);
1736  for (casadi_int i=0; i<n_in_; ++i) {
1737  mapped[i] = arg[i].size2()!=size2_in(i);
1738  }
1739 
1740  // Allocate results
1741  res.resize(n_out_);
1742  for (casadi_int i=0; i<n_out_; ++i) {
1743  if (!res[i].sparsity().is_stacked(sparsity_out(i), npar)) {
1744  res[i] = Matrix<D>::zeros(repmat(sparsity_out(i), 1, npar));
1745  }
1746  }
1747 
1748  // Allocate temporary memory if needed
1749  std::vector<casadi_int> iw_tmp(sz_iw());
1750  std::vector<D> w_tmp(sz_w());
1751 
1752  // Get pointers to input arguments
1753  std::vector<const D*> argp(sz_arg());
1754  for (casadi_int i=0; i<n_in_; ++i) argp[i]=get_ptr(arg2[i]);
1755 
1756  // Get pointers to output arguments
1757  std::vector<D*> resp(sz_res());
1758  for (casadi_int i=0; i<n_out_; ++i) resp[i]=get_ptr(res[i]);
1759 
1760  // For all parallel calls
1761  for (casadi_int p=0; p<npar; ++p) {
1762  // Call memory-less
1763  if (eval_gen(get_ptr(argp), get_ptr(resp),
1764  get_ptr(iw_tmp), get_ptr(w_tmp), memory(0),
1765  always_inline, never_inline)) {
1766  if (error_on_fail_) casadi_error("Evaluation failed");
1767  }
1768  // Update offsets
1769  if (p==npar-1) break;
1770  for (casadi_int i=0; i<n_in_; ++i) if (mapped[i]) argp[i] += nnz_in(i);
1771  for (casadi_int i=0; i<n_out_; ++i) resp[i] += nnz_out(i);
1772  }
1773  }
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 3388 of file function_internal.cpp.

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

3520  {
3521  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3522  if (aseed.empty()) { // Quick return if no seeds
3523  asens.clear();
3524  return;
3525  }
3526  casadi_error("'reverse' (SX) not defined for " + class_name());
3527  }

References casadi::SharedObjectInternal::class_name().

◆ callback()

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

Definition at line 1200 of file nlpsol.cpp.

1200  {
1201  // Quick return if no callback function
1202  if (fcallback_.is_null()) return 0;
1203  // Callback inputs
1204  std::fill_n(m->arg, fcallback_.n_in(), nullptr);
1205 
1206  auto *d_nlp = &m->d_nlp;
1207 
1208  m->arg[NLPSOL_X] = d_nlp->z;
1209  m->arg[NLPSOL_F] = &d_nlp->objective;
1210  m->arg[NLPSOL_G] = d_nlp->z + nx_;
1211  m->arg[NLPSOL_LAM_G] = d_nlp->lam + nx_;
1212  m->arg[NLPSOL_LAM_X] = d_nlp->lam;
1213 
1214  // Callback outputs
1215  std::fill_n(m->res, fcallback_.n_out(), nullptr);
1216  double ret = 0;
1217  m->res[0] = &ret;
1218 
1219  // Start timer
1220  m->fstats.at("callback_fun").tic();
1221  try {
1222  // Evaluate
1223  fcallback_(m->arg, m->res, m->iw, m->w, 0);
1224  } catch(KeyboardInterruptException& ex) {
1225  (void)ex; // unused
1226  throw;
1227  } catch(std::exception& ex) {
1228  print("WARNING: intermediate_callback error: %s\n", ex.what());
1230  }
1231 
1232  // User user interruption?
1233  if (static_cast<casadi_int>(ret)) return 1;
1234 
1235  // Stop timer
1236  m->fstats.at("callback_fun").toc();
1237 
1238  return 0;
1239  }
casadi_int n_out() const
Get the number of function outputs.
Definition: function.cpp:975
casadi_int n_in() const
Get the number of function inputs.
Definition: function.cpp:971
bool is_null() const
Is a null pointer?
bool iteration_callback_ignore_errors_
Options.
Definition: nlpsol_impl.hpp:95
casadi_int nx_
Number of variables.
Definition: nlpsol_impl.hpp:66
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:858
@ NLPSOL_X
Decision variables at the optimal solution (nx x 1)
Definition: nlpsol.hpp:854
@ NLPSOL_F
Cost function value at the optimal solution (1 x 1)
Definition: nlpsol.hpp:856
@ NLPSOL_LAM_G
Lagrange multipliers for bounds on G at the solution (ng x 1); same sign convention.
Definition: nlpsol.hpp:863
@ NLPSOL_LAM_X
Definition: nlpsol.hpp:861

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

◆ 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 448 of file function_internal.cpp.

449  {
450  if (option_name == "print_in") {
451  print_in_ = option_value;
452  } else if (option_name == "print_out") {
453  print_out_ = option_value;
454  } else if (option_name == "print_canonical") {
455  print_canonical_ = option_value;
456  } else if (option_name=="ad_weight") {
457  ad_weight_ = option_value;
458  } else if (option_name=="ad_weight_sp") {
459  ad_weight_sp_ = option_value;
460  } else if (option_name=="dump") {
461  dump_ = option_value;
462  } else if (option_name=="dump_in") {
463  dump_in_ = option_value;
464  } else if (option_name=="dump_out") {
465  dump_out_ = option_value;
466  } else if (option_name=="dump_dir") {
467  dump_dir_ = option_value.to_string();
468  } else if (option_name=="dump_format") {
469  dump_format_ = option_value.to_string();
470  } else {
471  // Option not found - continue to base classes
472  ProtoFunction::change_option(option_name, option_value);
473  }
474  }
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 1776 of file function_internal.hpp.

1776  {
1777  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1778  + str(n_in_) + ", got " + str(arg.size()));
1779  for (casadi_int i=0; i<n_in_; ++i) {
1780  if (!check_mat(arg[i].sparsity(), sparsity_in(i), npar)) {
1781  // Dimensions
1782  std::string d_arg = str(arg[i].size1()) + "-by-" + str(arg[i].size2());
1783  std::string d_in = str(size1_in(i)) + "-by-" + str(size2_in(i));
1784  std::string e = "Input " + str(i) + " (" + name_in_[i] + ") has mismatching shape. "
1785  "Got " + d_arg + ". Allowed dimensions, in general, are:\n"
1786  " - The input dimension N-by-M (here " + d_in + ")\n"
1787  " - A scalar, i.e. 1-by-1\n"
1788  " - M-by-N if N=1 or M=1 (i.e. a transposed vector)\n"
1789  " - N-by-M1 if K*M1=M for some K (argument repeated horizontally)\n";
1790  if (npar!=-1) {
1791  e += " - N-by-P*M, indicating evaluation with multiple arguments (P must be a "
1792  "multiple of " + str(npar) + " for consistency with previous inputs)";
1793  }
1794  casadi_error(e);
1795  }
1796  }
1797  }
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 714 of file nlpsol.cpp.

714  {
715  auto *m = static_cast<NlpsolMemory*>(mem);
716  auto *d_nlp = &m->d_nlp;
717 
718  // Skip check?
719  if (!inputs_check_) return;
720 
721  const double inf = std::numeric_limits<double>::infinity();
722 
723  // Number of equality constraints
724  casadi_int n_eq = 0;
725 
726  // Detect ill-posed problems (simple bounds)
727  for (casadi_int i=0; i<nx_; ++i) {
728  double lb = d_nlp->lbx ? d_nlp->lbx[i] : get_default_in(NLPSOL_LBX);
729  double ub = d_nlp->ubx ? d_nlp->ubx[i] : get_default_in(NLPSOL_UBX);
730  double x0 = d_nlp->x0 ? d_nlp->x0[i] : get_default_in(NLPSOL_X0);
731  casadi_assert(lb <= ub && lb!=inf && ub!=-inf,
732  "Ill-posed problem detected: "
733  "LBX[" + str(i) + "] <= UBX[" + str(i) + "] was violated. "
734  "Got LBX[" + str(i) + "]=" + str(lb) + " and UBX[" + str(i) + "] = " + str(ub) + ".");
735  if (warn_initial_bounds_ && (x0>ub || x0<lb)) {
736  casadi_warning("Nlpsol: The initial guess does not satisfy LBX and UBX. "
737  "Option 'warn_initial_bounds' controls this warning.");
738  break;
739  }
740  if (lb==ub) n_eq++;
741  }
742 
743  // Detect ill-posed problems (nonlinear bounds)
744  for (casadi_int i=0; i<nnz_out(NLPSOL_G); ++i) {
745  double lb = d_nlp->lbg ? d_nlp->lbg[i] : get_default_in(NLPSOL_LBG);
746  double ub = d_nlp->ubg ? d_nlp->ubg[i] : get_default_in(NLPSOL_UBG);
747  casadi_assert(lb <= ub && lb!=inf && ub!=-inf,
748  "Ill-posed problem detected: "
749  "LBG[" + str(i) + "] <= UBG[" + str(i) + "] was violated. "
750  "Got LBG[" + str(i) + "] = " + str(lb) + " and UBG[" + str(i) + "] = " + str(ub) + ".");
751  if (lb==ub) n_eq++;
752  }
753 
754  // Make sure enough degrees of freedom
755  using casadi::str; // Workaround, MingGW bug, cf. CasADi issue #890
756  if (n_eq> nx_) {
757  casadi_warning("NLP is overconstrained: There are " + str(n_eq) +
758  " equality constraints but only " + str(nx_) + " variables.");
759  }
760  }
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:839
@ NLPSOL_X0
Decision variables, initial guess (nx x 1), default 0.
Definition: nlpsol.hpp:833
@ NLPSOL_UBG
Constraints upper bound (ng x 1), default +inf.
Definition: nlpsol.hpp:843
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
Definition: nlpsol.hpp:841
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
Definition: nlpsol.hpp:837
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 3714 of file function_internal.cpp.

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

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 1800 of file function_internal.hpp.

1800  {
1801  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1802  + str(n_out_) + ", got " + str(res.size()));
1803  for (casadi_int i=0; i<n_out_; ++i) {
1804  casadi_assert(check_mat(res[i].sparsity(), sparsity_out(i), npar),
1805  "Output " + str(i) + " (" + name_out_[i] + ") has mismatching shape. "
1806  "Expected " + str(size_out(i)) + ", got " + str(res[i].size()));
1807  }
1808  }
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 3923 of file function_internal.cpp.

3923  {
3924 #ifdef CASADI_WITH_THREAD
3925  std::lock_guard<std::mutex> lock(mtx_);
3926 #endif //CASADI_WITH_THREAD
3927  if (unused_.empty()) {
3928  check_mem_count(mem_.size()+1);
3929  // Allocate a new memory object
3930  void* m = alloc_mem();
3931  mem_.push_back(m);
3932  if (init_mem(m)) {
3933  casadi_error("Failed to create or initialize memory object");
3934  }
3935  return static_cast<int>(mem_.size()) - 1;
3936  } else {
3937  // Use an unused memory object
3938  int m = unused_.top();
3939  unused_.pop();
3940  return m;
3941  }
3942  }
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::FatropInterface::class_name ( ) const
inlineoverridevirtual

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

Reimplemented from casadi::Nlpsol.

Definition at line 110 of file fatrop_interface.hpp.

110 { return "FatropInterface";}

Referenced by codegen_body().

◆ clear_mem()

void casadi::ProtoFunction::clear_mem ( )
inherited

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

Definition at line 3811 of file function_internal.cpp.

3811  {
3812  for (auto&& i : mem_) {
3813  if (i!=nullptr) free_mem(i);
3814  }
3815  mem_.clear();
3816  }
virtual void free_mem(void *mem) const
Free memory block.

References casadi::ProtoFunction::free_mem().

Referenced by casadi::AlpaqaInterface::~AlpaqaInterface(), casadi::AmplInterface::~AmplInterface(), casadi::BlazingSplineFunction::~BlazingSplineFunction(), casadi::Blocksqp::~Blocksqp(), casadi::BonminInterface::~BonminInterface(), casadi::BSplineInterpolant::~BSplineInterpolant(), casadi::CallbackInternal::~CallbackInternal(), casadi::CbcInterface::~CbcInterface(), casadi::ClarabelInterface::~ClarabelInterface(), casadi::ClpInterface::~ClpInterface(), casadi::ConoptInterface::~ConoptInterface(), casadi::CplexInterface::~CplexInterface(), casadi::CsparseInterface::~CsparseInterface(), casadi::CvodesInterface::~CvodesInterface(), casadi::DaqpInterface::~DaqpInterface(), casadi::Erk::~Erk(), casadi::External::~External(), casadi::FastNewton::~FastNewton(), casadi::FatropConicInterface::~FatropConicInterface(), ~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::Rosenbrock::~Rosenbrock(), 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 2517 of file function_internal.cpp.

2517  {
2518  // Define function
2519  g << "/* " << definition() << " */\n";
2520  g << "static " << signature(fname) << " {\n";
2521 
2522  // Reset local variables, flush buffer
2523  g.flush(g.body);
2524 
2525  g.scope_enter();
2526 
2527  if (dump_in_ || dump_out_) {
2528  Function F = shared_from_this<Function>();
2529  std::string cg_name = codegen_name(g, false);
2530  std::string dump_counter = g.shorthand(cg_name + "_dump_counter");
2531  g.auxiliaries << "static int " << dump_counter << " = 0;\n";
2532  if (g.thread_safe()) {
2533  g.define_local_mutex(F, cg_name + "_dump_mutex");
2534  std::string dump_mutex = g.local_mutex(F, cg_name + "_dump_mutex");
2535  g << "CASADI_MUTEX_LOCK(&" << dump_mutex << ");\n";
2536  g << "int dump_id_local = " << dump_counter << "++;\n";
2537  g << "CASADI_MUTEX_UNLOCK(&" << dump_mutex << ");\n";
2538  } else {
2539  g << "int dump_id_local = " << dump_counter << "++;\n";
2540  }
2541  }
2542 
2543  if (dump_in_) g.generate_dump(shared_from_this<Function>(), "arg", true);
2544  if (print_in_) g.generate_print(shared_from_this<Function>(), "arg", true);
2545 
2546  // Generate function body (to buffer)
2547  codegen_body(g);
2548 
2549  if (dump_out_) g.generate_dump(shared_from_this<Function>(), "res", false);
2550  if (print_out_) g.generate_print(shared_from_this<Function>(), "res", false);
2551 
2552  g.scope_exit();
2553 
2554  // Finalize the function
2555  g << "return 0;\n";
2556  g << "}\n\n";
2557 
2558  // Flush to function body
2559  g.flush(g.body);
2560  }
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 2661 of file function_internal.cpp.

2661  {
2662  bool needs_mem = codegen_needs_mem();
2663  if (needs_mem) {
2664  std::string name = codegen_name(g, false);
2665  std::string mem_counter = g.shorthand(name + "_mem_counter");
2666  g << "return " + mem_counter + "++;\n";
2667  }
2668  }
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::FatropInterface::codegen_body ( CodeGenerator &  g) const
overridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 692 of file fatrop_interface.cpp.

692  {
694  g.add_runtime(class_name(), fatrop_runtime_str, {"casadi_real"});
695 
696  g.local("d", "struct casadi_fatrop_data*");
697  g.init_local("d", "&" + codegen_mem(g));
698  g.local("p", "struct casadi_fatrop_prob");
699  set_fatrop_prob(g);
700 
701  g << "casadi_fatrop_set_work(d, &arg, &res, &iw, &w);\n";
702  g << "casadi_oracle_set_work(d->nlp->oracle, &arg, &res, &iw, &w);\n";
703 
704  // Cache the solver: presolve (re)creates it only when needed
705  g << "{\n";
706  g << "int new_solver = (d->solver == 0);\n";
707  // fatrop's solve repoints a process-wide singleton stream via
708  // fatrop::OutputStreamManager::set_stream, which is not thread-safe.
709  // Serialize across threads.
710  if (g.thread_safe()) {
711  Function F = shared_from_this<Function>();
712  std::string mutex_name = codegen_name(g, false) + "_fatrop_create_mutex";
713  g.define_local_mutex(F, mutex_name);
714  std::string mtx = g.local_mutex(F, mutex_name);
715  g << "CASADI_MUTEX_LOCK(&" << mtx << ");\n";
716  g << "casadi_fatrop_presolve(d);\n";
717  g << "CASADI_MUTEX_UNLOCK(&" << mtx << ");\n";
718  } else {
719  g << "casadi_fatrop_presolve(d);\n";
720  }
721  g << "if (new_solver) {\n";
722 
723  for (const auto& kv : opts_) {
724  switch (fatrop_ocp_c_option_type(kv.first.c_str())) {
725  case 0:
726  g << "fatrop_ocp_c_set_option_double(d->solver, \"" + kv.first + "\", "
727  + g.constant(kv.second.to_double()) + ");\n";
728  break;
729  case 1:
730  g << "fatrop_ocp_c_set_option_int(d->solver, \"" + kv.first + "\", "
731  + str(kv.second.to_int()) + ");\n";
732  break;
733  case 2:
734  g << "fatrop_ocp_c_set_option_bool(d->solver, \"" + kv.first + "\", "
735  + str(static_cast<int>(kv.second.to_bool())) + ");\n";
736  break;
737  case 3:
738  {
739  std::string s = kv.second.to_string();
740  g << "fatrop_ocp_c_set_option_bool(d->solver, \"" + kv.first + "\", \""
741  + s + "\");\n";
742  }
743  break;
744  case -1:
745  casadi_error("Fatrop option not supported: " + kv.first);
746  default:
747  casadi_error("Unknown option type.");
748  }
749  }
750 
751  g << "}\n";
752  g << "}\n";
753  g << "casadi_fatrop_solve(d);\n";
754 
756 
757  if (error_on_fail_) {
758  g << "return d->unified_return_status;\n";
759  } else {
760  g << "return 0;\n";
761  }
762 }
std::string class_name() const override
Get type name.
std::string codegen_mem(CodeGenerator &g, const std::string &index="mem") const
Get thread-local memory object.
void codegen_body_exit(CodeGenerator &g) const override
Generate code for the function body.
Definition: nlpsol.cpp:1358
void codegen_body_enter(CodeGenerator &g) const override
Generate code for the function body.
Definition: nlpsol.cpp:1258

References casadi::CodeGenerator::add_runtime(), class_name(), casadi::Nlpsol::codegen_body_enter(), casadi::Nlpsol::codegen_body_exit(), casadi::FunctionInternal::codegen_mem(), casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::constant(), casadi::CodeGenerator::define_local_mutex(), casadi::ProtoFunction::error_on_fail_, casadi::CodeGenerator::init_local(), casadi::CodeGenerator::local(), casadi::CodeGenerator::local_mutex(), opts_, set_fatrop_prob(), casadi::str(), and casadi::CodeGenerator::thread_safe().

◆ 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 1258 of file nlpsol.cpp.

1258  {
1260  g.local("d_nlp", "struct casadi_nlpsol_data");
1261  g.local("p_nlp", "struct casadi_nlpsol_prob");
1262  codegen_setup_constants(g, "d_nlp", "p_nlp", "d_oracle");
1263  codegen_setup_per_call(g, "d_nlp");
1264  }
void codegen_setup_per_call(CodeGenerator &g, const std::string &d_nlp) const
Definition: nlpsol.cpp:1303
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:1271
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(), 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 1358 of file nlpsol.cpp.

1358  {
1359  codegen_post_solve(g, "d_nlp");
1361  }
void codegen_post_solve(CodeGenerator &g, const std::string &d_nlp) const
Definition: nlpsol.cpp:1363
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(), 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 2670 of file function_internal.cpp.

2670  {
2671  std::string name = codegen_name(g, false);
2672  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2673  std::string stack = g.shorthand(name + "_unused_stack");
2674  std::string mem_counter = g.shorthand(name + "_mem_counter");
2675  std::string mem_array = g.shorthand(name + "_mem");
2676  std::string alloc_mem = g.shorthand(name + "_alloc_mem");
2677  std::string init_mem = g.shorthand(name + "_init_mem");
2678 
2679 
2680  g.auxiliaries << "static int " << mem_counter << " = 0;\n";
2681  g.auxiliaries << "static int " << stack_counter << " = -1;\n";
2682  g.auxiliaries << "static int " << stack << "[CASADI_MAX_NUM_THREADS];\n";
2683  g.auxiliaries << "static " << codegen_mem_type() <<
2684  " " << mem_array << "[CASADI_MAX_NUM_THREADS];\n\n";
2685 
2686  if (g.thread_safe()) {
2687  Function F = shared_from_this<Function>();
2688  g.define_local_mutex(F, name + "_mem_mutex");
2689  std::string mem_mutex = g.local_mutex(F, name + "_mem_mutex");
2690  g << "CASADI_MUTEX_LOCK(&" << mem_mutex << ");\n";
2691  g.scope_add_cleanup("CASADI_MUTEX_UNLOCK(&" + mem_mutex + ");\n");
2692  }
2693 
2694  g.local("mid", "int");
2695 
2696  g << "if (" << stack_counter << ">=0) {\n";
2697  g.scope_return(stack + "[" + stack_counter + "--]");
2698  g << "} else {\n";
2699  g << "if (" << mem_counter << "==CASADI_MAX_NUM_THREADS) {\n";
2700  g.scope_return("-1");
2701  g << "}\n";
2702  g << "mid = " << alloc_mem << "();\n";
2703  g << "if (mid<0) {\n";
2704  g.scope_return("-1");
2705  g << "}\n";
2706  g << "if (" << init_mem << "(mid)) {\n";
2707  g.scope_return("-1");
2708  g << "}\n";
2709  g.scope_return("mid");
2710  g << "}\n";
2711  }
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::FatropInterface::codegen_declarations ( CodeGenerator &  g) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 645 of file fatrop_interface.cpp.

645  {
647  g.add_auxiliary(CodeGenerator::AUX_NLP);
648  g.add_auxiliary(CodeGenerator::AUX_MAX);
649  g.add_auxiliary(CodeGenerator::AUX_COPY);
650  g.add_auxiliary(CodeGenerator::AUX_PROJECT);
651  g.add_auxiliary(CodeGenerator::AUX_SCAL);
652  g.add_auxiliary(CodeGenerator::AUX_SPARSITY);
653  g.add_auxiliary(CodeGenerator::AUX_ORACLE_CALLBACK);
654  g.add_auxiliary(CodeGenerator::AUX_OCP_BLOCK);
655  g.add_auxiliary(CodeGenerator::AUX_DENSIFY);
656  g.add_auxiliary(CodeGenerator::AUX_SPARSIFY);
657  g.add_auxiliary(CodeGenerator::AUX_INF);
658  g.add_auxiliary(CodeGenerator::AUX_SCALED_COPY);
659  g.add_auxiliary(CodeGenerator::AUX_AXPY);
660  g.add_auxiliary(CodeGenerator::AUX_PRINTF);
661  g.add_dependency(get_function("nlp_f"));
662  g.add_dependency(get_function("nlp_grad_f"));
663  g.add_dependency(get_function("nlp_g"));
664  g.add_dependency(get_function("nlp_jac_g"));
665  if (exact_hessian_) {
666  g.add_dependency(get_function("nlp_hess_l"));
667  }
668  g.add_include("fatrop/ocp/OCPCInterface.h");
669 
670  std::string name = "fatrop_cb_write";
671  std::string f = g.shorthand(name);
672 
673  g << "void " << f
674  << "(const char* msg, int num) {\n";
675  g.flush(g.body);
676  g.scope_enter();
677  g << "CASADI_PRINTF(\"%.*s\", num, msg);\n";
678  g.scope_exit();
679  g << "}\n";
680 
681  name = "fatrop_cb_flush";
682  f = g.shorthand(name);
683 
684  g << "void " << f
685  << "(void) {\n";
686  g.flush(g.body);
687  g.scope_enter();
688  g.scope_exit();
689  g << "}\n";
690 }
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
Definition: nlpsol.cpp:1338

References casadi::CodeGenerator::add_auxiliary(), casadi::CodeGenerator::add_dependency(), casadi::CodeGenerator::add_include(), casadi::CodeGenerator::AUX_AXPY, casadi::CodeGenerator::AUX_COPY, casadi::CodeGenerator::AUX_DENSIFY, casadi::CodeGenerator::AUX_INF, casadi::CodeGenerator::AUX_MAX, casadi::CodeGenerator::AUX_NLP, casadi::CodeGenerator::AUX_OCP_BLOCK, casadi::CodeGenerator::AUX_ORACLE_CALLBACK, casadi::CodeGenerator::AUX_PRINTF, casadi::CodeGenerator::AUX_PROJECT, casadi::CodeGenerator::AUX_SCAL, casadi::CodeGenerator::AUX_SCALED_COPY, casadi::CodeGenerator::AUX_SPARSIFY, casadi::CodeGenerator::AUX_SPARSITY, casadi::CodeGenerator::body, casadi::Nlpsol::codegen_declarations(), exact_hessian_, casadi::CodeGenerator::flush(), casadi::OracleFunction::get_function(), casadi::CodeGenerator::scope_enter(), casadi::CodeGenerator::scope_exit(), and casadi::CodeGenerator::shorthand().

◆ 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 2616 of file function_internal.cpp.

2616  {
2617 
2618  // Treat dependent functions
2619  std::set<void*> added;
2620  Function F = shared_from_this<Function>();
2621  for (const Function& f : F.find_functions(0)) {
2622  if (f->has_refcount_in_deps_) {
2623  std::string cg_name = f->codegen_name(g, false);
2624  auto i = added.insert(f.get());
2625  if (i.second) { // prevent duplicate calls
2626  std::string decref = g.shorthand(cg_name + "_decref");
2627  g << decref << "();\n";
2628  }
2629  }
2630  }
2631 
2632  if (has_refcount_) {
2633  std::string name = codegen_name(g, false);
2634  std::string ref_counter = g.shorthand(name + "_ref_counter");
2635  std::string mem_counter = g.shorthand(name + "_mem_counter");
2636  std::string free_mem = g.shorthand(name + "_free_mem");
2637  g << ref_counter << "--;\n";
2638  g << "if (" << ref_counter << "==0) {\n";
2639  if (codegen_needs_mem()) {
2640  g << "while (" << mem_counter << ">0) {\n";
2641  g << free_mem << "(--" << mem_counter << ");\n";
2642  g << "}\n";
2643  }
2644  if (g.thread_safe()) {
2645  Function F = shared_from_this<Function>();
2646  for (const auto& m : g.local_mutexes(F)) {
2647  std::string mtx = g.local_mutex(F, m);
2648  g << "#if CASADI_MUTEX_USE_STATIC_INIT == 0\n";
2649  g << "CASADI_MUTEX_DESTROY(&" << mtx << ");\n";
2650  g << "#endif\n";
2651  }
2652  }
2653  g << "}\n";
2654  }
2655  }
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()

void casadi::FatropInterface::codegen_free_mem ( CodeGenerator &  g) const
overridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 641 of file fatrop_interface.cpp.

641  {
642  g << "casadi_fatrop_free_mem(&" + codegen_mem(g) + ");\n";
643  }

References casadi::FunctionInternal::codegen_mem().

◆ 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 2583 of file function_internal.cpp.

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

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::FatropInterface::codegen_init_mem ( CodeGenerator &  g) const
overridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 636 of file fatrop_interface.cpp.

636  {
637  g << "casadi_fatrop_init_mem(&" + codegen_mem(g) + ");\n";
638  g << "return 0;\n";
639  }

References casadi::FunctionInternal::codegen_mem().

◆ 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 3058 of file function_internal.cpp.

3058  {
3059  std::string name = codegen_name(g, false);
3060  std::string mem_array = g.shorthand(name + "_mem");
3061  return mem_array+"[" + index + "]";
3062  }

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

Referenced by casadi::MadmpecInterface::codegen_body(), casadi::ClarabelInterface::codegen_body(), casadi::DaqpInterface::codegen_body(), 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(), 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(), 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()

std::string casadi::FatropInterface::codegen_mem_type ( ) const
inlineoverridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 178 of file fatrop_interface.hpp.

178 { return "struct casadi_fatrop_data"; }

◆ codegen_meta()

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

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

Definition at line 2733 of file function_internal.cpp.

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

3043  {
3044  if (ns) {
3045  // Get the index of the function
3046  for (auto&& e : g.added_functions_) {
3047  if (e.f.get()==this) return e.codegen_name;
3048  }
3049  } else {
3050  for (casadi_int i=0;i<g.added_functions_.size();++i) {
3051  const auto & e = g.added_functions_[i];
3052  if (e.f.get()==this) return "f" + str(i);
3053  }
3054  }
3055  casadi_error("Function '" + name_ + "' not found");
3056  }

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

Referenced by casadi::FunctionInternal::codegen(), casadi::FunctionInternal::codegen_alloc_mem(), 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()

bool casadi::FatropInterface::codegen_needs_mem ( ) const
inlineoverridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 181 of file fatrop_interface.hpp.

181 { return true; }

◆ codegen_post_solve()

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

Definition at line 1363 of file nlpsol.cpp.

1363  {
1364  if (calc_f_ || calc_g_ || calc_lam_x_ || calc_lam_p_) {
1365  g.local("one", "const casadi_real");
1366  g.init_local("one", "1");
1367  g << "d->arg[0] = " << d_nlp << ".z;\n";
1368  g << "d->arg[1] = " << d_nlp << ".p;\n";
1369  g << "d->arg[2] = &one;\n";
1370  g << "d->arg[3] = " << d_nlp << ".lam+" << str(nx_) << ";\n";
1371  g << "d->res[0] = " << (calc_f_ ? "&" + d_nlp + ".objective" : "0") << ";\n";
1372  g << "d->res[1] = " << (calc_g_ ? d_nlp + ".z+" + str(nx_) : "0") << ";\n";
1373  g << "d->res[2] = " << (calc_lam_x_ ? d_nlp + ".lam+" + str(nx_) : "0") << ";\n";
1374  g << "d->res[3] = " << (calc_lam_p_ ? d_nlp + ".lam_p" : "0") << ";\n";
1375  std::string nlp_grad = g(get_function("nlp_grad"), "d->arg", "d->res", "d->iw", "d->w");
1376  g << "if (" << nlp_grad << ") return 1;\n";
1377  if (calc_lam_x_) g << g.scal(nx_, "-1.0", d_nlp + ".lam") << "\n";
1378  if (calc_lam_p_) g << g.scal(np_, "-1.0", d_nlp + ".lam_p") << "\n";
1379  }
1380  if (bound_consistency_) {
1381  g << g.bound_consistency(nx_+ng_, d_nlp + ".z", d_nlp + ".lam",
1382  d_nlp + ".lbz", d_nlp + ".ubz") << ";\n";
1383  }
1384 
1385  g << g.copy(d_nlp + ".z", nx_, d_nlp + ".x") << "\n";
1386 
1387  if (detect_simple_bounds_is_simple_.empty()) {
1388  g << g.copy(d_nlp + ".z + " + str(nx_), ng_, d_nlp + ".g") << "\n";
1389  g << g.copy(d_nlp + ".lam", nx_, d_nlp + ".lam_x") << "\n";
1390  g << g.copy(d_nlp + ".lam + " + str(nx_), ng_, d_nlp + ".lam_g") << "\n";
1391  } else {
1392  g << "if (casadi_nlpsol_detect_bounds_after(&" << d_nlp << ")) return 1;\n";
1393  }
1394 
1395  g.copy_check("&" + d_nlp + ".objective", 1, d_nlp + ".f", false, true);
1396  g.copy_check(d_nlp + ".lam_p", np_, d_nlp + ".lam_p", false, true);
1397  }
bool calc_lam_p_
Options.
Definition: nlpsol_impl.hpp:97
casadi_int ng_
Number of constraints.
Definition: nlpsol_impl.hpp:69
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
casadi_int np_
Number of parameters.
Definition: nlpsol_impl.hpp:72
bool calc_lam_x_
Options.
Definition: nlpsol_impl.hpp:97
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 2713 of file function_internal.cpp.

2713  {
2714  std::string name = codegen_name(g, false);
2715  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2716  std::string stack = g.shorthand(name + "_unused_stack");
2717 
2718  if (g.thread_safe()) {
2719  Function F = shared_from_this<Function>();
2720  std::string mem_mutex = g.local_mutex(F, name + "_mem_mutex");
2721  g << "CASADI_MUTEX_LOCK(&" << mem_mutex << ");\n";
2722  g.scope_add_cleanup("CASADI_MUTEX_UNLOCK(&" + mem_mutex + ");\n");
2723  }
2724 
2725  g << stack << "[++" << stack_counter << "] = mem;\n";
2726  g.scope_return();
2727  }

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 1271 of file nlpsol.cpp.

1273  {
1274  g << d_nlp << ".oracle = &" << d_oracle << ";\n";
1275  g << d_nlp << ".prob = &" << p_nlp << ";\n";
1276  g << p_nlp << ".nx = " << nx_ << ";\n";
1277  g << p_nlp << ".ng = " << ng_ << ";\n";
1278  g << p_nlp << ".np = " << np_ << ";\n";
1279  g << p_nlp << ".detect_bounds.ng = " << detect_simple_bounds_is_simple_.size() << ";\n";
1280  if (detect_simple_bounds_is_simple_.size()) {
1281  g << p_nlp << ".detect_bounds.sz_arg = " << detect_simple_bounds_parts_.sz_arg() << ";\n";
1282  g << p_nlp << ".detect_bounds.sz_res = " << detect_simple_bounds_parts_.sz_res() << ";\n";
1283  g << p_nlp << ".detect_bounds.sz_iw = " << detect_simple_bounds_parts_.sz_iw() << ";\n";
1284  g << p_nlp << ".detect_bounds.sz_w = " << detect_simple_bounds_parts_.sz_w() << ";\n";
1285 
1286  g << p_nlp << ".detect_bounds.nb = " << detect_simple_bounds_target_x_.size() << ";\n";
1287  g << p_nlp << ".detect_bounds.target_x = "
1288  << g.constant(detect_simple_bounds_target_x_) << ";\n";
1289  g << p_nlp << ".detect_bounds.target_g = "
1290  << g.constant(detect_simple_bounds_target_g_) << ";\n";
1291  g << p_nlp << ".detect_bounds.is_simple = "
1292  << g.constant(detect_simple_bounds_is_simple_) << ";\n";
1293  std::string w =
1294  g.shorthand(g.wrapper(detect_simple_bounds_parts_, "detect_simple_bounds_wrapper"));
1295  g << p_nlp << ".detect_bounds.callback = " << w << ";\n";
1296  g << p_nlp << ".detect_bounds.callback_data = 0;\n";
1297  }
1298  }
size_t sz_res() const
Get the length of the output pointer array needed to evaluate (at least.
Definition: function.cpp:1237
size_t sz_iw() const
Get the length of the integer work vector needed to evaluate.
Definition: function.cpp:1239
size_t sz_w() const
Get the length of the real work vector needed to evaluate.
Definition: function.cpp:1241
size_t sz_arg() const
Get the length of the input pointer array needed to evaluate (at least n_in)
Definition: function.cpp:1235
Function detect_simple_bounds_parts_
Definition: nlpsol_impl.hpp:85
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 1303 of file nlpsol.cpp.

1303  {
1304  g << d_nlp << ".p = arg[" << NLPSOL_P << "];\n";
1305  g << d_nlp << ".lbx = arg[" << NLPSOL_LBX << "];\n";
1306  g << d_nlp << ".ubx = arg[" << NLPSOL_UBX << "];\n";
1307  g << d_nlp << ".lbg = arg[" << NLPSOL_LBG << "];\n";
1308  g << d_nlp << ".ubg = arg[" << NLPSOL_UBG << "];\n";
1309  g << d_nlp << ".x0 = arg[" << NLPSOL_X0 << "];\n";
1310  g << d_nlp << ".lam_x0 = arg[" << NLPSOL_LAM_X0 << "];\n";
1311  g << d_nlp << ".lam_g0 = arg[" << NLPSOL_LAM_G0 << "];\n";
1312  g << "arg += " << NLPSOL_NUM_IN << ";\n";
1313 
1314  g << d_nlp << ".x = res[" << NLPSOL_X << "];\n";
1315  g << d_nlp << ".f = res[" << NLPSOL_F << "];\n";
1316  g << d_nlp << ".g = res[" << NLPSOL_G << "];\n";
1317  g << d_nlp << ".lam_x = res[" << NLPSOL_LAM_X << "];\n";
1318  g << d_nlp << ".lam_g = res[" << NLPSOL_LAM_G << "];\n";
1319  g << d_nlp << ".lam_p = res[" << NLPSOL_LAM_P << "];\n";
1320  g << "res += " << NLPSOL_NUM_OUT << ";\n";
1321 
1322  g << "casadi_nlpsol_set_work(&" << d_nlp << ", &arg, &res, &iw, &w);\n";
1323 
1324  g.copy_default(d_nlp + ".x0", nx_, d_nlp + ".z", "0", false);
1325  g.copy_default(d_nlp + ".lbx", nx_, d_nlp + ".lbz", "-casadi_inf", false);
1326  g.copy_default(d_nlp + ".ubx", nx_, d_nlp + ".ubz", "casadi_inf", false);
1327  g.copy_default(d_nlp + ".lam_x0", nx_, d_nlp + ".lam", "0", false);
1328 
1329  if (detect_simple_bounds_is_simple_.empty()) {
1330  g.copy_default(d_nlp + ".lbg", ng_, d_nlp + ".lbz+" + str(nx_), "-casadi_inf", false);
1331  g.copy_default(d_nlp + ".ubg", ng_, d_nlp + ".ubz+" + str(nx_), "casadi_inf", false);
1332  g.copy_default(d_nlp + ".lam_g0", ng_, d_nlp + ".lam+" + str(nx_), "0", false);
1333  } else {
1334  g << "if (casadi_nlpsol_detect_bounds_before(&" << d_nlp << ")) return 1;\n";
1335  }
1336  }
@ NLPSOL_P
Value of fixed parameters (np x 1), default 0.
Definition: nlpsol.hpp:835
@ NLPSOL_LAM_G0
Lagrange multipliers for bounds on G, initial guess (ng x 1), default 0.
Definition: nlpsol.hpp:847
@ NLPSOL_LAM_X0
Lagrange multipliers for bounds on X, initial guess (nx x 1), default 0.
Definition: nlpsol.hpp:845
@ NLPSOL_NUM_IN
Definition: nlpsol.hpp:848
@ NLPSOL_NUM_OUT
Definition: nlpsol.hpp:867
@ NLPSOL_LAM_P
Definition: nlpsol.hpp:866

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 3165 of file function_internal.cpp.

3165  {
3166  return sz_arg();
3167  }

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 3171 of file function_internal.cpp.

3171  {
3172  return sz_iw();
3173  }

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 3168 of file function_internal.cpp.

3168  {
3169  return sz_res();
3170  }

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 3174 of file function_internal.cpp.

3174  {
3175  return sz_w();
3176  }

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 1902 of file function_internal.hpp.

1903  {
1904  // Get default inputs
1905  std::vector<M> arg_v(n_in_);
1906  for (casadi_int i=0; i<arg_v.size(); ++i) {
1907  arg_v[i] = get_default_in(i);
1908  }
1909 
1910  // Assign provided inputs
1911  for (auto&& e : arg) {
1912  arg_v.at(index_in(e.first)) = e.second;
1913  }
1914 
1915  return arg_v;
1916  }
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 1890 of file function_internal.hpp.

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

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 1931 of file function_internal.hpp.

1932  {
1933  // Get default inputs
1934  std::vector<M> res_v(n_out_);
1935  for (casadi_int i=0; i<res_v.size(); ++i) {
1936  res_v[i] = std::numeric_limits<double>::quiet_NaN();
1937  }
1938 
1939  // Assign provided inputs
1940  for (auto&& e : res) {
1941  M a = e.second;
1942  res_v.at(index_out(e.first)) = a;
1943  }
1944  return res_v;
1945  }
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 1919 of file function_internal.hpp.

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

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::RuntimeIntegrator::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
Build a function computing derivatives by naming inputs and outputs.
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::RuntimeIntegrator::init(), casadi::AlpaqaInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), casadi::ConoptInterface::init(), 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 207 of file nlpsol.cpp.

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

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::FatropInterface::creator ( const std::string &  name,
const Function &  nlp 
)
inlinestatic

Definition at line 113 of file fatrop_interface.hpp.

113  {
114  return new FatropInterface(name, nlp);
115  }
FatropInterface(const std::string &name, const Function &nlp)

Referenced by casadi::casadi_register_nlpsol_fatrop().

◆ 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 1141 of file function_internal.cpp.

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

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::FatropInterface::deserialize ( DeserializingStream &  s)
inlinestatic

Definition at line 187 of file fatrop_interface.hpp.

187 { return new FatropInterface(s); }

Referenced by casadi::casadi_register_nlpsol_fatrop().

◆ 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 2249 of file function_internal.cpp.

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

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 1162 of file function_internal.cpp.

1162  {
1163  stream << definition() << " " << class_name();
1164  if (more) {
1165  stream << std::endl;
1166  disp_more(stream);
1167  }
1168  }
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 943 of file nlpsol.cpp.

943  {
944  stream << "minimize f(x;p) subject to lbx<=x<=ubx, lbg<=g(x;p)<=ubg defined by:\n";
945  oracle_.disp(stream, true);
946  }
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 3583 of file function_internal.cpp.

3583  {
3584  std::vector<DM> ret(n_in_);
3585  for (casadi_int i=0; i<ret.size(); ++i) {
3586  ret[i] = dm_in(i);
3587  }
3588  return ret;
3589  }
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 3591 of file function_internal.cpp.

3591  {
3592  std::vector<DM> ret(n_out_);
3593  for (casadi_int i=0; i<ret.size(); ++i) {
3594  ret[i] = dm_out(i);
3595  }
3596  return ret;
3597  }
const std::vector< DM > dm_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

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

◆ dm_out() [2/2]

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

◆ ensure_stacked()

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

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

Definition at line 1948 of file function_internal.hpp.

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

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 805 of file nlpsol.cpp.

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

3081  {
3082  // Sound fallback: we cannot prove any output zero, so mark everything active
3083  for (casadi_int oind=0; oind<n_out_; ++oind) {
3084  if (res[oind]==nullptr) continue;
3085  std::fill_n(res[oind], nnz_out(oind), ~static_cast<bvec_t>(0));
3086  }
3087  return 0;
3088  }
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 2232 of file function_internal.cpp.

2232  {
2233  casadi_error("'eval_dm' not defined for " + class_name());
2234  }

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 1029 of file function_internal.cpp.

1031  {
1032  casadi_int dump_id = (dump_in_ || dump_out_ || dump_) ? get_dump_id() : -1;
1033  if (dump_in_) dump_in(dump_id, arg);
1034  if (dump_ && dump_id==0) dump();
1035  if (print_in_) print_in(uout(), arg, false);
1036  auto *m = static_cast<FunctionMemory*>(mem);
1037 
1038  // Avoid memory corruption
1039  for (casadi_int i=0;i<n_in_;++i) {
1040  casadi_assert(arg[i]==nullptr || arg[i]+nnz_in(i)<=w || arg[i]>=w+sz_w(),
1041  "Memory corruption detected for input " + name_in_[i] + ".\n"+
1042  "arg[" + str(i) + "] " + str(arg[i]) + "-" + str(arg[i]+nnz_in(i)) +
1043  " intersects with w " + str(w)+"-"+str(w+sz_w())+".");
1044  }
1045  for (casadi_int i=0;i<n_out_;++i) {
1046  casadi_assert(res[i]==nullptr || res[i]+nnz_out(i)<=w || res[i]>=w+sz_w(),
1047  "Memory corruption detected for output " + name_out_[i]);
1048  }
1049  // Reset statistics
1050  for (auto&& s : m->fstats) s.second.reset();
1051  if (m->t_total) m->t_total->tic();
1052  m->dump_id = dump_id;
1053  int ret;
1054  if (eval_) {
1055  auto *m = static_cast<FunctionMemory*>(mem);
1056  m->stats_available = true;
1057  int mem_ = 0;
1058  if (checkout_) {
1059 #ifdef CASADI_WITH_THREAD
1060  std::lock_guard<std::mutex> lock(mtx_);
1061 #endif //CASADI_WITH_THREAD
1062  mem_ = checkout_();
1063  }
1064  ret = eval_(arg, res, iw, w, mem_);
1065  if (release_) {
1066 #ifdef CASADI_WITH_THREAD
1067  std::lock_guard<std::mutex> lock(mtx_);
1068 #endif //CASADI_WITH_THREAD
1069  release_(mem_);
1070  }
1071  } else {
1072  ret = eval(arg, res, iw, w, mem);
1073  }
1074  if (m->t_total) m->t_total->toc();
1075  // Show statistics
1076  print_time(m->fstats);
1077 
1078  if (dump_out_) dump_out(dump_id, res);
1079  if (print_out_) print_out(uout(), res, false);
1080  // Check all outputs for NaNs
1081  if (regularity_check_) {
1082  for (casadi_int i = 0; i < n_out_; ++i) {
1083  // Skip of not calculated
1084  if (!res[i]) continue;
1085  // Loop over nonzeros
1086  casadi_int nnz = this->nnz_out(i);
1087  for (casadi_int nz = 0; nz < nnz; ++nz) {
1088  if (isnan(res[i][nz]) || isinf(res[i][nz])) {
1089  // Throw readable error message
1090  casadi_error(str(res[i][nz]) + " detected for output " + name_out_[i] + " at "
1091  + sparsity_out(i).repr_el(nz));
1092  }
1093  }
1094  }
1095  }
1096  return ret;
1097  }
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.
std::ostream & uout()

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

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

◆ eval_gen() [3/3]

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

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

Definition at line 444 of file function_internal.hpp.

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

◆ eval_mx()

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

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

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

Definition at line 2451 of file function_internal.cpp.

2452  {
2453 
2454  always_inline = always_inline || always_inline_;
2455  never_inline = never_inline || never_inline_;
2456 
2457  // The code below creates a call node, to inline, wrap in an MXFunction
2458  if (always_inline) {
2459  casadi_assert(!never_inline, "Inconsistent options for " + str(name_));
2460  wrap().call(arg, res, true);
2461  return;
2462  }
2463 
2464  // Create a call-node
2465  res = Call::create(self(), arg);
2466  }
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 with a list or a dict of arguments; the result has the same form.
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 2236 of file function_internal.cpp.

2238  {
2239 
2240  always_inline = always_inline || always_inline_;
2241  never_inline = never_inline || never_inline_;
2242 
2243  casadi_assert(!always_inline, "'eval_sx' not defined for " + class_name() +
2244  " in combination with always_inline true");
2245 
2246  return CallSX::eval_sx(self(), arg, res);
2247  }
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 459 of file oracle_function.cpp.

459  {
460  oracle_ = oracle_.expand();
461 }
Function expand() const
Convert an MXFunction into an equivalent SXFunction.
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 552 of file oracle_function.cpp.

553  {
554  // Call to base class
555  FunctionInternal::find(all_fun, max_depth);
556  for (auto&& e : all_functions_) {
557  add_embedded(all_fun, e.second.f, max_depth);
558  }
559 }
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 875 of file function_internal.cpp.

876  {
877  if (ret == 0) {
878  trace << "{\"event\":\"outputs\",\"values\":[";
879  for (casadi_int i = 0; i < n_out_; ++i) {
880  if (i) trace << ",";
881  trace_values(trace, res[i], nnz_out(i));
882  }
883  trace << "]}\n";
884  }
885  trace << "{\"event\":\"end\",\"status\":" << ret << "}\n";
886  trace.flush();
887  casadi_assert(trace.good(), "Failed to write dump_trace for '" + name_ + "'");
888  }
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 4129 of file function_internal.cpp.

4129  {
4130  // Always of width 8
4131  casadi_assert_dev(time>=0);
4132  double log_time = log10(time);
4133  int magn = static_cast<int>(floor(log_time));
4134  int iprefix = static_cast<int>(floor(log_time/3));
4135  if (iprefix<-4) {
4136  sprint(buffer, 10, " 0");
4137  return;
4138  }
4139  if (iprefix>=5) {
4140  sprint(buffer, 10, " inf");
4141  return;
4142  }
4143  char prefixes[] = "TGMk munp";
4144  char prefix = prefixes[4-iprefix];
4145 
4146  int rem = magn-3*iprefix;
4147  double time_normalized = time/pow(10, 3*iprefix);
4148 
4149  if (rem==0) {
4150  sprint(buffer, 10, " %1.2f%cs", time_normalized, prefix);
4151  } else if (rem==1) {
4152  sprint(buffer, 10, " %2.2f%cs", time_normalized, prefix);
4153  } else {
4154  sprint(buffer, 10, "%3.2f%cs", time_normalized, prefix);
4155  }
4156  }
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 2285 of file function_internal.cpp.

2285  {
2286  casadi_assert_dev(nfwd>=0);
2287  // Used wrapped function if forward not available
2288  if (!enable_forward_ && !enable_fd_) {
2289  // Derivative information must be available
2290  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2291  return wrap().forward(nfwd);
2292  }
2293  // Retrieve/generate cached
2294  Function f;
2295  std::string fname = forward_name(name_, nfwd);
2296  if (!incache(fname, f)) {
2297  casadi_int i;
2298  // Prefix to be used for forward seeds, sensitivities
2299  std::string pref = diff_prefix("fwd");
2300  // Names of inputs
2301  std::vector<std::string> inames;
2302  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2303  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2304  for (i=0; i<n_in_; ++i) inames.push_back(pref + name_in_[i]);
2305  // Names of outputs
2306  std::vector<std::string> onames;
2307  for (i=0; i<n_out_; ++i) onames.push_back(pref + name_out_[i]);
2308  // Options
2310  if (enable_forward_) {
2311  opts = combine(opts, generate_options("forward"));
2312  } else {
2313  opts = combine(opts, FunctionInternal::generate_options("forward"));
2314  }
2315  opts["derivative_of"] = self();
2316  // Generate derivative function
2317  casadi_assert_dev(enable_forward_ || enable_fd_);
2318  if (enable_forward_) {
2319  f = get_forward(nfwd, fname, inames, onames, opts);
2320  } else {
2321  opts = combine(opts, fd_options_);
2322  // Get FD method
2323  if (fd_method_.empty() || fd_method_=="central") {
2324  f = Function::create(new CentralDiff(fname, nfwd), opts);
2325  } else if (fd_method_=="forward") {
2326  f = Function::create(new ForwardDiff(fname, nfwd), opts);
2327  } else if (fd_method_=="backward") {
2328  f = Function::create(new BackwardDiff(fname, nfwd), opts);
2329  } else if (fd_method_=="smoothing") {
2330  f = Function::create(new Smoothing(fname, nfwd), opts);
2331  } else {
2332  casadi_error("Unknown 'fd_method': " + fd_method_);
2333  }
2334  }
2335  // Consistency check for inputs
2336  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_in_);
2337  casadi_int ind=0;
2338  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2339  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2340  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), nfwd*size2_in(i));
2341  // Consistency check for outputs
2342  casadi_assert_dev(f.n_out()==n_out_);
2343  for (i=0; i<n_out_; ++i) f.assert_sparsity_out(i, sparsity_out(i), nfwd);
2344  // Save to cache
2345  tocache_if_missing(f);
2346  }
2347  return f;
2348  }
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 computing nfwd forward directional 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::FatropInterface::free_mem ( void *  mem) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 531 of file fatrop_interface.cpp.

531  {
532  auto m = static_cast<FatropMemory*>(mem);
533  casadi_fatrop_free_mem(&m->d);
534  delete static_cast<FatropMemory*>(mem);
535  }

◆ free_mx()

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

Reimplemented in casadi::MXFunction.

Definition at line 3631 of file function_internal.cpp.

3631  {
3632  casadi_error("'free_mx' only defined for 'MXFunction'");
3633  }

◆ free_sx()

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

Reimplemented in casadi::SXFunction.

Definition at line 3635 of file function_internal.cpp.

3635  {
3636  casadi_error("'free_sx' only defined for 'SXFunction'");
3637  }

◆ from_compact()

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

Definition at line 2050 of file function_internal.cpp.

2051  {
2052  // Return value
2053  Sparsity r = sp;
2054  // Insert rows if sparse output
2055  if (numel_out(oind) != r.size1()) {
2056  casadi_assert_dev(r.size1() == nnz_out(oind));
2057  r.enlargeRows(numel_out(oind), sparsity_out(oind).find());
2058  }
2059  // Insert columns if sparse input
2060  if (numel_in(iind) != r.size2()) {
2061  casadi_assert_dev(r.size2() == nnz_in(iind));
2062  r.enlargeColumns(numel_in(iind), sparsity_in(iind).find());
2063  }
2064  // Return non-compact pattern
2065  return r;
2066  }
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 1585 of file function_internal.hpp.

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

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 3246 of file function_internal.cpp.

3246  {
3247  if (!enable_forward_ && !enable_fd_) return true;
3248  if (jac_penalty_==-1) return false;
3249 
3250  // Heuristic 1: Jac calculated via forward mode likely cheaper
3251  if (jac_penalty_*static_cast<double>(nnz_in())<nfwd) return true;
3252 
3253  // Heuristic 2: Jac calculated via reverse mode likely cheaper
3254  double w = ad_weight();
3255  if (enable_reverse_ &&
3256  jac_penalty_*(1-w)*static_cast<double>(nnz_out())<w*static_cast<double>(nfwd))
3257  return true; // NOLINT
3258 
3259  return false;
3260  }

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 431 of file oracle_function.cpp.

432  {
433  CodeGenerator gen(fname, opts);
434  gen.add(oracle_);
435  for (auto&& e : all_functions_) {
436  // After jit_dependencies, f is the loaded External: generate from the original
437  if (e.second.jit) gen.add(e.second.f_original.is_null() ? e.second.f : e.second.f_original);
438  }
439  return gen.generate();
440 }

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 801 of file function_internal.cpp.

801  {
802  // Set up output stream
803  auto of_ptr = Filesystem::ofstream_ptr(fname);
804  std::ostream& of = *of_ptr;
805  normalized_setup(of);
806 
807  // Encode each input
808  for (casadi_int i=0; i<n_in_; ++i) {
809  const double* v = arg[i];
810  for (casadi_int k=0;k<nnz_in(i);++k) {
811  normalized_out(of, v ? v[k] : 0);
812  of << std::endl;
813  }
814  }
815  }
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 3639 of file function_internal.cpp.

3640  {
3641  casadi_error("'generate_lifted' only defined for 'MXFunction'");
3642  }

◆ 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 393 of file function_internal.cpp.

393  {
394  Dict opts = ProtoFunction::generate_options(target);
395  opts["jac_penalty"] = jac_penalty_;
396  opts["user_data"] = user_data_;
397  opts["inputs_check"] = inputs_check_;
398  if (target!="tmp") opts["jit"] = jit_;
399  opts["jit_cleanup"] = jit_cleanup_;
400  opts["jit_serialize"] = jit_serialize_;
401  opts["compiler"] = compiler_plugin_;
402  opts["jit_options"] = jit_options_;
403  opts["codegen_options"] = codegen_options_;
404  opts["jit_name"] = jit_base_name_;
405  opts["jit_temp_suffix"] = jit_temp_suffix_;
406  opts["ad_weight"] = ad_weight_;
407  opts["ad_weight_sp"] = ad_weight_sp_;
408  opts["always_inline"] = always_inline_;
409  opts["never_inline"] = never_inline_;
410  opts["max_num_dir"] = max_num_dir_;
411  if (target=="clone" || target=="tmp") {
412  opts["enable_forward"] = enable_forward_op_;
413  opts["enable_reverse"] = enable_reverse_op_;
414  opts["enable_jacobian"] = enable_jacobian_op_;
415  opts["enable_fd"] = enable_fd_op_;
416  opts["reverse_options"] = reverse_options_;
417  opts["forward_options"] = forward_options_;
418  opts["jacobian_options"] = jacobian_options_;
419  opts["der_options"] = der_options_;
420  opts["derivative_of"] = derivative_of_;
421  }
422  opts["fd_options"] = fd_options_;
423  opts["fd_method"] = fd_method_;
424  opts["print_in"] = print_in_;
425  opts["print_out"] = print_out_;
426  opts["print_canonical"] = print_canonical_;
427  opts["max_io"] = max_io_;
428  opts["dump_in"] = dump_in_;
429  opts["dump_out"] = dump_out_;
430  opts["dump_dir"] = dump_dir_;
431  opts["dump_format"] = dump_format_;
432  opts["dump"] = dump_;
433  if (target=="clone") {
434  opts["is_diff_in"] = is_diff_in_;
435  opts["is_diff_out"] = is_diff_out_;
436  }
437  if (target=="forward") {
438  opts["is_diff_in"] = join(is_diff_in_, is_diff_out_, is_diff_in_);
439  opts["is_diff_out"] = is_diff_out_;
440  }
441  if (target=="reverse") {
442  opts["is_diff_in"] = join(is_diff_in_, is_diff_out_, is_diff_out_);
443  opts["is_diff_out"] = is_diff_in_;
444  }
445  return opts;
446  }
std::string jit_serialize_
Serialize behaviour.
std::string compiler_plugin_
Just-in-time compiler.
void * user_data_
User-set field.
Dict codegen_options_
Options of the code generator of jit.
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::codegen_options_, 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 817 of file function_internal.cpp.

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

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 205 of file nlpsol_impl.hpp.

205 { return nlpsol_default_in(ind);}
double nlpsol_default_in(casadi_int ind)
Default value of an NLP solver input.
Definition: nlpsol.cpp:296

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 969 of file nlpsol.cpp.

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

References 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_force_equality_, casadi::Conic::sens_kkt(), 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 1136 of file function_internal.cpp.

1136  {
1137  casadi_assert_dev(!has_free());
1138  return std::vector<std::string>();
1139  }
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 535 of file oracle_function.cpp.

535  {
536  std::vector<std::string> ret;
537  ret.reserve(all_functions_.size());
538  for (auto&& e : all_functions_) {
539  ret.push_back(e.first);
540  }
541  return ret;
542 }

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(), 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(), casadi::ConoptInterface::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(), init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), casadi::FastNewton::init(), casadi::Feasiblesqpmethod::init(), casadi::Sqpmethod::init(), casadi::RuntimeIntegrator::jump_function(), casadi::OracleFunction::monitored(), casadi::MadmpecInterface::set_ccopt_prob(), set_fatrop_prob(), casadi::IpoptInterface::set_ipopt_prob(), casadi::MadnlpInterface::set_madnlp_prob(), casadi::RuntimeIntegrator::set_nominal_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 544 of file oracle_function.cpp.

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

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 1993 of file function_internal.cpp.

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

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

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 1678 of file function_internal.cpp.

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

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

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 717 of file function_internal.cpp.

717  {
718  // Start with default temp work dir
719  std::string jit_directory = GlobalOptions::getTempWorkDir();
720 
721  // Get user-specified directory
722  std::string directory;
723  directory = get_from_dict(jit_options, "directory", std::string(""));
724 
725  // What if directory itself is absolute?
726  if (Filesystem::is_absolute(directory)) {
727  // Override
728  jit_directory = directory;
729  } else {
730  jit_directory = jit_directory + directory;
731  if (Filesystem::is_enabled()) {
732  jit_directory = Filesystem::absolute(jit_directory);
733  }
734  }
735 
736  return Filesystem::ensure_trailing_slash(jit_directory);
737  }
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 146 of file nlpsol_impl.hpp.

146 { 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 147 of file nlpsol_impl.hpp.

147 { 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 162 of file nlpsol_impl.hpp.

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

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 163 of file nlpsol_impl.hpp.

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

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::FatropInterface::get_options ( ) const
inlineoverridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 120 of file fatrop_interface.hpp.

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

◆ get_partition()

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

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

Definition at line 2133 of file function_internal.cpp.

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

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

References 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_force_equality_, casadi::Conic::sens_kkt(), 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 379 of file nlpsol.cpp.

379  {
380  switch (static_cast<NlpsolInput>(i)) {
381  case NLPSOL_X0:
382  case NLPSOL_LBX:
383  case NLPSOL_UBX:
384  case NLPSOL_LAM_X0:
385  return get_sparsity_out(NLPSOL_X);
386  case NLPSOL_LBG:
387  case NLPSOL_UBG:
388  case NLPSOL_LAM_G0:
389  return get_sparsity_out(NLPSOL_G);
390  case NLPSOL_P:
391  return oracle_.sparsity_in(NL_P);
392  case NLPSOL_NUM_IN: break;
393  }
394  return Sparsity();
395  }
const Sparsity & sparsity_in(casadi_int ind) const
Get the sparsity pattern of an input, by index or name.
Definition: function.cpp:1167
Sparsity get_sparsity_out(casadi_int i) override
Sparsities of function inputs and outputs.
Definition: nlpsol.cpp:397

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 397 of file nlpsol.cpp.

397  {
398  switch (static_cast<NlpsolOutput>(i)) {
399  case NLPSOL_F:
400  return oracle_.sparsity_out(NL_F);
401  case NLPSOL_X:
402  case NLPSOL_LAM_X:
403  return oracle_.sparsity_in(NL_X);
404  case NLPSOL_LAM_G:
405  case NLPSOL_G:
406  if (detect_simple_bounds_is_simple_.empty()) {
407  return oracle_.sparsity_out(NL_G);
408  } else {
410  }
411  case NLPSOL_LAM_P:
412  return get_sparsity_in(NLPSOL_P);
413  case NLPSOL_NUM_OUT: break;
414  }
415  return Sparsity();
416  }
const Sparsity & sparsity_out(casadi_int ind) const
Get the sparsity pattern of an output, by index or name.
Definition: function.cpp:1183
Sparsity get_sparsity_in(casadi_int i) override
Sparsities of function inputs and outputs.
Definition: nlpsol.cpp:379
NlpsolOutput
Output arguments of an NLP Solver.
Definition: nlpsol.hpp:852

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

Reimplemented from casadi::Nlpsol.

Definition at line 606 of file fatrop_interface.cpp.

606  {
607  Dict stats = Nlpsol::get_stats(mem);
608  auto m = static_cast<FatropMemory*>(mem);
609  Dict fatrop;
610  fatrop["compute_sd_time"] = m->d.stats.compute_sd_time;
611  fatrop["duinf_time"] = m->d.stats.duinf_time;
612  fatrop["eval_hess_time"] = m->d.stats.eval_hess_time;
613  fatrop["eval_jac_time"] = m->d.stats.eval_jac_time;
614  fatrop["eval_cv_time"] = m->d.stats.eval_cv_time;
615  fatrop["eval_grad_time"] = m->d.stats.eval_grad_time;
616  fatrop["eval_obj_time"] = m->d.stats.eval_obj_time;
617  fatrop["initialization_time"] = m->d.stats.initialization_time;
618  fatrop["time_total"] = m->d.stats.time_total;
619  fatrop["eval_hess_count"] = m->d.stats.eval_hess_count;
620  fatrop["eval_jac_count"] = m->d.stats.eval_jac_count;
621  fatrop["eval_cv_count"] = m->d.stats.eval_cv_count;
622  fatrop["eval_grad_count"] = m->d.stats.eval_grad_count;
623  fatrop["eval_obj_count"] = m->d.stats.eval_obj_count;
624  fatrop["iterations_count"] = m->d.stats.iterations_count;
625  fatrop["return_flag"] = m->d.stats.return_flag;
626  stats["fatrop"] = fatrop;
627  stats["iter_count"] = m->d.stats.iterations_count;
628  stats["nx"] = nxs_;
629  stats["nu"] = nus_;
630  stats["ng"] = ngs_;
631  stats["N"] = N_;
632  stats["return_status"] = m->d.return_status;
633  return stats;
634  }
Dict get_stats(void *mem) const override
Get all statistics.
Definition: nlpsol.cpp:1241

References casadi::FatropMemory::d, casadi::Nlpsol::get_stats(), and casadi_fatrop_data< T1 >::stats.

◆ 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 770 of file nlpsol.cpp.

770  {
771  casadi_error("getReducedHessian not defined for class " + class_name());
772  return DM();
773  }
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 268 of file nlpsol_impl.hpp.

268 { 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 3919 of file function_internal.cpp.

3919  {
3920  return ind<mem_.size();
3921  }

◆ 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 1120 of file function_internal.cpp.

1120  {
1121  return get_options().find(option_name) != nullptr;
1122  }
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 279 of file nlpsol_impl.hpp.

279 { 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::FatropInterface::init ( const Dict &  opts)
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 135 of file fatrop_interface.cpp.

135  {
136  // Call the init method of the base class
137  Nlpsol::init(opts);
138 
139  casadi_int struct_cnt=0;
140 
141  // Default options
142  std::string convexify_strategy = "none";
143  double convexify_margin = 1e-7;
144  casadi_int max_iter_eig = 200;
145  structure_detection_ = STRUCTURE_NONE;
146  debug_ = false;
147 
148  calc_g_ = true;
149  calc_f_ = true;
150 
151  // Read options
152  for (auto&& op : opts) {
153  if (op.first=="N") {
154  N_ = op.second;
155  struct_cnt++;
156  } else if (op.first=="nx") {
157  nxs_ = op.second;
158  struct_cnt++;
159  } else if (op.first=="nu") {
160  nus_ = op.second;
161  struct_cnt++;
162  } else if (op.first=="ng") {
163  ngs_ = op.second;
164  struct_cnt++;
165  } else if (op.first=="convexify_strategy") {
166  convexify_strategy = op.second.to_string();
167  } else if (op.first=="convexify_margin") {
168  convexify_margin = op.second;
169  } else if (op.first=="max_iter_eig") {
170  max_iter_eig = op.second;
171  } else if (op.first=="fatrop") {
172  opts_ = op.second;
173  } else if (op.first=="structure_detection") {
174  std::string v = op.second;
175  if (v=="auto") {
176  structure_detection_ = STRUCTURE_AUTO;
177  } else if (v=="manual") {
178  structure_detection_ = STRUCTURE_MANUAL;
179  } else if (v=="none") {
180  structure_detection_ = STRUCTURE_NONE;
181  } else {
182  casadi_error("Unknown option for structure_detection: '" + v + "'.");
183  }
184  } else if (op.first=="debug") {
185  debug_ = op.second;
186  }
187  }
188 
189  // Do we need second order derivatives?
190  exact_hessian_ = true;
191  auto hessian_approximation = opts_.find("hessian_approximation");
192  if (hessian_approximation!=opts_.end()) {
193  exact_hessian_ = hessian_approximation->second == "exact";
194  }
195 
196  // Setup NLP functions
197  create_function("nlp_f", {"x", "p"}, {"f"});
198  create_function("nlp_g", {"x", "p"}, {"g"});
199  if (!has_function("nlp_grad_f")) {
200  create_function("nlp_grad_f", {"x", "p"}, {"grad:f:x"});
201  }
202  if (!has_function("nlp_jac_g")) {
203  create_function("nlp_jac_g", {"x", "p"}, {"g", "jac:g:x"});
204  }
205  jacg_sp_ = get_function("nlp_jac_g").sparsity_out(1);
206 
207  convexify_ = false;
208 
209  // Allocate temporary work vectors
210  if (exact_hessian_) {
211  if (!has_function("nlp_hess_l")) {
212  create_function("nlp_hess_l", {"x", "p", "lam:f", "lam:g"},
213  {"grad:gamma:x", "hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
214  }
215  hesslag_sp_ = get_function("nlp_hess_l").sparsity_out(1);
216  casadi_assert(hesslag_sp_.is_symmetric(), "Hessian must be symmetric");
217  if (convexify_strategy!="none") {
218  convexify_ = true;
219  Dict opts;
220  opts["strategy"] = convexify_strategy;
221  opts["margin"] = convexify_margin;
222  opts["max_iter_eig"] = max_iter_eig;
223  opts["verbose"] = verbose_;
225  }
226  }
227 
228  const std::vector<casadi_int>& nx = nxs_;
229  const std::vector<casadi_int>& ng = ngs_;
230  const std::vector<casadi_int>& nu = nus_;
231 
232  Sparsity lamg_csp_, lam_ulsp_, lam_uusp_, lam_xlsp_, lam_xusp_, lam_clsp_;
233 
234  const Sparsity& A_ = jacg_sp_;
235  if (debug_) {
236  A_.to_file("debug_fatrop_actual.mtx");
237  }
238  // Keep list of erroring rows
239  std::set<casadi_int> errors;
240 
241  casadi_int na_ = A_.size1(); //TODO(jgillis): replace with ng
242 
243  if (struct_cnt>0) {
244  casadi_assert(structure_detection_ == STRUCTURE_MANUAL,
245  "You must set structure_detection to 'manual' if you set N, nx, nu, ng.");
246  }
247 
248  if (structure_detection_==STRUCTURE_MANUAL) {
249  casadi_assert(struct_cnt==4,
250  "You must set all of N, nx, nu, ng.");
251  } else if (structure_detection_==STRUCTURE_NONE) {
252  N_ = 0;
253  nxs_ = {0};
254  nus_ = {nx_};
255  ngs_ = {ng_};
256  } else if (structure_detection_==STRUCTURE_AUTO) {
257  casadi_assert(!equality_.empty(),
258  "Structure detection auto requires the 'equality' option to be set");
259  /* General strategy: look for the xk+1 diagonal part in A
260  */
261 
262  // Find the right-most column for each row in A -> A_skyline
263  // Find the second-to-right-most column -> A_skyline2
264  // Find the left-most column -> A_bottomline
265  Sparsity AT = A_.T();
266  std::vector<casadi_int> A_skyline;
267  std::vector<casadi_int> A_skyline2;
268  std::vector<casadi_int> A_bottomline;
269 
270  std::vector<casadi_int> AT_colind = AT.get_colind();
271  std::vector<casadi_int> AT_row = AT.get_row();
272  for (casadi_int i=0;i<AT.size2();++i) {
273  casadi_int pivot = AT_colind.at(i+1);
274  if (pivot>AT_colind.at(i)) {
275  A_bottomline.push_back(AT_row.at(AT_colind.at(i)));
276  } else {
277  A_bottomline.push_back(-1);
278  }
279  if (pivot>AT_colind.at(i)) {
280  A_skyline.push_back(AT_row.at(pivot-1));
281  if (pivot>AT_colind.at(i)+1) {
282  A_skyline2.push_back(AT_row.at(pivot-2));
283  } else {
284  A_skyline2.push_back(-1);
285  }
286  } else {
287  A_skyline.push_back(-1);
288  A_skyline2.push_back(-1);
289  }
290  }
291 
292  casadi_assert(equality_[0],
293  "Constraint Jcobian must start with gap-closing constraint "
294  "(tagged 'true' in equality vector).");
295 
296  casadi_int pivot = A_skyline[0]; // Current right-most element
297  casadi_int start_pivot = pivot; // First right-most element that started the stage
298  casadi_int prev_start_pivot = 0;
299 
300  bool walking = true;
301 
302  nxs_.push_back(1);
303  nus_.push_back(0);
304  ngs_.push_back(0);
305  for (casadi_int i=1;i<na_;++i) { // Loop over all rows
306  bool is_gap_closing = true;
307  if (A_bottomline[i]!=-1 && A_bottomline[i]<prev_start_pivot) {
308  errors.insert(i);
309  report_issue(i, "Constraint found depending on a state of the previous interval.");
310  }
311  if (equality_[i]) {
312  // A candidate for a gap-closing constraint must tagged as equality
313  if (A_skyline[i]>pivot+1) { // Jump to a diagonal in the future
314  if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
315  errors.insert(i);
316  report_issue(i, "Constraint found depending on a state of the previous interval.");
317  }
318  //if (A_bottomline[i]<start_pivot || A_bottomline[i]>pivot) {
319  // errors.insert(i);
320  // report_issue(i, "Gap-closing constraint must depend on a state.");
321  //}
322  nxs_.push_back(1);
323  nus_.push_back(A_skyline[i]-pivot-1); // Size of jump equals number of states
324  ngs_.push_back(0);
325  prev_start_pivot = start_pivot;
326  start_pivot = A_skyline[i];
327  pivot = A_skyline[i];
328  walking = true;
329  } else if (A_skyline[i]==pivot+1) { // Walking the diagonal
330  if (A_skyline2[i]<start_pivot) { // Free of below-diagonal entries?
331  if (A_bottomline[i]>=prev_start_pivot) { // We must depend on at least one state
332  pivot++;
333  nxs_.back()++;
334  walking = true;
335  } else {
336  if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
337  errors.insert(i);
338  report_issue(i, "Constraint found depending "
339  "on a state of the previous interval.");
340  }
341  is_gap_closing = false;
342  }
343  } else {
344  nxs_.push_back(1);
345  nus_.push_back(0);
346  ngs_.push_back(0);
347  if (A_bottomline[i]!=-1 && A_bottomline[i]<start_pivot) {
348  errors.insert(i);
349  report_issue(i, "Gap-closing constraint found depending "
350  "on a state of the previous interval.");
351  }
352  prev_start_pivot = start_pivot;
353  start_pivot = A_skyline[i];
354  pivot = A_skyline[i];
355  walking = true;
356  }
357  } else {
358  is_gap_closing = false;
359  }
360  } else {
361  is_gap_closing = false;
362  }
363 
364  if (!is_gap_closing) {
365  if (walking) {
366  if (A_skyline[i]>=start_pivot) {
367  nxs_.push_back(0);
368  nus_.push_back(0);
369  ngs_.push_back(0);
370  walking = false;
371  }
372  }
373  ngs_.back()++; // non-gap-closing constraint detected
374  }
375 
376 
377  }
378 
379  if (nxs_.back()!=0) {
380  nxs_.push_back(0);
381  nus_.push_back(0);
382  ngs_.push_back(0);
383  }
384 
385  // Set nx0==nx1 unless not allowed
386  nxs_.insert(nxs_.begin(), std::min(A_skyline[0], nxs_.front()));
387 
388  // Patch loose ends
389  nus_.front() += std::max(A_skyline[0]-nxs_.front(), static_cast<casadi_int>(0));
390  nus_.back() += nx_-sum(nu)-sum(nx);
391 
392  casadi_assert_dev(nxs_.back()==0);
393  nxs_.pop_back();
394 
395  casadi_assert_dev(nx.size()==nu.size());
396  casadi_assert_dev(nx.size()==ng.size());
397 
398  casadi_assert_dev(sum(ng)+sum(nx)==na_+nx.front());
399  casadi_assert_dev(sum(nx)+sum(nu)==nx_);
400 
401  N_ = nxs_.size()-1;
402  }
403 
404  casadi_assert(nx.size()==N_+1, "nx must have length N+1.");
405  casadi_assert(nu.size()==N_+1, "nu must have length N+1.");
406  casadi_assert(ng.size()==N_+1, "ng must have length N+1.");
407 
408  if (verbose_) {
409  casadi_message("Using structure: N " + str(N_) + ", nx " + str(nx) + ", "
410  "nu " + str(nu) + ", ng " + str(ng) + ".");
411  }
412 
413  // Dor debugging purposes
414  std::vector< casadi_ocp_block > A_blocks, B_blocks, C_blocks, D_blocks;
415 
416  /* Disassemble A input into:
417  A B I
418  C D
419  A B I
420  C D
421  C D
422  */
423  casadi_int offset_r = 0, offset_c = 0;
424  for (casadi_int k=0;k<N_;++k) { // Loop over blocks
425  AB_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k]+nu[k]});
426  CD_blocks_.push_back({offset_r+nx[k+1], offset_c, ng[k], nx[k]+nu[k]});
427  A_blocks.push_back({offset_r, offset_c, nx[k+1], nx[k]});
428  B_blocks.push_back({offset_r, offset_c+nx[k], nx[k+1], nu[k]});
429  C_blocks.push_back({offset_r+nx[k+1], offset_c, ng[k], nx[k]});
430  D_blocks.push_back({offset_r+nx[k+1], offset_c+nx[k], ng[k], nu[k]});
431  offset_c+= nx[k]+nu[k];
432  if (k+1<N_)
433  I_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k+1]});
434  // TODO(jgillis) actually use these
435  // test5.py versus tesst6.py
436  // test5 changes behaviour when piping stdout to file -> memory corruption
437  // logs are ever so slightly different
438  else
439  I_blocks_.push_back({offset_r, offset_c, nx[k+1], nx[k+1]});
440  offset_r+= nx[k+1]+ng[k];
441  }
442  CD_blocks_.push_back({offset_r, offset_c, ng[N_], nx[N_]+nu[N_]});
443  C_blocks.push_back({offset_r, offset_c, ng[N_], nx[N_]});
444  D_blocks.push_back({offset_r, offset_c+nx[N_], ng[N_], nu[N_]});
445 
446  casadi_int offset = 0;
447  AB_offsets_.push_back(0);
448  for (auto e : AB_blocks_) {
449  offset += e.rows*e.cols;
450  AB_offsets_.push_back(offset);
451  }
452  offset = 0;
453  CD_offsets_.push_back(0);
454  for (auto e : CD_blocks_) {
455  offset += e.rows*e.cols;
456  CD_offsets_.push_back(offset);
457  }
458 
459  ABsp_ = blocksparsity(na_, nx_, AB_blocks_);
460  CDsp_ = blocksparsity(na_, nx_, CD_blocks_);
461  Isp_ = blocksparsity(na_, nx_, I_blocks_, true);
462 
463  Sparsity total = ABsp_ + CDsp_ + Isp_;
464 
465  if (debug_) {
466  total.to_file("debug_fatrop_expected.mtx");
467  blocksparsity(na_, nx_, A_blocks).to_file("debug_fatrop_A.mtx");
468  blocksparsity(na_, nx_, B_blocks).to_file("debug_fatrop_B.mtx");
469  blocksparsity(na_, nx_, C_blocks).to_file("debug_fatrop_C.mtx");
470  blocksparsity(na_, nx_, D_blocks).to_file("debug_fatrop_D.mtx");
471  Isp_.to_file("debug_fatrop_I.mtx");
472  std::vector<casadi_int> errors_vec(errors.begin(), errors.end());
473  std::vector<casadi_int> colind = {0, static_cast<casadi_int>(errors_vec.size())};
474  Sparsity(na_, 1, colind, errors_vec).to_file("debug_fatrop_errors.mtx");
475  }
476 
477  casadi_assert(errors.empty() && (A_ + total).nnz() == total.nnz(),
478  "Fatrop: specified structure of A does not correspond to what the interface can handle. "
479  "Structure is: N " + str(N_) + ", nx " + str(nx) + ", nu " + str(nu) + ", "
480  "ng " + str(ng) + ".\n"
481  "Note that debug_fatrop_expected.mtx and debug_fatrop_actual.mtx are written "
482  "to the current directory when 'debug' option is true.\n"
483  "These can be read with Sparsity.from_file(...)."
484  "For a ready-to-use script, "
485  "see https://gist.github.com/jgillis/dec56fa16c90a8e4a69465e8422c5459");
486  casadi_assert_dev(total.nnz() == ABsp_.nnz() + CDsp_.nnz() + Isp_.nnz());
487 
488  /* Disassemble H input into:
489  Q S'
490  S R
491  Q S'
492  S R
493 
494  Multiply by 2
495  */
496  offset = 0;
497  for (casadi_int k=0;k<N_+1;++k) { // Loop over blocks
498  RSQ_blocks_.push_back({offset, offset, nx[k]+nu[k], nx[k]+nu[k]});
499  offset+= nx[k]+nu[k];
500  }
501  RSQsp_ = blocksparsity(nx_, nx_, RSQ_blocks_);
502 
503  offset = 0;
504  RSQ_offsets_.push_back(0);
505  for (auto e : RSQ_blocks_) {
506  offset += e.rows*e.cols;
507  RSQ_offsets_.push_back(offset);
508  }
509 
510  set_fatrop_prob();
511 
512  // Allocate memory
513  casadi_int sz_arg, sz_res, sz_w, sz_iw;
514  casadi_fatrop_work(&p_, &sz_arg, &sz_res, &sz_iw, &sz_w);
515 
516  alloc_arg(sz_arg, true);
517  alloc_res(sz_res, true);
518  alloc_iw(sz_iw, true);
519  alloc_w(sz_w, true);
520  }
static Sparsity setup(ConvexifyData &d, const Sparsity &H, const Dict &opts=Dict(), bool inplace=true)
Definition: convexify.cpp:167
ConvexifyData convexify_data_
Data for convexification.
void init(const Dict &opts) override
Initialize.
Definition: nlpsol.cpp:509
std::vector< bool > equality_
Options.
casadi_int nnz() const
Number of structural nonzeros.
Definition: sparsity.cpp:150
void to_file(const std::string &filename, const std::string &format_hint="") const
Write the pattern to a file.
Definition: sparsity.cpp:2002
bool is_symmetric() const
Check whether the pattern equals its transpose.
Definition: sparsity.cpp:319
T sum(const std::vector< T > &values)
sum
void report_issue(casadi_int i, const std::string &msg)

References casadi::FunctionInternal::alloc_arg(), casadi::FunctionInternal::alloc_iw(), casadi::FunctionInternal::alloc_res(), casadi::FunctionInternal::alloc_w(), casadi::Nlpsol::calc_f_, casadi::Nlpsol::calc_g_, convexify_, convexify_data_, casadi::OracleFunction::create_function(), casadi::Nlpsol::equality_, exact_hessian_, casadi::Sparsity::get_colind(), casadi::OracleFunction::get_function(), casadi::Sparsity::get_row(), casadi::OracleFunction::has_function(), hesslag_sp_, casadi::Nlpsol::init(), casadi::Sparsity::is_symmetric(), jacg_sp_, casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::Nlpsol::nx_, opts_, casadi::report_issue(), set_fatrop_prob(), casadi::Convexify::setup(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::str(), casadi::sum(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::to_file(), and casadi::ProtoFunction::verbose_.

◆ init_mem()

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

Reimplemented from casadi::Nlpsol.

Definition at line 522 of file fatrop_interface.cpp.

522  {
523  if (Nlpsol::init_mem(mem)) return 1;
524  if (!mem) return 1;
525  auto m = static_cast<FatropMemory*>(mem);
526  casadi_fatrop_init_mem(&m->d);
527 
528  return 0;
529  }
int init_mem(void *mem) const override
Initalize memory block.
Definition: nlpsol.cpp:704

References casadi::Nlpsol::init_mem().

◆ 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 3656 of file function_internal.cpp.

3656  {
3657  casadi_error("'instruction_constant' not defined for " + class_name());
3658  }

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 3648 of file function_internal.cpp.

3648  {
3649  casadi_error("'instruction_id' not defined for " + class_name());
3650  }

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 3652 of file function_internal.cpp.

3652  {
3653  casadi_error("'instruction_input' not defined for " + class_name());
3654  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_MX()

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

Reimplemented in casadi::MXFunction.

Definition at line 3664 of file function_internal.cpp.

3664  {
3665  casadi_error("'instruction_MX' not defined for " + class_name());
3666  }

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 3660 of file function_internal.cpp.

3660  {
3661  casadi_error("'instruction_output' not defined for " + class_name());
3662  }

References casadi::SharedObjectInternal::class_name().

◆ instructions_sx()

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

Reimplemented in casadi::SXFunction.

Definition at line 3668 of file function_internal.cpp.

3668  {
3669  casadi_error("'instructions_sx' not defined for " + class_name());
3670  }

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 208 of file nlpsol_impl.hpp.

208 { 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 375 of file nlpsol.cpp.

375  {
376  return type=="Nlpsol" || (recursive && OracleFunction::is_a(type, recursive));
377  }
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 1980 of file function_internal.cpp.

1980  {
1981  // If derivative expression
1982  if (!derivative_of_.is_null()) {
1983  std::string n = derivative_of_.name();
1984  // Reverse move
1985  if (name_ == "adj1_" + n) {
1986  if (iind == oind) return true;
1987  }
1988  }
1989  // Not symmetric by default
1990  return false;
1991  }
const std::string & name() const
Get the name given at construction ("null" for a null object)
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 2068 of file function_internal.cpp.

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

2468  {
2469  // Used wrapped function if jacobian not available
2470  if (!has_jacobian()) {
2471  // Derivative information must be available
2472  casadi_assert(has_derivative(),
2473  "Derivatives cannot be calculated for " + name_);
2474  return wrap().jacobian();
2475  }
2476  // Retrieve/generate cached
2477  Function f;
2478  std::string fname = "jac_" + name_;
2479  if (!incache(fname, f)) {
2480  // Names of inputs
2481  std::vector<std::string> inames;
2482  for (casadi_int i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2483  for (casadi_int i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2484  // Names of outputs
2485  std::vector<std::string> onames;
2486  onames.reserve(n_in_ * n_out_);
2487  for (size_t oind = 0; oind < n_out_; ++oind) {
2488  for (size_t iind = 0; iind < n_in_; ++iind) {
2489  onames.push_back("jac_" + name_out_[oind] + "_" + name_in_[iind]);
2490  }
2491  }
2492  // Options
2494  opts["derivative_of"] = self();
2495  // Generate derivative function
2496  casadi_assert_dev(enable_jacobian_);
2497  f = get_jacobian(fname, inames, onames, opts);
2498  // Consistency checks
2499  casadi_assert(f.n_in() == inames.size(),
2500  "Mismatching input signature, expected " + str(inames));
2501  casadi_assert(f.n_out() == onames.size(),
2502  "Mismatching output signature, expected " + str(onames));
2503  // Save to cache
2504  tocache_if_missing(f);
2505  }
2506  return f;
2507  }
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
Get a function computing all Jacobian blocks at once.
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 442 of file oracle_function.cpp.

442  {
443  if (compiler_.is_null()) {
444  if (verbose_) casadi_message("compiling to "+ fname+"'.");
445  // JIT dependent functions
448  }
449  // Replace the Oracle functions with generated functions
450  for (auto&& e : all_functions_) {
451  if (verbose_) casadi_message("loading '" + e.second.f.name() + "' from '" + fname + "'.");
452  if (e.second.jit) {
453  e.second.f_original = e.second.f;
454  e.second.f = external(e.second.f.name(), compiler_);
455  }
456  }
457 }
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::codegen_options_, 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(), casadi::Integrator::eval(), and casadi::RuntimeIntegrator::eval().

◆ kkt()

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

Definition at line 948 of file nlpsol.cpp.

948  {
949 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
950  // Safe access to kkt_
951  std::lock_guard<std::mutex> lock(kkt_mtx_);
952 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
953  // Quick return if cached
954  SharedObject temp;
955  if (kkt_.shared_if_alive(temp)) {
956  return shared_cast<Function>(temp);
957  }
958 
959  // Generate KKT function
960  Function ret = oracle_.factory("kkt", {"x", "p", "lam:f", "lam:g"},
961  {"jac:g:x", "hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
962 
963  // Cache and return
964  kkt_ = ret;
965  return ret;
966  }
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.
std::ostream & uerr()
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 469 of file oracle_function.cpp.

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

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 1207 of file function_internal.cpp.

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

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 3677 of file function_internal.cpp.

3678  {
3679  if (x.empty()) return x;
3680  // Check number of arguments
3681  casadi_assert(x.size()==n_in_, "mapsum_mx: Wrong number_i of arguments");
3682  // Number of parallel calls
3683  casadi_int npar = 1;
3684  // Check/replace arguments
3685  std::vector<MX> x_mod(x.size());
3686  for (casadi_int i=0; i<n_in_; ++i) {
3687  if (check_mat(x[i].sparsity(), sparsity_in_[i], npar)) {
3688  x_mod[i] = replace_mat(x[i], sparsity_in_[i], npar);
3689  } else {
3690  // Mismatching sparsity: The following will throw an error message
3691  npar = 0;
3692  check_arg(x, npar);
3693  }
3694  }
3695 
3696  casadi_int n = 1;
3697  for (casadi_int i=0; i<x_mod.size(); ++i) {
3698  n = std::max(x_mod[i].size2() / size2_in(i), n);
3699  }
3700 
3701  std::vector<casadi_int> reduce_in;
3702  for (casadi_int i=0; i<x_mod.size(); ++i) {
3703  if (x_mod[i].size2()/size2_in(i)!=n) {
3704  reduce_in.push_back(i);
3705  }
3706  }
3707 
3708  Function ms = self().map("mapsum", parallelization, n, reduce_in, range(n_out_));
3709 
3710  // Call the internal function
3711  return ms(x_mod);
3712  }
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 1811 of file function_internal.hpp.

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

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 1821 of file function_internal.hpp.

1821  {
1822  check_res(res, npar);
1823  for (casadi_int i=0; i<n_out_; ++i) {
1824  if (res.at(i).size1()!=size1_out(i)) return false;
1825  if (res.at(i).size2()!=size2_out(i) && res.at(i).size2()!=npar*size2_out(i)) return false;
1826  }
1827  return true;
1828  }
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 3912 of file function_internal.cpp.

3912  {
3913 #ifdef CASADI_WITH_THREAD
3914  std::lock_guard<std::mutex> lock(mtx_);
3915 #endif //CASADI_WITH_THREAD
3916  return mem_.at(ind);
3917  }

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 3627 of file function_internal.cpp.

3628  {
3629  }

◆ monitored()

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

Definition at line 561 of file oracle_function.cpp.

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

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 3607 of file function_internal.cpp.

3607  {
3608  std::vector<MX> ret(n_in_);
3609  for (casadi_int i=0; i<ret.size(); ++i) {
3610  ret[i] = mx_in(i);
3611  }
3612  return ret;
3613  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::Conic::get_forward(), casadi::Nlpsol::get_forward(), casadi::LinearInterpolantJac::get_jacobian(), casadi::Conic::get_reverse(), 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 3615 of file function_internal.cpp.

3615  {
3616  std::vector<MX> ret(n_out_);
3617  for (casadi_int i=0; i<ret.size(); ++i) {
3618  ret[i] = mx_out(i);
3619  }
3620  return ret;
3621  }

References casadi::FunctionInternal::n_out_.

Referenced by casadi::Conic::get_forward(), casadi::Nlpsol::get_forward(), casadi::Conic::get_reverse(), 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 3644 of file function_internal.cpp.

3644  {
3645  casadi_error("'n_instructions' not defined for " + class_name());
3646  }

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 3672 of file function_internal.cpp.

3672  {
3673  casadi_error("'n_nodes' not defined for " + class_name());
3674  }

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 2427 of file function_internal.cpp.

2427  {
2428  casadi_int ret=0;
2429  for (casadi_int iind=0; iind<n_in_; ++iind) ret += nnz_in(iind);
2430  return ret;
2431  }

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 2439 of file function_internal.cpp.

2439  {
2440  casadi_int ret=0;
2441  for (casadi_int iind=0; iind<n_in_; ++iind) ret += numel_in(iind);
2442  return ret;
2443  }

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
Total number of entries, structural zeros included, i.e. size1()*size2()
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 2445 of file function_internal.cpp.

2445  {
2446  casadi_int ret=0;
2447  for (casadi_int oind=0; oind<n_out_; ++oind) ret += numel_out(oind);
2448  return ret;
2449  }

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 3767 of file function_internal.cpp.

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

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 3737 of file function_internal.cpp.

3737  {
3738  casadi_assert(nnz_in()==arg.size(),
3739  "Dimension mismatch. Expecting " + str(nnz_in()) +
3740  ", got " + str(arg.size()) + " instead.");
3741 
3742  std::vector<DM> ret = dm_in();
3743  casadi_int offset = 0;
3744  for (casadi_int i=0;i<n_in_;++i) {
3745  DM& r = ret.at(i);
3746  std::copy(arg.begin()+offset, arg.begin()+offset+nnz_in(i), r.ptr());
3747  offset+= nnz_in(i);
3748  }
3749  return ret;
3750  }

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 3785 of file function_internal.cpp.

3785  {
3786  // Disallow parallel inputs
3787  casadi_int npar = -1;
3788  if (!matching_res(res, npar)) {
3789  return nz_out(replace_res(res, npar));
3790  }
3791 
3792  std::vector<DM> res2 = project_res(res, 1);
3793  std::vector<double> ret(nnz_out());
3794  casadi_int offset = 0;
3795  for (casadi_int i=0;i<n_out_;++i) {
3796  const double* e = res2.at(i).ptr();
3797  std::copy(e, e+nnz_out(i), ret.begin()+offset);
3798  offset+= nnz_out(i);
3799  }
3800  return ret;
3801  }
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 3752 of file function_internal.cpp.

3752  {
3753  casadi_assert(nnz_out()==res.size(),
3754  "Dimension mismatch. Expecting " + str(nnz_out()) +
3755  ", got " + str(res.size()) + " instead.");
3756 
3757  std::vector<DM> ret = dm_out();
3758  casadi_int offset = 0;
3759  for (casadi_int i=0;i<n_out_;++i) {
3760  DM& r = ret.at(i);
3761  std::copy(res.begin()+offset, res.begin()+offset+nnz_out(i), r.ptr());
3762  offset+= nnz_out(i);
3763  }
3764  return ret;
3765  }

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 854 of file function_internal.cpp.

855  {
856  if (dump_id < 0) dump_id = get_dump_id();
857  std::stringstream filename;
858  filename << dump_dir_ << filesep() << name_ << "." << std::setfill('0')
859  << std::setw(6) << dump_id << ".trace.jsonl";
860  auto output = Filesystem::ofstream_ptr(filename.str());
861  std::ostream& trace = *output;
862  normalized_setup(trace);
863  trace << "{\"event\":\"header\",\"format\":\"casadi_trace\",\"version\":1,"
864  << "\"function\":\"" << name_ << "\",\"type\":\"" << class_name()
865  << "\",\"dump_id\":" << dump_id << "}\n";
866  trace << "{\"event\":\"inputs\",\"values\":[";
867  for (casadi_int i = 0; i < n_in_; ++i) {
868  if (i) trace << ",";
869  trace_values(trace, arg[i], nnz_in(i));
870  }
871  trace << "]}\n";
872  return output;
873  }
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::FatropInterface::plugin_name ( ) const
inlineoverridevirtual

Implements casadi::PluginInterface< Nlpsol >.

Definition at line 107 of file fatrop_interface.hpp.

107 { return "fatrop";}

◆ 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 4170 of file function_internal.cpp.

4170  {
4171  // Variable number of arguments
4172  va_list args;
4173  va_start(args, fmt);
4174  // Static & dynamic buffers
4175  char buf[256];
4176  size_t buf_sz = sizeof(buf);
4177  char* buf_dyn = nullptr;
4178  // Try to print with a small buffer
4179  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
4180  // Need a larger buffer?
4181  if (n>static_cast<casadi_int>(buf_sz)) {
4182  buf_sz = static_cast<size_t>(n+1);
4183  buf_dyn = new char[buf_sz];
4184  n = vsnprintf(buf_dyn, buf_sz, fmt, args);
4185  }
4186  // Print buffer content
4187  if (n>=0) uout() << (buf_dyn ? buf_dyn : buf) << std::flush;
4188  // Cleanup
4189  delete[] buf_dyn;
4190  va_end(args);
4191  // Throw error if failure
4192  casadi_assert(n>=0, "Print failure while processing '" + std::string(fmt) + "'");
4193  }

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 973 of file function_internal.cpp.

973  {
974  StreamStateGuard backup(stream);
975  normalized_setup(stream);
976  if (nz) {
977  stream << "[";
978  for (casadi_int i=0; i<sz; ++i) {
979  if (i>0) stream << ", ";
980  normalized_out(stream, nz[i]);
981  }
982  stream << "]";
983  } else {
984  stream << "NULL";
985  }
986  }

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 988 of file function_internal.cpp.

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

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 1023 of file function_internal.cpp.

1023  {
1024  StreamStateGuard backup(stream);
1025  normalized_setup(stream);
1026  normalized_out(stream, a);
1027  }

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 1099 of file function_internal.cpp.

1099  {
1100  stream << " Number of inputs: " << n_in_ << std::endl;
1101  for (casadi_int i=0; i<n_in_; ++i) {
1102  stream << " Input " << i << " (\"" << name_in_[i] << "\"): "
1103  << sparsity_in_[i].dim() << std::endl;
1104  }
1105  stream << " Number of outputs: " << n_out_ << std::endl;
1106  for (casadi_int i=0; i<n_out_; ++i) {
1107  stream << " Output " << i << " (\"" << name_out_[i] << "\"): "
1108  << sparsity_out_[i].dim() << std::endl;
1109  }
1110  }

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 939 of file function_internal.cpp.

939  {
940  stream << "Function " << name_ << " (" << this << ")" << std::endl;
941  for (casadi_int i=0; i<n_in_; ++i) {
942  stream << "Input " << i << " (" << name_in_[i] << "): ";
943  if (arg[i]) {
944  if (print_canonical_) {
945  print_canonical(stream, sparsity_in_[i], arg[i]);
946  } else {
947  DM::print_default(stream, sparsity_in_[i], arg[i], truncate);
948  }
949  stream << std::endl;
950  } else {
951  stream << "NULL" << std::endl;
952  }
953  }
954  }
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 1116 of file function_internal.cpp.

1116  {
1117  get_options().print_one(name, stream);
1118  }
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 1112 of file function_internal.cpp.

1112  {
1113  get_options().print_all(stream);
1114  }
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 956 of file function_internal.cpp.

956  {
957  stream << "Function " << name_ << " (" << this << ")" << std::endl;
958  for (casadi_int i=0; i<n_out_; ++i) {
959  stream << "Output " << i << " (" << name_out_[i] << "): ";
960  if (res[i]) {
961  if (print_canonical_) {
962  print_canonical(stream, sparsity_out_[i], res[i]);
963  } else {
964  DM::print_default(stream, sparsity_out_[i], res[i], truncate);
965  }
966  stream << std::endl;
967  } else {
968  stream << "NULL" << std::endl;
969  }
970  }
971  }

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 4090 of file function_internal.cpp.

4090  {
4091  if (!print_time_) return;
4092  // Length of the name being printed
4093  size_t name_len=0;
4094  for (auto &&s : fstats) {
4095  name_len = std::max(s.first.size(), name_len);
4096  }
4097  name_len = std::max(name_.size(), name_len);
4098 
4099  // Print name with a given length. Format: "%NNs "
4100  char namefmt[10];
4101  sprint(namefmt, sizeof(namefmt), "%%%ds ", static_cast<casadi_int>(name_len));
4102 
4103  // Print header
4104  print(namefmt, name_.c_str());
4105 
4106  print(" : %8s %10s %8s %10s %9s\n", "t_proc", "(avg)", "t_wall", "(avg)", "n_eval");
4107 
4108 
4109  char buffer_proc[10];
4110  char buffer_wall[10];
4111  char buffer_proc_avg[10];
4112  char buffer_wall_avg[10];
4113 
4114  // Print keys
4115  for (const auto &s : fstats) {
4116  if (s.second.n_call!=0) {
4117  print(namefmt, s.first.c_str());
4118  format_time(buffer_proc, s.second.t_proc);
4119  format_time(buffer_wall, s.second.t_wall);
4120  format_time(buffer_proc_avg, s.second.t_proc/s.second.n_call);
4121  format_time(buffer_wall_avg, s.second.t_wall/s.second.n_call);
4122  print(" | %s (%s) %s (%s) %9d\n",
4123  buffer_proc, buffer_proc_avg,
4124  buffer_wall, buffer_wall_avg, s.second.n_call);
4125  }
4126  }
4127  }
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 1683 of file function_internal.hpp.

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

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 1723 of file function_internal.hpp.

1724  {
1725  return arg;
1726  }

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 1576 of file function_internal.hpp.

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

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 3944 of file function_internal.cpp.

3944  {
3945 #ifdef CASADI_WITH_THREAD
3946  std::lock_guard<std::mutex> lock(mtx_);
3947 #endif //CASADI_WITH_THREAD
3948  unused_.push(mem);
3949  }

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 1858 of file function_internal.hpp.

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

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 1882 of file function_internal.hpp.

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

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 1874 of file function_internal.hpp.

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

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 1866 of file function_internal.hpp.

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

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 476 of file function_internal.cpp.

476  {
477  dump_count_ = 0;
478  }

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 2350 of file function_internal.cpp.

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

4467  {
4468  serialize_type(s);
4469  serialize_body(s);
4470  }
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 134 of file nlpsol_impl.hpp.

134 { return "Nlpsol"; }

◆ serialize_body()

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

Reimplemented from casadi::Nlpsol.

Definition at line 927 of file fatrop_interface.cpp.

927  {
929  s.version("FatropInterface", 1);
930 
931  s.pack("FatropInterface::jacg_sp", jacg_sp_);
932  s.pack("FatropInterface::hesslag_sp", hesslag_sp_);
933  s.pack("FatropInterface::exact_hessian", exact_hessian_);
934  s.pack("FatropInterface::opts", opts_);
935  s.pack("FatropInterface::convexify", convexify_);
936 
937  s.pack("FatropInterface::Isp", Isp_);
938  s.pack("FatropInterface::ABsp", ABsp_);
939  s.pack("FatropInterface::CDsp", CDsp_);
940  s.pack("FatropInterface::RSQsp", RSQsp_);
941 
942  s.pack("FatropInterface::AB_blocks", fatrop_blocks_pack(AB_blocks_));
943  s.pack("FatropInterface::CD_blocks", fatrop_blocks_pack(CD_blocks_));
944  s.pack("FatropInterface::RSQ_blocks", fatrop_blocks_pack(RSQ_blocks_));
945  s.pack("FatropInterface::I_blocks", fatrop_blocks_pack(I_blocks_));
946 
947  s.pack("FatropInterface::nxs", nxs_);
948  s.pack("FatropInterface::nus", nus_);
949  s.pack("FatropInterface::ngs", ngs_);
950  s.pack("FatropInterface::N", N_);
951  s.pack("FatropInterface::structure_detection", static_cast<casadi_int>(structure_detection_));
952  s.pack("FatropInterface::AB_offsets", AB_offsets_);
953  s.pack("FatropInterface::CD_offsets", CD_offsets_);
954  s.pack("FatropInterface::RSQ_offsets", RSQ_offsets_);
955  s.pack("FatropInterface::I_offsets", I_offsets_);
956  s.pack("FatropInterface::debug", debug_);
957 }
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Definition: nlpsol.cpp:1399
std::vector< casadi_int > fatrop_blocks_pack(const std::vector< casadi_ocp_block > &blocks)

References convexify_, exact_hessian_, casadi::fatrop_blocks_pack(), hesslag_sp_, jacg_sp_, opts_, casadi::SerializingStream::pack(), casadi::Nlpsol::serialize_body(), and casadi::SerializingStream::version().

◆ 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 1430 of file nlpsol.cpp.

1430  {
1433  }
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_fatrop_prob() [1/2]

void casadi::FatropInterface::set_fatrop_prob ( )

Definition at line 780 of file fatrop_interface.cpp.

780  {
781  p_.nlp = &p_nlp_;
782  p_.nx = get_ptr(nxs_);
783  p_.nu = get_ptr(nus_);
784  p_.ABsp = ABsp_;
785  p_.AB_offsets = get_ptr(AB_offsets_);
786  p_.CDsp = CDsp_;
787  p_.CD_offsets = get_ptr(CD_offsets_);
788  p_.RSQsp = RSQsp_;
789  p_.RSQ_offsets = get_ptr(RSQ_offsets_);
790  p_.Isp = Isp_;
791  p_.I_offsets = get_ptr(I_offsets_);
792 
793  p_.AB = get_ptr(AB_blocks_);
794  p_.CD = get_ptr(CD_blocks_);
795  p_.RSQ = get_ptr(RSQ_blocks_);
796  p_.I = get_ptr(I_blocks_);
797  p_.N = N_;
798 
799  p_.sp_a = jacg_sp_;
800  p_.sp_h = hesslag_sp_;
801 
802  p_.nlp_hess_l = OracleCallback("nlp_hess_l", this);
803  p_.nlp_jac_g = OracleCallback("nlp_jac_g", this);
804  p_.nlp_grad_f = OracleCallback("nlp_grad_f", this);
805  p_.nlp_f = OracleCallback("nlp_f", this);
806  p_.nlp_g = OracleCallback("nlp_g", this);
807  p_.write = &casadi_c_logger_write;
808  p_.flush = &casadi_c_logger_flush;
809 
810  casadi_fatrop_setup(&p_);
811 }
casadi_nlpsol_prob< double > p_nlp_
Definition: nlpsol_impl.hpp:63
OracleCallback nlp_grad_f
const casadi_int * I_offsets
const casadi_int * sp_h
const casadi_int * nx
const casadi_int * RSQsp
OracleCallback nlp_hess_l
FatropOcpCWrite write
const casadi_int * nu
casadi_ocp_block * I
const casadi_int * sp_a
FatropOcpCFlush flush
casadi_ocp_block * AB
const casadi_int * CDsp
OracleCallback nlp_g
casadi_ocp_block * RSQ
const casadi_int * RSQ_offsets
casadi_ocp_block * CD
const casadi_int * CD_offsets
const casadi_int * Isp
const casadi_nlpsol_prob< T1 > * nlp
OracleCallback nlp_f
OracleCallback nlp_jac_g
const casadi_int * ABsp
const casadi_int * AB_offsets

References casadi_fatrop_prob< T1 >::AB, casadi_fatrop_prob< T1 >::AB_offsets, casadi_fatrop_prob< T1 >::ABsp, casadi_fatrop_prob< T1 >::CD, casadi_fatrop_prob< T1 >::CD_offsets, casadi_fatrop_prob< T1 >::CDsp, casadi_fatrop_prob< T1 >::flush, casadi::get_ptr(), hesslag_sp_, casadi_fatrop_prob< T1 >::I, casadi_fatrop_prob< T1 >::I_offsets, casadi_fatrop_prob< T1 >::Isp, jacg_sp_, casadi_fatrop_prob< T1 >::N, casadi_fatrop_prob< T1 >::nlp, casadi_fatrop_prob< T1 >::nlp_f, casadi_fatrop_prob< T1 >::nlp_g, casadi_fatrop_prob< T1 >::nlp_grad_f, casadi_fatrop_prob< T1 >::nlp_hess_l, casadi_fatrop_prob< T1 >::nlp_jac_g, casadi_fatrop_prob< T1 >::nu, casadi_fatrop_prob< T1 >::nx, casadi::Nlpsol::p_nlp_, casadi_fatrop_prob< T1 >::RSQ, casadi_fatrop_prob< T1 >::RSQ_offsets, casadi_fatrop_prob< T1 >::RSQsp, casadi_fatrop_prob< T1 >::sp_a, casadi_fatrop_prob< T1 >::sp_h, and casadi_fatrop_prob< T1 >::write.

Referenced by codegen_body(), FatropInterface(), and init().

◆ set_fatrop_prob() [2/2]

void casadi::FatropInterface::set_fatrop_prob ( CodeGenerator &  g) const

Definition at line 836 of file fatrop_interface.cpp.

836  {
837  if (jacg_sp_.size1()>0 && jacg_sp_.nnz()==0) {
838  casadi_error("Empty sparsity pattern not supported in FATROP C interface");
839  }
840  g << "d->nlp = &d_nlp;\n";
841  g << "d->prob = &p;\n";
842  g << "p.nlp = &p_nlp;\n";
843 
844  g << "p.nx = " << g.constant(nxs_) << ";\n";
845  g << "p.nu = " << g.constant(nus_) << ";\n";
846  g << "p.ABsp = " << g.sparsity(ABsp_) << ";\n";
847  g << "p.AB_offsets = " << g.constant(AB_offsets_) << ";\n";
848  g << "p.CDsp = " << g.sparsity(CDsp_) << ";\n";
849  g << "p.CD_offsets = " << g.constant(CD_offsets_) << ";\n";
850  g << "p.RSQsp = " << g.sparsity(RSQsp_) << ";\n";
851  g << "p.RSQ_offsets = " << g.constant(RSQ_offsets_) << ";\n";
852  g << "p.Isp = " << g.sparsity(Isp_) << ";\n";
853  g << "p.I_offsets = " << g.constant(I_offsets_) << ";\n";
854 
855  codegen_unpack_block(g, "AB", AB_blocks_);
856  codegen_unpack_block(g, "CD", CD_blocks_);
857  codegen_unpack_block(g, "RSQ", RSQ_blocks_);
858  codegen_unpack_block(g, "I", I_blocks_);
859  g << "p.N = " << N_ << ";\n";
860 
861  g.setup_callback("p.nlp_jac_g", get_function("nlp_jac_g"));
862  g.setup_callback("p.nlp_grad_f", get_function("nlp_grad_f"));
863  g.setup_callback("p.nlp_f", get_function("nlp_f"));
864  g.setup_callback("p.nlp_g", get_function("nlp_g"));
865  g.setup_callback("p.nlp_hess_l", get_function("nlp_hess_l"));
866 
867  g << "p.sp_a = " << g.sparsity(jacg_sp_) << ";\n";
868  if (exact_hessian_) {
869  g << "p.sp_h = " << g.sparsity(hesslag_sp_) << ";\n";
870  } else {
871  g << "p.sp_h = 0;\n";
872  }
873 
874  g << "p.write = &" << g.shorthand("fatrop_cb_write") << ";\n";
875  g << "p.flush = &" << g.shorthand("fatrop_cb_flush") << ";\n";
876 
877  g << "casadi_fatrop_setup(&p);\n";
878 
879 }
casadi_int size1() const
Number of rows.
Definition: sparsity.cpp:124
void codegen_unpack_block(CodeGenerator &g, const std::string &name, const std::vector< casadi_ocp_block > &blocks)

References casadi::codegen_unpack_block(), casadi::CodeGenerator::constant(), exact_hessian_, casadi::OracleFunction::get_function(), hesslag_sp_, jacg_sp_, casadi::Sparsity::nnz(), casadi::CodeGenerator::setup_callback(), casadi::CodeGenerator::shorthand(), casadi::Sparsity::size1(), and casadi::CodeGenerator::sparsity().

◆ 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 4034 of file function_internal.cpp.

4034  {
4035 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
4036  // Safe access to jac_sparsity_
4037  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
4038 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
4039  casadi_int ind = iind + oind * n_in_;
4040  jac_sparsity_[false].resize(n_in_ * n_out_);
4041  jac_sparsity_[false].at(ind) = sp;
4042  jac_sparsity_[true].resize(n_in_ * n_out_);
4043  jac_sparsity_[true].at(ind) = to_compact(oind, iind, sp);
4044  }

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 509 of file oracle_function.cpp.

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

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::FatropInterface::set_work ( void *  mem,
const double **&  arg,
double **&  res,
casadi_int *&  iw,
double *&  w 
) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 538 of file fatrop_interface.cpp.

539  {
540  auto m = static_cast<FatropMemory*>(mem);
541 
542  // Set work in base classes
543  Nlpsol::set_work(mem, arg, res, iw, w);
544 
545  m->d.prob = &p_;
546  m->d.nlp = &m->d_nlp;
547 
548  casadi_fatrop_set_work(&m->d, &arg, &res, &iw, &w);
549 
550  m->d.nlp->oracle->m = static_cast<void*>(m);
551 
552  // options
553  }
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:896

References casadi_fatrop_prob< T1 >::nlp, and casadi::Nlpsol::set_work().

◆ setOptionsFromFile()

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

Definition at line 775 of file nlpsol.cpp.

775  {
776  casadi_error("setOptionsFromFile not defined for class " + class_name());
777  }

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 3803 of file function_internal.cpp.

3804  {
3805  set_work(mem, arg, res, iw, w);
3806  set_temp(mem, arg, res, iw, w);
3807  auto *m = static_cast<FunctionMemory*>(mem);
3808  m->stats_available = true;
3809  }
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::RuntimeIntegrator::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 313 of file nlpsol_impl.hpp.

313 { 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 2562 of file function_internal.cpp.

2562  {
2563  return "int " + fname + "(const casadi_real** arg, casadi_real** res, "
2564  "casadi_int* iw, casadi_real* w, int mem)";
2565  }

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 2567 of file function_internal.cpp.

2567  {
2568  std::vector<std::string> args;
2569  for (auto e : name_in_) {
2570  args.push_back("const casadi_real* " + str(e));
2571  }
2572  for (auto e : name_out_) {
2573  args.push_back("casadi_real* " + str(e));
2574  }
2575  args.push_back("const casadi_real** arg");
2576  args.push_back("casadi_real** res");
2577  args.push_back("casadi_int* iw");
2578  args.push_back("casadi_real* w");
2579  args.push_back("int mem");
2580  return "int " + fname + "_unrolled(" + join(args, ", ") + ")";
2581  }

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 4003 of file function_internal.cpp.

4004  {
4005  casadi_assert(tasks.empty(), "simplify passes not supported for " + class_name());
4006  return self();
4007  }

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 4015 of file function_internal.cpp.

4017  {
4018  return wrap().slice(name, order_in, order_out, opts);
4019  }
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
Create a function with a subset or reordering of the inputs and outputs.
Definition: function.cpp:899

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

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

◆ solve()

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

Implements casadi::Nlpsol.

Definition at line 555 of file fatrop_interface.cpp.

555  {
556  auto m = static_cast<FatropMemory*>(mem);
557 
558  // Cache the solver: presolve (re)creates it only when needed
559  bool new_solver = (m->d.solver == 0);
560  // fatrop's solve repoints a process-wide singleton stream via
561  // fatrop::OutputStreamManager::set_stream, which is not thread-safe.
562  // Serialize across threads.
563  {
564 #ifdef CASADI_WITH_THREAD
565  static std::mutex mutex_fatrop_create;
566  std::lock_guard<std::mutex> lock(mutex_fatrop_create);
567 #endif //CASADI_WITH_THREAD
568  casadi_fatrop_presolve(&m->d);
569  }
570 
571  // Set options only when a new solver was created (options persist across solves)
572  if (new_solver) {
573  for (const auto& kv : opts_) {
574  switch (fatrop_ocp_c_option_type(kv.first.c_str())) {
575  case 0:
576  fatrop_ocp_c_set_option_double(m->d.solver, kv.first.c_str(), kv.second);
577  break;
578  case 1:
579  fatrop_ocp_c_set_option_int(m->d.solver, kv.first.c_str(), kv.second.to_int());
580  break;
581  case 2:
582  fatrop_ocp_c_set_option_bool(m->d.solver, kv.first.c_str(), kv.second.to_bool());
583  break;
584  case 3:
585  {
586  std::string s = kv.second.to_string();
587  fatrop_ocp_c_set_option_string(m->d.solver, kv.first.c_str(), s.c_str());
588  }
589  break;
590  case -1:
591  casadi_error("Fatrop option not supported: " + kv.first);
592  default:
593  casadi_error("Unknown option type.");
594  }
595  }
596  }
597 
598  casadi_fatrop_solve(&m->d);
599 
600  m->success = m->d.success;
601  m->unified_return_status = static_cast<UnifiedReturnStatus>(m->d.unified_return_status);
602 
603  return 0;
604  }
UnifiedReturnStatus

References opts_.

◆ 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::RuntimeIntegrator, casadi::Rootfinder, casadi::MXFunction, casadi::MapSum, casadi::Map, and casadi::Integrator.

Definition at line 3090 of file function_internal.cpp.

3091  {
3092  // Loop over outputs
3093  for (casadi_int oind=0; oind<n_out_; ++oind) {
3094  // Skip if nothing to assign
3095  if (res[oind]==nullptr || nnz_out(oind)==0) continue;
3096  // Clear result
3097  casadi_clear(res[oind], nnz_out(oind));
3098  // Loop over inputs
3099  for (casadi_int iind=0; iind<n_in_; ++iind) {
3100  // Skip if no seeds
3101  if (arg[iind]==nullptr || nnz_in(iind)==0) continue;
3102  // Propagate sparsity for the specific block
3103  if (sp_forward_block(arg, res, iw, w, mem, oind, iind)) return 1;
3104  }
3105  }
3106  return 0;
3107  }
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::Integrator::sp_forward(), 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 3109 of file function_internal.cpp.

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

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::RuntimeIntegrator, casadi::Rootfinder, casadi::MXFunction, casadi::MapSum, casadi::Map, and casadi::Integrator.

Definition at line 3125 of file function_internal.cpp.

3126  {
3127  // Loop over outputs
3128  for (casadi_int oind=0; oind<n_out_; ++oind) {
3129  // Skip if nothing to assign
3130  if (res[oind]==nullptr || nnz_out(oind)==0) continue;
3131 
3132  // Loop over inputs
3133  for (casadi_int iind=0; iind<n_in_; ++iind) {
3134  // Skip if no seeds
3135  if (arg[iind]==nullptr || nnz_in(iind)==0) continue;
3136 
3137  // Get the sparsity of the Jacobian block
3138  Sparsity sp = jac_sparsity(oind, iind, true, false);
3139  if (sp.is_null() || sp.nnz() == 0) continue; // Skip if zero
3140 
3141  // Carry out the sparse matrix-vector multiplication
3142  casadi_int d1 = sp.size2();
3143  const casadi_int *colind = sp.colind(), *row = sp.row();
3144  for (casadi_int cc=0; cc<d1; ++cc) {
3145  for (casadi_int el = colind[cc]; el < colind[cc+1]; ++el) {
3146  arg[iind][cc] |= res[oind][row[el]];
3147  }
3148  }
3149  }
3150 
3151  // Clear seeds
3152  casadi_clear(res[oind], nnz_out(oind));
3153  }
3154  return 0;
3155  }

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::Integrator::sp_reverse(), 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 3540 of file function_internal.cpp.

3540  {
3541  // If reverse mode propagation unavailable, use forward
3542  if (!has_sprev()) return 0;
3543 
3544  // If forward mode propagation unavailable, use reverse
3545  if (!has_spfwd()) return 1;
3546 
3547  // Use the (potentially user set) option
3548  return ad_weight_sp_;
3549  }

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 4158 of file function_internal.cpp.

4158  {
4159  // Variable number of arguments
4160  va_list args;
4161  va_start(args, fmt);
4162  // Print to buffer
4163  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
4164  // Cleanup
4165  va_end(args);
4166  // Throw error if failure
4167  casadi_assert(n>=0 && n<buf_sz, "Print failure while processing '" + std::string(fmt) + "'");
4168  }

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 4226 of file function_internal.cpp.

4226  {
4227  switch (status) {
4228  case SOLVER_RET_LIMITED: return "SOLVER_RET_LIMITED";
4229  case SOLVER_RET_NAN: return "SOLVER_RET_NAN";
4230  case SOLVER_RET_SUCCESS: return "SOLVER_RET_SUCCESS";
4231  default: return "SOLVER_RET_UNKNOWN";
4232  }
4233  }
@ SOLVER_RET_NAN
@ SOLVER_RET_LIMITED

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 3567 of file function_internal.cpp.

3567  {
3568  std::vector<SX> ret(n_in_);
3569  for (casadi_int i=0; i<ret.size(); ++i) {
3570  ret[i] = sx_in(i);
3571  }
3572  return ret;
3573  }
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 3575 of file function_internal.cpp.

3575  {
3576  std::vector<SX> ret(n_out_);
3577  for (casadi_int i=0; i<ret.size(); ++i) {
3578  ret[i] = sx_out(i);
3579  }
3580  return ret;
3581  }
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 1272 of file function_internal.cpp.

1272  {
1273  return self()(arg);
1274  }

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 1601 of file function_internal.hpp.

1602  {
1603  std::vector<std::vector<MatType> > aseed(nadj, v);
1604  for (casadi_int dir=0; dir<nadj; ++dir) {
1605  // Replace symbolic inputs
1606  casadi_int oind=0;
1607  for (typename std::vector<MatType>::iterator i=aseed[dir].begin();
1608  i!=aseed[dir].end();
1609  ++i, ++oind) {
1610  // Name of the adjoint seed
1611  std::stringstream ss;
1612  ss << "a";
1613  if (nadj>1) ss << dir << "_";
1614  ss << oind;
1615 
1616  // Save to matrix
1617  *i = MatType::sym(ss.str(), is_diff_out_[oind] ? i->sparsity() : Sparsity(i->size()));
1618 
1619  }
1620  }
1621  return aseed;
1622  }

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::RuntimeIntegrator::alloc_ivp_work(), 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(), init(), casadi::HighsInterface::init(), casadi::HpipmInterface::init(), casadi::MadnlpInterface::init(), casadi::MosekInterface::init(), casadi::XpressInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Qrqp::init(), casadi::Rosenbrock::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 3157 of file function_internal.cpp.

3158  {
3159  sz_arg = this->sz_arg();
3160  sz_res = this->sz_res();
3161  sz_iw = this->sz_iw();
3162  sz_w = this->sz_w();
3163  }

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 2043 of file function_internal.cpp.

2044  {
2045  // Strip rows and columns
2046  std::vector<casadi_int> mapping;
2047  return sp.sub(sparsity_out(oind).find(), sparsity_in(iind).find(), mapping);
2048  }

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 833 of file function_internal.cpp.

834  {
835  if (!values) {
836  trace << "null";
837  return;
838  }
839  trace << "[";
840  for (casadi_int i = 0; i < nnz; ++i) {
841  if (i) trace << ",";
842  double v = values[i];
843  if (isnan(v)) {
844  trace << "\"nan\"";
845  } else if (isinf(v)) {
846  trace << (v < 0 ? "\"-inf\"" : "\"inf\"");
847  } else {
848  normalized_out(trace, v);
849  }
850  }
851  trace << "]";
852  }

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 259 of file nlpsol_impl.hpp.

259 {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 3995 of file function_internal.cpp.

3997  {
3998  Function f = shared_from_this<Function>();
3999  f = f.wrap();
4000  return f.which_depends(s_in, s_out, order, tr);
4001  }

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 1251 of file function_internal.cpp.

1251  {
1252  Function f;
1253  if (!incache(name, f)) {
1254  // Options
1255  Dict opts;
1256  opts["derivative_of"] = derivative_of_;
1257  opts["ad_weight"] = ad_weight();
1258  opts["ad_weight_sp"] = sp_weight();
1259  opts["max_num_dir"] = max_num_dir_;
1260  opts["is_diff_in"] = is_diff_in_;
1261  opts["is_diff_out"] = is_diff_out_;
1262  // Wrap the function
1263  std::vector<MX> arg = mx_in();
1264  std::vector<MX> res = self()(arg);
1265  f = Function(name, arg, res, name_in_, name_out_, opts);
1266  // Save in cache
1267  tocache_if_missing(f);
1268  }
1269  return f;
1270  }

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 1226 of file function_internal.cpp.

1226  {
1227  return wrap_as_needed("wrap_" + name_, opts);
1228  }
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 1230 of file function_internal.cpp.

1230  {
1231  if (opts.empty() && name==name_) return shared_from_this<Function>();
1232  // Options
1233  Dict my_opts = opts;
1234  my_opts["derivative_of"] = derivative_of_;
1235  if (my_opts.find("ad_weight")==my_opts.end())
1236  my_opts["ad_weight"] = ad_weight();
1237  if (my_opts.find("ad_weight_sp")==my_opts.end())
1238  my_opts["ad_weight_sp"] = sp_weight();
1239  if (my_opts.find("max_num_dir")==my_opts.end())
1240  my_opts["max_num_dir"] = max_num_dir_;
1241  // Wrap the function
1242  std::vector<MX> arg = mx_in();
1243  std::vector<MX> res = self()(arg);
1244  return Function(name, arg, res, name_in_, name_out_, my_opts);
1245  }

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

◆ codegen_options_

Dict casadi::FunctionInternal::codegen_options_
inherited

◆ common_options_

Dict casadi::OracleFunction::common_options_
protectedinherited

◆ compiler_

Importer casadi::FunctionInternal::compiler_
inherited

◆ compiler_plugin_

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

◆ convexify_

bool casadi::FatropInterface::convexify_

Definition at line 160 of file fatrop_interface.hpp.

Referenced by FatropInterface(), init(), and serialize_body().

◆ convexify_data_

ConvexifyData casadi::FatropInterface::convexify_data_

Definition at line 157 of file fatrop_interface.hpp.

Referenced by init().

◆ custom_jacobian_

Function casadi::FunctionInternal::custom_jacobian_
inherited

◆ decref_

signal_t casadi::FunctionInternal::decref_
inherited

◆ der_options_

Dict casadi::FunctionInternal::der_options_
inherited

◆ derivative_of_

Function casadi::FunctionInternal::derivative_of_
inherited

◆ deserialize_map

std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> casadi::FunctionInternal::deserialize_map
staticinherited
Initial value:
= {
{"MXFunction", MXFunction::deserialize},
{"SXFunction", SXFunction::deserialize},
{"Interpolant", Interpolant::deserialize},
{"Switch", Switch::deserialize},
{"ForwardDiff", ForwardDiff::deserialize},
{"BackwardDiff", BackwardDiff::deserialize},
{"CentralDiff", CentralDiff::deserialize},
{"Smoothing", Smoothing::deserialize},
{"Map", Map::deserialize},
{"MapSum", MapSum::deserialize},
{"Nlpsol", Nlpsol::deserialize},
{"Rootfinder", Rootfinder::deserialize},
{"Integrator", Integrator::deserialize},
{"External", External::deserialize},
{"Conic", Conic::deserialize},
{"FmuFunction", FmuFunction::deserialize},
{"BlazingSplineFunction", BlazingSplineFunction::deserialize},
}
static ProtoFunction * deserialize(DeserializingStream &s)
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static ProtoFunction * deserialize(DeserializingStream &s)
void deserialize(DeserializingStream &s, SDPToSOCPMem &m)
Definition: conic.cpp:958
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:114
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: nlpsol.cpp:1435
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 1517 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::FatropInterface::exact_hessian_

◆ 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

◆ has_refcount_

bool casadi::FunctionInternal::has_refcount_
inherited

◆ has_refcount_in_deps_

bool casadi::FunctionInternal::has_refcount_in_deps_
inherited

◆ hesslag_sp_

Sparsity casadi::FatropInterface::hesslag_sp_

Definition at line 101 of file fatrop_interface.hpp.

Referenced by FatropInterface(), init(), serialize_body(), and set_fatrop_prob().

◆ incref_

signal_t casadi::FunctionInternal::incref_
inherited

◆ infix_

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

Definition at line 310 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_sp_

Sparsity casadi::FatropInterface::jacg_sp_

Definition at line 100 of file fatrop_interface.hpp.

Referenced by FatropInterface(), init(), serialize_body(), and set_fatrop_prob().

◆ 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 110 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::FatropInterface::meta_doc
static

Definition at line 152 of file fatrop_interface.hpp.

Referenced by casadi::casadi_register_nlpsol_fatrop().

◆ 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::RuntimeIntegrator::advance_noevent(), 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::RuntimeIntegrator::impulseB(), 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::RuntimeIntegrator::retreat(), 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(), casadi::ConoptInterface::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(), casadi::ConoptInterface::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(), casadi::ConoptInterface::init(), 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(), casadi::ConoptInterface::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(), casadi::ConoptInterface::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(), casadi::ConoptInterface::cb_fdevalini(), casadi::ConoptInterface::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(), casadi::ConoptInterface::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::Feasiblesqpmethod::Feasiblesqpmethod(), 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(), casadi::ConoptInterface::init(), 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(), casadi::ConoptInterface::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(), casadi::ConoptInterface::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().

◆ options_

const Options casadi::FatropInterface::options_
static

Definition at line 119 of file fatrop_interface.hpp.

Referenced by casadi::casadi_register_nlpsol_fatrop().

◆ opts_

Dict casadi::FatropInterface::opts_

Definition at line 149 of file fatrop_interface.hpp.

Referenced by codegen_body(), FatropInterface(), init(), serialize_body(), and solve().

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

bool casadi::Nlpsol::sens_force_equality_
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 303 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::RuntimeIntegrator::advance_noevent(), 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(), 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().

◆ warn_initial_bounds_

bool casadi::Nlpsol::warn_initial_bounds_
inherited

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