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 
266  class CASADI_EXPORT Callback : public Function {
267  public:
271  static std::string type_name() {return "Callback";}
272 
278  Callback();
279 
331  Callback(const Callback& obj);
332 
338  virtual ~Callback();
339 
405  void construct(const std::string& name, const Dict& opts=Dict());
406 
471  virtual void init() {}
472 
479  virtual void finalize() {}
480 
570  virtual std::vector<DM> eval(const std::vector<DM>& arg) const;
571 
614  virtual int eval_buffer(const double **arg, const std::vector<casadi_int>& sizes_arg,
615  double **res, const std::vector<casadi_int>& sizes_res) const;
621  virtual bool has_eval_buffer() const;
622 
628  virtual casadi_int get_n_in();
629 
680  virtual casadi_int get_n_out();
681 
735  virtual Sparsity get_sparsity_in(casadi_int i);
736 
743  virtual Sparsity get_sparsity_out(casadi_int i);
744 
807  virtual std::string get_name_in(casadi_int i);
808 
814  virtual std::string get_name_out(casadi_int i);
815 
884  virtual bool uses_output() const;
885 
892  virtual Function get_factory(const std::string& name,
893  const std::vector<std::string>& s_in,
894  const std::vector<std::string>& s_out,
895  const Function::AuxOut& aux,
896  const Dict& opts) const;
897 
899 
1005  virtual bool has_jacobian() const;
1006  virtual Function get_jacobian(const std::string& name,
1007  const std::vector<std::string>& inames,
1008  const std::vector<std::string>& onames,
1009  const Dict& opts) const;
1011 
1013 
1091  virtual bool has_forward(casadi_int nfwd) const;
1092  virtual Function get_forward(casadi_int nfwd, const std::string& name,
1093  const std::vector<std::string>& inames,
1094  const std::vector<std::string>& onames,
1095  const Dict& opts) const;
1097 
1099 
1177  virtual bool has_reverse(casadi_int nadj) const;
1178  virtual Function get_reverse(casadi_int nadj, const std::string& name,
1179  const std::vector<std::string>& inames,
1180  const std::vector<std::string>& onames,
1181  const Dict& opts) const;
1183 
1185 
1266  virtual bool has_jac_sparsity(casadi_int oind, casadi_int iind) const { return false; }
1267  virtual Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const {
1268  return Sparsity(); }
1270  };
1271 
1272 } // namespace casadi
1273 
1274 #endif // CASADI_CALLBACK_HPP
User-defined Function implemented by subclassing.
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:126
std::map< std::string, std::vector< std::string > > AuxOut
Definition: function.hpp:1546
General sparsity class.
Definition: sparsity.hpp:200
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.