casadi/core/callback.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef CASADI_CALLBACK_HPP
26 #define CASADI_CALLBACK_HPP
27 
28 #include "function.hpp"
29 
30 namespace casadi {
32  class CallbackInternal;
33 
49  class CASADI_EXPORT Callback : public Function {
50  public:
54  static std::string type_name() {return "Callback";}
55 
59  Callback();
60 
64  Callback(const Callback& obj);
65 
69  virtual ~Callback();
70 
78  void construct(const std::string& name, const Dict& opts=Dict());
79 
88  virtual void init() {}
89 
98  virtual void finalize() {}
99 
106  virtual std::vector<DM> eval(const std::vector<DM>& arg) const;
107 
116  virtual int eval_buffer(const double **arg, const std::vector<casadi_int>& sizes_arg,
117  double **res, const std::vector<casadi_int>& sizes_res) const;
122  virtual bool has_eval_buffer() const;
123 
129  virtual casadi_int get_n_in();
130 
136  virtual casadi_int get_n_out();
137 
143  virtual Sparsity get_sparsity_in(casadi_int i);
144 
150  virtual Sparsity get_sparsity_out(casadi_int i);
151 
157  virtual std::string get_name_in(casadi_int i);
158 
164  virtual std::string get_name_out(casadi_int i);
165 
169  virtual bool uses_output() const;
170 
172 
175  virtual bool has_jacobian() const;
176  virtual Function get_jacobian(const std::string& name,
177  const std::vector<std::string>& inames,
178  const std::vector<std::string>& onames,
179  const Dict& opts) const;
181 
183 
190  virtual bool has_forward(casadi_int nfwd) const;
191  virtual Function get_forward(casadi_int nfwd, const std::string& name,
192  const std::vector<std::string>& inames,
193  const std::vector<std::string>& onames,
194  const Dict& opts) const;
196 
198 
205  virtual bool has_reverse(casadi_int nadj) const;
206  virtual Function get_reverse(casadi_int nadj, const std::string& name,
207  const std::vector<std::string>& inames,
208  const std::vector<std::string>& onames,
209  const Dict& opts) const;
211 
213 
218  virtual bool has_jac_sparsity(casadi_int oind, casadi_int iind) const { return false; }
219  virtual Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const {
220  return Sparsity(); }
222  };
223 
224 } // namespace casadi
225 
226 #endif // CASADI_CALLBACK_HPP
Callback function functionality.
virtual void finalize()
Finalize the object.
virtual void init()
Initialize the object.
virtual bool has_jac_sparsity(casadi_int oind, casadi_int iind) const
Return sparsity of Jacobian of all input elements.
static std::string type_name()
Get type name.
virtual Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const
Return sparsity of Jacobian of all input elements.
Function object.
Definition: function.hpp:60
General sparsity class.
Definition: sparsity.hpp:106
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.