All Classes Namespaces Functions Variables Typedefs Enumerations Pages
function.h
1 #ifndef _FMATVEC_FUNCTION_H_
2 #define _FMATVEC_FUNCTION_H_
3 
4 #include <fmatvec/fmatvec.h>
5 #include <fmatvec/atom.h>
6 #include <stdexcept>
7 
8 namespace fmatvec {
9 
13 class ErrorType {
14 #if !defined(SWIG) && !defined(MBSIM_COMPILE_SWIG)
15  ErrorType() = delete;
16 #else
17  // SWIG instantiats everything. Hence, we allow this for SWIG but throw a runtime error
18  public:
19  ErrorType() {
20  throw std::runtime_error("Impossible type.");
21  }
22 #endif
23 };
24 
29 template<typename T>
30 struct StaticSize;
31 
33 template<>
34 struct StaticSize<int> {
35  enum { size1=1, size2=1 };
36 };
37 
39 template<>
40 struct StaticSize<double> {
41  enum { size1=1, size2=1 };
42 };
43 
45 template<typename Shape, typename AT>
46 struct StaticSize<Vector<Shape, AT> > {
47  enum { size1=0, size2=1 };
48 };
49 
51 template<typename Shape, typename AT>
52 struct StaticSize<RowVector<Shape, AT> > {
53  enum { size1=1, size2=0 };
54 };
55 
57 template<int N, typename AT>
58 struct StaticSize<Vector<Fixed<N>, AT> > {
59  enum { size1=N, size2=1 };
60 };
61 
63 template<int N, typename AT>
64 struct StaticSize<RowVector<Fixed<N>, AT> > {
65  enum { size1=1, size2=N };
66 };
67 
69 template<typename Storage, typename RowShape, typename ColShape, typename AT>
70 struct StaticSize<Matrix<Storage, RowShape, ColShape, AT> > {
71  enum { size1=0, size2=0 };
72 };
73 
75 template<typename Storage, int N, int M, typename AT>
76 struct StaticSize<Matrix<Storage, Fixed<N>, Fixed<M>, AT> > {
77  enum { size1=N, size2=M };
78 };
79 
81 template<typename Storage, int N, typename ColShape, typename AT>
82 struct StaticSize<Matrix<Storage, Fixed<N>, ColShape, AT> > {
83  enum { size1=N, size2=0 };
84 };
85 
87 template<typename Storage, typename RowShape, int M, typename AT>
88 struct StaticSize<Matrix<Storage, RowShape, Fixed<M>, AT> > {
89  enum { size1=0, size2=M };
90 };
91 
93 template<int N, typename AT>
94 struct StaticSize<SquareMatrix<Fixed<N>, AT> > {
95  enum { size1=N, size2=N };
96 };
97 
99 template<typename Shape, typename AT>
100 struct StaticSize<SquareMatrix<Shape, AT> > {
101  enum { size1=0, size2=0 };
102 };
103 
107 template<typename Dep, typename Indep>
108 struct Der {
109  typedef ErrorType type;
110 };
111 
115 template<typename Dep>
116 struct Der<Dep, double> {
117  typedef Dep type;
118 };
119 
125 template<typename IndepVecShape>
126 struct Der<double, Vector<IndepVecShape, double> > {
128 };
129 
135 template<typename DepVecShape, typename IndepVecShape>
136 struct Der<Vector<DepVecShape, double>, Vector<IndepVecShape, double> > {
138 };
139 
150 template<>
151 struct Der<Matrix<Rotation, Fixed<3>, Fixed<3>, double>, double> {
152  typedef Vector<Fixed<3>, double> type;
153 };
154 
169 template<typename IndepVecShape>
170 struct Der<Matrix<Rotation, Fixed<3>, Fixed<3>, double>, Vector<IndepVecShape, double> > {
171  typedef Matrix<General, Fixed<3>, IndepVecShape, double> type;
172 };
173 
184 template<typename Sig>
185 class Function;
186 
188 template<typename Ret, typename Arg>
189 class Function<Ret(Arg)> : virtual public Atom {
190 
191  public:
192 
193  using DRetDArg = typename Der<Ret, Arg>::type;
194  using DDRetDDArg = typename Der<DRetDArg, Arg>::type;
195 
197  enum { retSize1 = StaticSize<Ret>::size1, retSize2 = StaticSize<Ret>::size2 };
198 
200  static constexpr int argSize = StaticSize<Arg>::size1;
201 
203  virtual std::pair<int, int> getRetSize() const { return std::make_pair(retSize1, retSize2); }
204 
206  virtual int getArgSize() const { return argSize; }
207 
209  virtual Ret operator()(const Arg &arg)=0;
210 
212  virtual DRetDArg parDer(const Arg &arg) {
213  throw std::runtime_error("parDer must be overloaded by derived class.");
214  }
215 
217  virtual Ret dirDer(const Arg &argDir, const Arg &arg) {
218  throw std::runtime_error("dirDer must be overloaded by derived class.");
219  }
220 
222  virtual DDRetDDArg parDerParDer(const Arg &arg) {
223  throw std::runtime_error("parDerParDer must be overloaded by derived class.");
224  }
225 
227  virtual DRetDArg parDerDirDer(const Arg &argDir, const Arg &arg) {
228  throw std::runtime_error("parDerDirDer must be overloaded by derived class.");
229  }
230 
232  virtual Ret dirDerDirDer(const Arg &argDir_1, const Arg &argDir_2, const Arg &arg) {
233  throw std::runtime_error("dirDerDirDer must be overloaded by derived class.");
234  }
235 
237  // is constant.
238  virtual bool constParDer() const { return false; }
239 };
240 
242 template<typename Ret, typename Arg1, typename Arg2>
243 class Function<Ret(Arg1, Arg2)> : virtual public Atom {
244 
245  public:
246 
247  using DRetDArg1 = typename Der<Ret, Arg1>::type;
248  using DRetDArg2 = typename Der<Ret, Arg2>::type;
249  using DDRetDDArg1 = typename Der<DRetDArg1, Arg1>::type;
250  using DDRetDDArg2 = typename Der<DRetDArg2, Arg2>::type;
251  using DDRetDArg1DArg2 = typename Der<DRetDArg1, Arg2>::type;
252 
254  enum { retSize1 = StaticSize<Ret>::size1, retSize2 = StaticSize<Ret>::size2 };
255 
257  static constexpr int arg1Size = StaticSize<Arg1>::size1;
258 
260  static constexpr int arg2Size = StaticSize<Arg2>::size1;
261 
263  virtual std::pair<int, int> getRetSize() const { return std::make_pair(retSize1, retSize2); }
264 
266  virtual int getArg1Size() const { return arg1Size; }
268  virtual int getArg2Size() const { return arg2Size; }
269 
271  virtual Ret operator()(const Arg1 &arg1, const Arg2 &arg2)=0;
272 
274  virtual DRetDArg1 parDer1(const Arg1 &arg1, const Arg2 &arg2) {
275  throw std::runtime_error("parDer1 must be overloaded by derived class.");
276  }
277 
279  virtual Ret dirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
280  throw std::runtime_error("dirDer1 must be overloaded by derived class.");
281  }
282 
284  virtual DRetDArg2 parDer2(const Arg1 &arg1, const Arg2 &arg2) {
285  throw std::runtime_error("parDer2 must be overloaded by derived class.");
286  }
287 
289  virtual Ret dirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2) {
290  throw std::runtime_error("dirDer2 must be overloaded by derived class.");
291  }
292 
294  virtual DDRetDDArg1 parDer1ParDer1(const Arg1 &arg1, const Arg2 &arg2) {
295  throw std::runtime_error("parDer1ParDer1 must be overloaded by derived class.");
296  }
297 
299  virtual DRetDArg1 parDer1DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
300  throw std::runtime_error("parDer1DirDer1 must be overloaded by derived class.");
301  }
302 
304  virtual Ret dirDer1DirDer1(const Arg1 &arg1Dir_1, const Arg1 &arg1Dir_2, const Arg1 &arg1, const Arg2 &arg2) {
305  throw std::runtime_error("dirDer1DirDer1 must be overloaded by derived class.");
306  }
307 
309  virtual DDRetDDArg2 parDer2ParDer2(const Arg1 &arg1, const Arg2 &arg2) {
310  throw std::runtime_error("parDer2ParDer2 must be overloaded by derived class.");
311  }
312 
314  virtual DRetDArg2 parDer2DirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2) {
315  throw std::runtime_error("parDer2DirDer2 must be overloaded by derived class.");
316  }
317 
319  virtual Ret dirDer2DirDer2(const Arg2 &arg2Dir_1, const Arg2 &arg2Dir_2, const Arg1 &arg1, const Arg2 &arg2) {
320  throw std::runtime_error("dirDer2DirDer2 must be overloaded by derived class.");
321  }
322 
324  virtual DDRetDArg1DArg2 parDer1ParDer2(const Arg1 &arg1, const Arg2 &arg2) {
325  throw std::runtime_error("parDer1ParDer2 must be overloaded by derived class.");
326  }
327 
329  virtual DRetDArg1 parDer1DirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2) {
330  throw std::runtime_error("parDer1DirDer2 must be overloaded by derived class.");
331  }
332 
334  virtual Ret dirDer2DirDer1(const Arg2 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
335  throw std::runtime_error("dirDer2DirDer1 must be overloaded by derived class.");
336  }
337 
339  virtual DRetDArg2 parDer2DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
340  throw std::runtime_error("parDer2DirDer1 must be overloaded by derived class.");
341  }
342 
344  // is constant.
345  virtual bool constParDer1() const { return false; }
346 
348  // is constant.
349  virtual bool constParDer2() const { return false; }
350 };
351 
352 // A function object with 3, 4, 5, ... arguments
353 // Not required till now!
354 
355 }
356 
357 #endif
virtual DDRetDArg1DArg2 parDer1ParDer2(const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: partial derivative of parDer1 with respect to the second argument...
Definition: function.h:324
Definition: fmatvec.h:38
virtual DDRetDDArg2 parDer2ParDer2(const Arg1 &arg1, const Arg2 &arg2)
Second derivative: partial derivative of parDer2 with respect to the first argument.
Definition: function.h:309
virtual DRetDArg parDer(const Arg &arg)
First derivative: partial derivative of the function value with respect to the argument.
Definition: function.h:212
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
virtual Ret dirDerDirDer(const Arg &argDir_1, const Arg &argDir_2, const Arg &arg)
Second derivative: directional derivative of dirDer with respect to the argument. ...
Definition: function.h:232
virtual DRetDArg1 parDer1DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2)
Second derivative: directional derivative of parDer1 with respect to the first argument.
Definition: function.h:299
Definition: atom.h:18
virtual int getArg2Size() const
Return the size of the second argument: =1 == scalar; &gt;1 == vector; =0 == unknown vector size...
Definition: function.h:268
virtual Ret dirDer(const Arg &argDir, const Arg &arg)
First derivative: directional derivative of the function value with respect to the argument...
Definition: function.h:217
Definition: fmatvec.h:50
Shape class for rotation matrices.
Definition: types.h:124
Definition: function.h:185
virtual int getArgSize() const
Return the size of the argument: =1 == scalar; &gt;1 == vector; =0 == unknown vector size...
Definition: function.h:206
Definition: function.h:13
Definition: function.h:108
virtual int getArg1Size() const
Return the size of the first argument: =1 == scalar; &gt;1 == vector; =0 == unknown vector size...
Definition: function.h:266
virtual Ret dirDer2DirDer1(const Arg2 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: directional derivative of dirDer2 with respect to the first argument...
Definition: function.h:334
virtual std::pair< int, int > getRetSize() const
Return the size of the return value: =0 == unknown size.
Definition: function.h:263
virtual Ret dirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2)
First derivative: directional derivative of the function value with respect to the second argument...
Definition: function.h:289
virtual bool constParDer() const
Returns true, if the partial derivative of the function value with respect to the argument...
Definition: function.h:238
virtual Ret dirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2)
First derivative: directional derivative of the function value with respect to the first argument...
Definition: function.h:279
Definition: fmatvec.h:44
Definition: fmatvec.h:47
virtual DRetDArg1 parDer1DirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: directional derivative of parDer1 with respect to the second argument...
Definition: function.h:329
virtual DRetDArg2 parDer2DirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2)
Second derivative: directional derivative of parDer2 with respect to the first argument.
Definition: function.h:314
virtual Ret dirDer2DirDer2(const Arg2 &arg2Dir_1, const Arg2 &arg2Dir_2, const Arg1 &arg1, const Arg2 &arg2)
Second derivative: directional derivative of dirDer2 with respect to the first argument.
Definition: function.h:319
virtual Ret dirDer1DirDer1(const Arg1 &arg1Dir_1, const Arg1 &arg1Dir_2, const Arg1 &arg1, const Arg2 &arg2)
Second derivative: directional derivative of dirDer1 with respect to the first argument.
Definition: function.h:304
virtual bool constParDer2() const
Returns true, if the partial derivative of the function value with respect to the second argument...
Definition: function.h:349
virtual DDRetDDArg1 parDer1ParDer1(const Arg1 &arg1, const Arg2 &arg2)
Second derivative: partial derivative of parDer1 with respect to the first argument.
Definition: function.h:294
Definition: function.h:30
virtual DRetDArg parDerDirDer(const Arg &argDir, const Arg &arg)
Second derivative: directional derivative of parDer with respect to the argument. ...
Definition: function.h:227
virtual std::pair< int, int > getRetSize() const
Return the size of the return value: =0 == unknown size.
Definition: function.h:203
virtual DRetDArg2 parDer2(const Arg1 &arg1, const Arg2 &arg2)
First derivative: partial derivative of the function value with respect to the second argument...
Definition: function.h:284
virtual DDRetDDArg parDerParDer(const Arg &arg)
Second derivative: partial derivative of parDer with respect to the argument.
Definition: function.h:222
virtual DRetDArg1 parDer1(const Arg1 &arg1, const Arg2 &arg2)
First derivative: partial derivative of the function value with respect to the first argument...
Definition: function.h:274
virtual DRetDArg2 parDer2DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: partial derivative of dirDer1 with respect to the second argument...
Definition: function.h:339
virtual bool constParDer1() const
Returns true, if the partial derivative of the function value with respect to the first argument...
Definition: function.h:345

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML