1 #ifndef _FMATVEC_FUNCTION_H_ 2 #define _FMATVEC_FUNCTION_H_ 4 #include <fmatvec/fmatvec.h> 5 #include <fmatvec/atom.h> 14 #if !defined(SWIG) && !defined(MBSIM_COMPILE_SWIG) 20 throw std::runtime_error(
"Impossible type.");
35 enum { size1=1, size2=1 };
41 enum { size1=1, size2=1 };
45 template<
typename Shape,
typename AT>
47 enum { size1=0, size2=1 };
51 template<
typename Shape,
typename AT>
53 enum { size1=1, size2=0 };
57 template<
int N,
typename AT>
59 enum { size1=N, size2=1 };
63 template<
int N,
typename AT>
65 enum { size1=1, size2=N };
69 template<
typename Storage,
typename RowShape,
typename ColShape,
typename AT>
71 enum { size1=0, size2=0 };
75 template<
typename Storage,
int N,
int M,
typename AT>
77 enum { size1=N, size2=M };
81 template<
typename Storage,
int N,
typename ColShape,
typename AT>
83 enum { size1=N, size2=0 };
87 template<
typename Storage,
typename RowShape,
int M,
typename AT>
89 enum { size1=0, size2=M };
93 template<
int N,
typename AT>
95 enum { size1=N, size2=N };
99 template<
typename Shape,
typename AT>
101 enum { size1=0, size2=0 };
107 template<
typename Dep,
typename Indep>
115 template<
typename Dep>
125 template<
typename IndepVecShape>
135 template<
typename DepVecShape,
typename IndepVecShape>
169 template<
typename IndepVecShape>
177 template<
typename Dep,
typename Indep>
185 template<
typename Indep>
200 template<
typename Sig>
204 template<
typename Ret,
typename Arg>
210 using DRetDDir =
typename DirDer<Ret, Arg>::type;
220 virtual std::pair<int, int>
getRetSize()
const {
return std::make_pair(retSize1, retSize2); }
226 virtual Ret operator()(
const Arg &arg)=0;
229 virtual DRetDArg
parDer(
const Arg &arg) {
230 throw std::runtime_error(
"parDer must be overloaded by derived class.");
234 virtual DRetDDir
dirDer(
const Arg &argDir,
const Arg &arg) {
235 if constexpr (std::is_same_v<DRetDArg, ErrorType>)
236 throw std::runtime_error(
"dirDer must be overloaded by derived class.");
238 return parDer(arg) * argDir;
243 throw std::runtime_error(
"parDerParDer must be overloaded by derived class.");
248 if constexpr (std::is_same_v<DDRetDDArg, ErrorType>)
249 throw std::runtime_error(
"parDerDirDer must be overloaded by derived class.");
251 return parDerParDer(arg) * argDir;
255 virtual DRetDDir
dirDerDirDer(
const Arg &argDir_1,
const Arg &argDir_2,
const Arg &arg) {
256 if constexpr (std::is_same_v<DRetDArg, ErrorType>)
257 throw std::runtime_error(
"dirDerDirDer must be overloaded by derived class.");
259 return parDerDirDer(argDir_2, arg) * argDir_1;
268 template<
typename Ret,
typename Arg1,
typename Arg2>
274 using DRetDDir1 =
typename DirDer<Ret, Arg1>::type;
275 using DRetDDir2 =
typename DirDer<Ret, Arg2>::type;
290 virtual std::pair<int, int>
getRetSize()
const {
return std::make_pair(retSize1, retSize2); }
298 virtual Ret operator()(
const Arg1 &arg1,
const Arg2 &arg2)=0;
301 virtual DRetDArg1
parDer1(
const Arg1 &arg1,
const Arg2 &arg2) {
302 throw std::runtime_error(
"parDer1 must be overloaded by derived class.");
306 virtual DRetDDir1
dirDer1(
const Arg1 &arg1Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
307 if constexpr (std::is_same_v<DRetDArg1, ErrorType>)
308 throw std::runtime_error(
"dirDer1 must be overloaded by derived class.");
310 return parDer1(arg1, arg2) * arg1Dir;
314 virtual DRetDArg2
parDer2(
const Arg1 &arg1,
const Arg2 &arg2) {
315 throw std::runtime_error(
"parDer2 must be overloaded by derived class.");
319 virtual DRetDDir2
dirDer2(
const Arg2 &arg2Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
320 if constexpr (std::is_same_v<DRetDArg2, ErrorType>)
321 throw std::runtime_error(
"dirDer2 must be overloaded by derived class.");
323 return parDer2(arg1, arg2) * arg2Dir;
328 throw std::runtime_error(
"parDer1ParDer1 must be overloaded by derived class.");
332 virtual DRetDArg1
parDer1DirDer1(
const Arg1 &arg1Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
333 if constexpr (std::is_same_v<DDRetDDArg1, ErrorType>)
334 throw std::runtime_error(
"parDer1DirDer1 must be overloaded by derived class.");
336 return parDer1ParDer1(arg1, arg2) * arg1Dir;
340 virtual DRetDDir1
dirDer1DirDer1(
const Arg1 &arg1Dir_1,
const Arg1 &arg1Dir_2,
const Arg1 &arg1,
const Arg2 &arg2) {
341 if constexpr (std::is_same_v<DDRetDDArg1, ErrorType>)
342 throw std::runtime_error(
"dirDer1DirDer1 must be overloaded by derived class.");
344 return parDer1ParDer1(arg1, arg2) * arg1Dir_1 * arg1Dir_2;
349 throw std::runtime_error(
"parDer2ParDer2 must be overloaded by derived class.");
353 virtual DRetDArg2
parDer2DirDer2(
const Arg2 &arg2Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
354 if constexpr (std::is_same_v<DDRetDDArg2, ErrorType>)
355 throw std::runtime_error(
"parDer2DirDer2 must be overloaded by derived class.");
357 return parDer2ParDer2(arg1, arg2) * arg2Dir;
361 virtual DRetDDir2
dirDer2DirDer2(
const Arg2 &arg2Dir_1,
const Arg2 &arg2Dir_2,
const Arg1 &arg1,
const Arg2 &arg2) {
362 if constexpr (std::is_same_v<DDRetDDArg2, ErrorType>)
363 throw std::runtime_error(
"dirDer2DirDer2 must be overloaded by derived class.");
365 return parDer2ParDer2(arg1, arg2) * arg2Dir_1 * arg2Dir_2;
370 throw std::runtime_error(
"parDer1ParDer2 must be overloaded by derived class.");
374 virtual DRetDArg1
parDer1DirDer2(
const Arg2 &arg2Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
375 if constexpr (std::is_same_v<DDRetDArg1DArg2, ErrorType>)
376 throw std::runtime_error(
"parDer1DirDer2 must be overloaded by derived class.");
378 return parDer1ParDer2(arg1, arg2) * arg2Dir;
382 virtual DRetDDir2
dirDer2DirDer1(
const Arg2 &arg2Dir,
const Arg1 &arg1Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
383 if constexpr (std::is_same_v<DDRetDArg1DArg2, ErrorType>)
384 throw std::runtime_error(
"dirDer2DirDer1 must be overloaded by derived class.");
386 return parDer1ParDer2(arg1, arg2) * arg2Dir * arg1Dir;
390 virtual DRetDArg2
parDer2DirDer1(
const Arg1 &arg1Dir,
const Arg1 &arg1,
const Arg2 &arg2) {
391 if constexpr (std::is_same_v<DDRetDArg1DArg2, ErrorType>)
392 throw std::runtime_error(
"parDer2DirDer1 must be overloaded by derived class.");
394 return parDer1ParDer2(arg1, arg2) * arg1Dir;
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:369
virtual DRetDDir2 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:361
virtual std::pair< int, int > getRetSize() const
Return the size of the return value: =0 == unknown size.
Definition: function.h:220
virtual DDRetDDArg2 parDer2ParDer2(const Arg1 &arg1, const Arg2 &arg2)
Second derivative: partial derivative of parDer2 with respect to the first argument.
Definition: function.h:348
virtual DRetDArg parDer(const Arg &arg)
First derivative: partial derivative of the function value with respect to the argument.
Definition: function.h:229
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
virtual DRetDDir1 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:306
virtual bool constParDer() const
Returns true, if the partial derivative of the function value with respect to the argument.
Definition: function.h:264
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:332
virtual DRetDDir2 dirDer2DirDer1(const Arg2 &arg2Dir, const Arg1 &arg1Dir, const Arg1 &arg1, const Arg2 &arg2)
Second mixed derivative: directional derivative of dirDer2 with respect to the first argument.
Definition: function.h:382
virtual DRetDDir dirDer(const Arg &argDir, const Arg &arg)
First derivative: directional derivative of the function value with respect to the argument.
Definition: function.h:234
Shape class for rotation matrices.
Definition: types.h:160
Definition: function.h:201
Definition: function.h:13
Definition: function.h:108
virtual int getArgSize() const
Return the size of the argument: =1 == scalar; >1 == vector; =0 == unknown vector size.
Definition: function.h:223
virtual DRetDDir 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:255
virtual DRetDDir1 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:340
virtual int getArg2Size() const
Return the size of the second argument: =1 == scalar; >1 == vector; =0 == unknown vector size.
Definition: function.h:295
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:374
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:353
virtual int getArg1Size() const
Return the size of the first argument: =1 == scalar; >1 == vector; =0 == unknown vector size.
Definition: function.h:293
Namespace fmatvec.
Definition: _memory.cc:28
virtual std::pair< int, int > getRetSize() const
Return the size of the return value: =0 == unknown size.
Definition: function.h:290
virtual DDRetDDArg1 parDer1ParDer1(const Arg1 &arg1, const Arg2 &arg2)
Second derivative: partial derivative of parDer1 with respect to the first argument.
Definition: function.h:327
Definition: function.h:30
virtual bool constParDer1() const
Returns true, if the partial derivative of the function value with respect to the first argument.
Definition: function.h:399
virtual DRetDArg parDerDirDer(const Arg &argDir, const Arg &arg)
Second derivative: directional derivative of parDer with respect to the argument.
Definition: function.h:247
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:314
virtual DRetDDir2 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:319
virtual DDRetDDArg parDerParDer(const Arg &arg)
Second derivative: partial derivative of parDer with respect to the argument.
Definition: function.h:242
virtual bool constParDer2() const
Returns true, if the partial derivative of the function value with respect to the second argument.
Definition: function.h:403
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:301
Definition: function.h:178
SymbolicExpression parDer(const SymbolicExpression &dep, const IndependentVariable &indep)
Definition: ast.cc:264
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:390