All Classes Namespaces Functions 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 
19 template<typename T>
20 struct Size {
21  typedef ErrorType type;
22 };
23 
25 template<>
26 struct Size<double> {
27  typedef int type;
28 };
29 
31 template<typename Shape>
32 struct Size<Vector<Shape, double> > {
33  typedef int type;
34 };
35 
37 template<typename Shape>
38 struct Size<RowVector<Shape, double> > {
39  typedef int type;
40 };
41 
43 template<typename Type, typename RowShape, typename ColShape>
44 struct Size<Matrix<Type, RowShape, ColShape, double> > {
45  typedef Vector<Fixed<2>, int> type;
46 };
47 
53 template<typename T>
54 struct StaticSize {
55  enum { size1=0, size2=0 };
56 };
57 
59 template<>
60 struct StaticSize<double> {
61  enum { size1=1, size2=1 };
62 };
63 
65 template<typename Shape, typename AT>
66 struct StaticSize<Vector<Shape, AT> > {
67  enum { size1=0, size2=1 };
68 };
69 
71 template<typename Shape, typename AT>
72 struct StaticSize<RowVector<Shape, AT> > {
73  enum { size1=1, size2=0 };
74 };
75 
77 template<int N, typename AT>
78 struct StaticSize<Vector<Fixed<N>, AT> > {
79  enum { size1=N, size2=1 };
80 };
81 
83 template<int N, typename AT>
84 struct StaticSize<RowVector<Fixed<N>, AT> > {
85  enum { size1=1, size2=N };
86 };
87 
89 template<typename Storage, int N, int M, typename AT>
90 struct StaticSize<Matrix<Storage, Fixed<N>, Fixed<M>, AT> > {
91  enum { size1=N, size2=M };
92 };
93 
95 template<typename Storage, int N, typename ColShape, typename AT>
96 struct StaticSize<Matrix<Storage, Fixed<N>, ColShape, AT> > {
97  enum { size1=N, size2=0 };
98 };
99 
101 template<typename Storage, typename RowShape, int M, typename AT>
102 struct StaticSize<Matrix<Storage, RowShape, Fixed<M>, AT> > {
103  enum { size1=0, size2=M };
104 };
105 
110 template<typename Dep, typename Indep>
111 struct Der {
112  typedef ErrorType type;
113 };
114 
118 template<typename Dep>
119 struct Der<Dep, double> {
120  typedef Dep type;
121 };
122 
128 template<typename IndepVecShape>
129 struct Der<double, Vector<IndepVecShape, double> > {
131 };
132 
138 template<typename DepVecShape, typename IndepVecShape>
139 struct Der<Vector<DepVecShape, double>, Vector<IndepVecShape, double> > {
141 };
142 
153 template<typename DepMatShape>
154 struct Der<Matrix<Rotation, DepMatShape, DepMatShape, double>, double> {
156 };
157 
172 template<typename DepMatShape, typename IndepVecShape>
173 struct Der<Matrix<Rotation, DepMatShape, DepMatShape, double>, Vector<IndepVecShape, double> > {
175 };
176 
187 template<typename Sig>
188 class Function;
189 
191 template<typename Ret, typename Arg>
192 class Function<Ret(Arg)> : virtual public Atom {
193 
194  public:
195 
197  virtual typename Size<Arg>::type getArgSize() const {
198  throw std::runtime_error("getArgSize must be overloaded by derived class.");
199  }
200 
202  virtual Ret operator()(const Arg &arg)=0;
203 
205  virtual typename Der<Ret, Arg>::type parDer(const Arg &arg) {
206  throw std::runtime_error("parDer must be overloaded by derived class.");
207  }
208 
210  virtual Ret dirDer(const Arg &argDir, const Arg &arg) {
211  throw std::runtime_error("dirDer must be overloaded by derived class.");
212  }
213 
215  virtual typename Der<typename Der<Ret, Arg>::type, Arg>::type parDerParDer(const Arg &arg) {
216  throw std::runtime_error("parDerParDer must be overloaded by derived class.");
217  }
218 
220  virtual typename Der<Ret, Arg>::type parDerDirDer(const Arg &argDir, const Arg &arg) {
221  throw std::runtime_error("parDerDirDer must be overloaded by derived class.");
222  }
223 
225  // is constant.
226  virtual bool constParDer() const { return false; }
227 };
228 
230 template<typename Ret, typename Arg1, typename Arg2>
231 class Function<Ret(Arg1, Arg2)> : virtual public Atom {
232 
233  public:
234 
236  virtual typename Size<Arg1>::type getArg1Size() const {
237  throw std::runtime_error("getArg1Size must be overloaded by derived class.");
238  }
240  virtual typename Size<Arg2>::type getArg2Size() const {
241  throw std::runtime_error("getArg2Size must be overloaded by derived class.");
242  }
243 
245  virtual Ret operator()(const Arg1 &arg1, const Arg2 &arg2)=0;
246 
248  virtual typename Der<Ret, Arg1>::type parDer1(const Arg1 &arg1, const Arg2 &arg2) {
249  throw std::runtime_error("parDer1 must be overloaded by derived class.");
250  }
251 
253  virtual Ret dirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
254  throw std::runtime_error("dirDer1 must be overloaded by derived class.");
255  }
256 
258  virtual typename Der<Ret, Arg2>::type parDer2(const Arg1 &arg1, const Arg2 &arg2) {
259  throw std::runtime_error("parDer2 must be overloaded by derived class.");
260  }
261 
263  virtual Ret dirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2) {
264  throw std::runtime_error("dirDer2 must be overloaded by derived class.");
265  }
266 
268  virtual typename Der<typename Der<Ret, Arg1>::type, Arg1>::type parDer1ParDer1(const Arg1 &arg1, const Arg2 &arg2) {
269  throw std::runtime_error("parDer1ParDer1 must be overloaded by derived class.");
270  }
271 
273  virtual typename Der<Ret, Arg1>::type parDer1DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
274  throw std::runtime_error("parDer1DirDer1 must be overloaded by derived class.");
275  }
276 
278  virtual typename Der<typename Der<Ret, Arg2>::type, Arg2>::type parDer2ParDer2(const Arg1 &arg1, const Arg2 &arg2) {
279  throw std::runtime_error("parDer2ParDer2 must be overloaded by derived class.");
280  }
281 
283  virtual typename Der<Ret, Arg2>::type parDer2DirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2) {
284  throw std::runtime_error("parDer2DirDer2 must be overloaded by derived class.");
285  }
286 
288  virtual typename Der<typename Der<Ret, Arg1>::type, Arg2>::type parDer1ParDer2(const Arg1 &arg1, const Arg2 &arg2) {
289  throw std::runtime_error("parDer1ParDer2 must be overloaded by derived class.");
290  }
291 
293  virtual typename Der<Ret, Arg1>::type parDer1DirDer2(const Arg2 &arg2Dir, const Arg1 &arg1, const Arg2 &arg2) {
294  throw std::runtime_error("parDer1DirDer2 must be overloaded by derived class.");
295  }
296 
298  virtual typename Der<typename Der<Ret, Arg2>::type, Arg1>::type parDer2ParDer1(const Arg1 &arg1, const Arg2 &arg2) {
299  throw std::runtime_error("parDer2ParDer1 must be overloaded by derived class.");
300  }
301 
303  virtual typename Der<Ret, Arg2>::type parDer2DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2) {
304  throw std::runtime_error("parDer2DirDer1 must be overloaded by derived class.");
305  }
306 
308  // is constant.
309  virtual bool constParDer1() const { return false; }
310 
312  // is constant.
313  virtual bool constParDer2() const { return false; }
314 };
315 
316 // A function object with 3, 4, 5, ... arguments
317 // Not required till now!
318 
319 }
320 
321 #endif
virtual Der< Ret, Arg1 >::type parDer1(const Arg1 &arg1, const Arg2 &arg2)
First derivative: partial derivative of the function value with respect to the first argument...
Definition: function.h:248
Definition: types.h:68
virtual Size< Arg >::type getArgSize() const
Return the size of first argument.
Definition: function.h:197
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
virtual Der< typename Der< Ret, Arg1 >::type, Arg1 >::type parDer1ParDer1(const Arg1 &arg1, const Arg2 &arg2)
Second derivative: partial derivative of parDer1 with respect to the first argument.
Definition: function.h:268
virtual Der< typename Der< Ret, Arg2 >::type, Arg1 >::type parDer2ParDer1(const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: partial derivative of parDer2 with respect to the first argument.
Definition: function.h:298
Definition: atom.h:20
virtual Der< Ret, Arg2 >::type parDer2DirDer1(const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: directional derivative of parDer2 with respect to the first argument...
Definition: function.h:303
virtual Der< Ret, Arg >::type parDerDirDer(const Arg &argDir, const Arg &arg)
Second derivative: directional derivative of parDer with respect to the argument. ...
Definition: function.h:220
virtual Der< Ret, Arg2 >::type 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:283
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:210
Definition: matrix.h:218
Shape class for rotation matrices.
Definition: types.h:124
Definition: function.h:188
Definition: function.h:13
Definition: function.h:111
virtual Der< Ret, Arg1 >::type 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:293
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:263
virtual Size< Arg2 >::type getArg2Size() const
Return the size of first argument.
Definition: function.h:240
virtual Der< typename Der< Ret, Arg2 >::type, Arg2 >::type parDer2ParDer2(const Arg1 &arg1, const Arg2 &arg2)
Second derivative: partial derivative of parDer2 with respect to the first argument.
Definition: function.h:278
virtual bool constParDer() const
Returns true, if the partial derivative of the function value with respect to the argument...
Definition: function.h:226
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:253
Definition: matrix.h:215
virtual Der< typename Der< Ret, Arg1 >::type, Arg2 >::type parDer1ParDer2(const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: partial derivative of parDer1 with respect to the second argument...
Definition: function.h:288
virtual Der< Ret, Arg2 >::type parDer2(const Arg1 &arg1, const Arg2 &arg2)
First derivative: partial derivative of the function value with respect to the second argument...
Definition: function.h:258
virtual Size< Arg1 >::type getArg1Size() const
Return the size of first argument.
Definition: function.h:236
virtual bool constParDer2() const
Returns true, if the partial derivative of the function value with respect to the second argument...
Definition: function.h:313
virtual Der< Ret, Arg1 >::type 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:273
virtual Der< Ret, Arg >::type parDer(const Arg &arg)
First derivative: partial derivative of the function value with respect to the argument.
Definition: function.h:205
virtual Der< typename Der< Ret, Arg >::type, Arg >::type parDerParDer(const Arg &arg)
Second derivative: partial derivative of parDer with respect to the argument.
Definition: function.h:215
Definition: function.h:54
Definition: function.h:20
virtual bool constParDer1() const
Returns true, if the partial derivative of the function value with respect to the first argument...
Definition: function.h:309

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML