blazing_spline_impl.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 
26 #ifndef CASADI_BLAZING_SPLINE_IMPL_HPP
27 #define CASADI_BLAZING_SPLINE_IMPL_HPP
28 
29 #include "blazing_spline.hpp"
30 #include "function_internal.hpp"
31 
33 
34 namespace casadi {
35  class CASADI_EXPORT BlazingSplineFunction : public FunctionInternal {
36  public:
40  BlazingSplineFunction(
41  const std::string& name,
42  const std::vector< std::vector<double> >& knots,
43  casadi_int diff_order,
44  bool precompute_coeff = true,
45  bool precompute_grid = false);
46 
50  BlazingSplineFunction(
51  const std::string& name,
52  const std::vector<casadi_int>& knot_dims,
53  casadi_int diff_order,
54  bool precompute_coeff = false,
55  bool precompute_grid = false,
56  bool inv_input = false);
57 
61  std::string class_name() const override { return "BlazingSplineFunction";}
62 
66  ~BlazingSplineFunction() override;
67 
71  void merge(const std::vector<MX>& arg,
72  std::vector<MX>& subs_from, std::vector<MX>& subs_to) const override;
73 
75 
78  static const Options options_;
79  const Options& get_options() const override { return options_;}
81 
85  void init(const Dict& opts) override;
86 
87  void init_derived_members();
88 
92  bool has_codegen() const override { return true;}
93 
97  void codegen_body(CodeGenerator& g) const override;
98 
100 
103  bool has_jacobian() const override;
104  Function get_jacobian(const std::string& name,
105  const std::vector<std::string>& inames,
106  const std::vector<std::string>& onames,
107  const Dict& opts) const override;
109 
113  bool has_parametric_knots() const { return knots_.empty(); }
114 
118  casadi_int ndim() const { return knots_offset_.size()-1; }
119 
123  casadi_int arg_knots() const { return 2; }
124 
128  casadi_int arg_inv() const { return arg_knots() + 1; }
129 
130  casadi_int diff_order_;
131  bool precompute_coeff_ = false;
132  bool precompute_grid_ = false;
133  bool inv_input_ = false;
134  std::vector< std::vector<double> > knots_;
135  std::vector<std::string> lookup_modes_;
136  std::string pedantic_mode_order_ = "warn";
137  std::string pedantic_mode_size_ = "error";
138 
139  // Derived fields
140  std::vector<casadi_int> knots_offset_;
141  std::vector<double> knots_stacked_;
142  // Precomputed reciprocal knot spans (3 per knot per dim: inv1, inv2, inv3)
143  std::vector<double> knots_inv_;
144 
145  // Coefficient tensor size
146  casadi_int nc_, ndc_, nddc_;
147 
149 
152  size_t get_n_in() override;
153  size_t get_n_out() override;
155 
159  bool get_diff_in(casadi_int i) override;
160 
162 
165  Sparsity get_sparsity_in(casadi_int i) override;
166  Sparsity get_sparsity_out(casadi_int i) override;
168 
170 
173  std::string get_name_in(casadi_int i) override;
174  std::string get_name_out(casadi_int i) override;
176 
180  void serialize_body(SerializingStream &s) const override;
181 
185  static ProtoFunction* deserialize(DeserializingStream& s);
186 
190  std::string serialize_base_function() const override { return "BlazingSplineFunction"; }
191 
192  protected:
196  explicit BlazingSplineFunction(DeserializingStream& s);
197  };
198 
199 
200 } // namespace casadi
202 
203 #endif // CASADI_BLAZING_SPLINE_IMPL_HPP
The casadi namespace.
Definition: archiver.hpp:32
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.