forked from yixuan/RcppNumerical
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunc.h
More file actions
60 lines (42 loc) · 1.13 KB
/
Func.h
File metadata and controls
60 lines (42 loc) · 1.13 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (C) 2016 Yixuan Qiu <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef FUNC_H
#define FUNC_H
#include <RcppEigen.h>
namespace Numer
{
// Reference to a vector
typedef Eigen::Ref<Eigen::VectorXd> Refvec;
typedef const Eigen::Ref<const Eigen::VectorXd> Constvec;
// For 1-D numerical integration
class Func
{
public:
virtual double operator()(const double& x) const = 0;
virtual void eval(double* x, const int n) const
{
for(int i = 0; i < n; i++)
x[i] = this->operator()(x[i]);
}
virtual ~Func() {}
};
// For multi-dimensional numerical integration and
// optimization that does not require gradient
class MFunc
{
public:
virtual double operator()(Constvec& x) = 0;
virtual ~MFunc() {}
};
// For optimization that requires gradient
class MFuncGrad
{
public:
virtual double f_grad(Constvec& x, Refvec grad) = 0;
virtual ~MFuncGrad() {}
};
} // namespace Numer
#endif // FUNC_H