25 #include "callback_internal.hpp"
29 #define TRY_CALL(FCN, OBJ, ...) \
31 casadi_assert((OBJ)!=0, "Callback object has been deleted"); \
32 return (OBJ)->FCN(__VA_ARGS__);\
33 } catch (std::exception& ex) { \
34 casadi_error("Error calling \"" CASADI_STR(FCN) "\" for object " \
35 + name_ + ":\n" + std::string(ex.what())); \
80 bool symmetric)
const {
89 casadi_assert(
self_!=
nullptr,
"Callback object has been deleted");
95 casadi_assert(
self_!=
nullptr,
"Callback object has been deleted");
105 for (casadi_int i=0;i<
n_in_;++i) {
109 for (casadi_int i=0;i<
n_out_;++i) {
121 casadi_int* iw,
double* w,
void* mem)
const {
122 setup(mem, arg, res, iw, w);
140 const std::vector<std::string>& inames,
141 const std::vector<std::string>& onames,
142 const Dict& opts)
const {
147 get_forward(casadi_int nfwd,
const std::string& name,
148 const std::vector<std::string>& inames,
149 const std::vector<std::string>& onames,
const Dict& opts)
const {
158 get_reverse(casadi_int nadj,
const std::string& name,
159 const std::vector<std::string>& inames,
160 const std::vector<std::string>& onames,
const Dict& opts)
const {
std::vector< DM > eval_dm(const std::vector< DM > &arg) const override
Evaluate with DM matrices.
void finalize() override
Finalize the object creation.
bool has_jacobian() const override
Return Jacobian of all input elements with respect to all output elements.
void init(const Dict &opts) override
Initialize.
std::string get_name_out(casadi_int i) override
Names of function input and outputs.
std::string get_name_in(casadi_int i) override
Names of function input and outputs.
size_t get_n_out() override
Number of function inputs and outputs.
Callback * self_
Pointer to the public class.
bool has_forward(casadi_int nfwd) const override
Return function that calculates forward derivatives.
std::vector< casadi_int > sizes_arg_
bool has_jac_sparsity(casadi_int oind, casadi_int iind) const override
Return sparsity of Jacobian of an output respect to an input.
Function get_jacobian(const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
Return Jacobian of all input elements with respect to all output elements.
~CallbackInternal() override
Destructor.
size_t get_n_in() override
Number of function inputs and outputs.
std::vector< casadi_int > sizes_res_
bool has_eval_dm() const override
Evaluate with DM matrices.
bool uses_output() const override
Do the derivative functions need nondifferentiated outputs?
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
Return function that calculates adjoint derivatives.
Function get_forward(casadi_int nfwd, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
Return function that calculates forward derivatives.
Sparsity get_sparsity_out(casadi_int i) override
Sparsities of function inputs and outputs.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
Evaluate numerically.
bool has_reverse(casadi_int nadj) const override
Return function that calculates adjoint derivatives.
Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const override
Return sparsity of Jacobian of an output respect to an input.
Sparsity get_sparsity_in(casadi_int i) override
Sparsities of function inputs and outputs.
bool has_eval_buffer() const
CallbackInternal(const std::string &name, Callback *self)
Constructor.
Callback function functionality.
Internal class for Function.
void init(const Dict &opts) override
Initialize.
void finalize() override
Finalize the object creation.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const
Evaluate numerically.
size_t n_in_
Number of inputs and outputs.
casadi_int nnz_in() const
Number of input/output nonzeros.
casadi_int nnz_out() const
Number of input/output nonzeros.
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
void clear_mem()
Clear all memory (called from destructor)
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.