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 (KeyboardInterruptException&) { \
35 } catch (std::exception& ex) { \
36 casadi_error("Error calling \"" CASADI_STR(FCN) "\" for object " \
37 + name_ + ":\n" + std::string(ex.what())); \
82 bool symmetric)
const {
91 casadi_assert(
self_!=
nullptr,
"Callback object has been deleted");
97 casadi_assert(
self_!=
nullptr,
"Callback object has been deleted");
107 for (casadi_int i=0;i<
n_in_;++i) {
111 for (casadi_int i=0;i<
n_out_;++i) {
123 casadi_int* iw,
double* w,
void* mem)
const {
124 setup(mem, arg, res, iw, w);
137 const std::vector<std::string>& s_in,
138 const std::vector<std::string>& s_out,
140 const Dict& opts)
const {
141 TRY_CALL(get_factory,
self_, name, s_in, s_out, aux, opts);
150 const std::vector<std::string>& inames,
151 const std::vector<std::string>& onames,
152 const Dict& opts)
const {
157 get_forward(casadi_int nfwd,
const std::string& name,
158 const std::vector<std::string>& inames,
159 const std::vector<std::string>& onames,
const Dict& opts)
const {
168 get_reverse(casadi_int nadj,
const std::string& name,
169 const std::vector<std::string>& inames,
170 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_
Function factory(const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux, const Dict &opts) const override
Customize calls to the function factory.
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.
User-defined Function implemented by subclassing.
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.
std::map< std::string, std::vector< std::string > > AuxOut
void clear_mem()
Clear all memory (called from destructor)
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.