-
Notifications
You must be signed in to change notification settings - Fork 1
/
funcderivatives.h
47 lines (35 loc) · 1.25 KB
/
funcderivatives.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef JWUTIL_FUNCDERIVATIVES_H
#define JWUTIL_FUNCDERIVATIVES_H
#include <type_traits>
#include "multidimmatrix.h"
#include "fastmath.h"
namespace jw_util
{
class _FuncDerivatiesBaseEmpty {};
template <unsigned int vars, unsigned int derivatives, typename BaseType = float>
class FuncDerivatives : public std::conditional<derivatives != 0, FuncDerivatives<vars, derivatives - 1, BaseType>, _FuncDerivatiesBaseEmpty>::type
{
template <unsigned int, unsigned int, typename>
friend class FuncDerivatives;
public:
FuncDerivatives()
{
matrix.set_zero();
}
template <unsigned int d>
MultiDimMatrix<vars, d, BaseType> &get_deriv()
{
static_assert(d <= derivatives, "FuncDerivatives<vars, derivatives>::get_deriv<d>(): d must not be greater than derivatives");
return FuncDerivatives<vars, d, BaseType>::matrix;
}
template <unsigned int d>
const MultiDimMatrix<vars, d, BaseType> &get_deriv() const
{
static_assert(d <= derivatives, "FuncDerivatives<vars, derivatives>::get_deriv<d>(): d must not be greater than derivatives");
return FuncDerivatives<vars, d, BaseType>::matrix;
}
private:
MultiDimMatrix<vars, derivatives, BaseType> matrix;
};
}
#endif // JWUTIL_FUNCDERIVATIVES_H