Skip to content

Commit b7568e4

Browse files
committed
make evalf function constant and fix small bug
1 parent 1e5e2c7 commit b7568e4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/utils/PolyInterpolator.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class PolyInterpolator {
5050
*/
5151
double ypxmin;
5252

53-
Eigen::VectorXd x_in_poly = Eigen::VectorXd(5);
54-
Eigen::VectorXd y_in_poly = Eigen::VectorXd(5);
55-
5653
public:
5754
/**
5855
* @brief Constructor
@@ -65,6 +62,7 @@ class PolyInterpolator {
6562
n = x_in.size();
6663
xmin = x_in(0);
6764
xmax = x_in(x_in.size() - 1);
65+
Eigen::VectorXd x_in_poly(5), y_in_poly(5);
6866

6967
int j = 0;
7068
for (int i = n - 5; i < n; i++) {
@@ -86,13 +84,14 @@ class PolyInterpolator {
8684
* Useful when the logarithm of the density is interpolated.
8785
* @param x x value at which to evaluate the function
8886
*/
89-
double evalfLeftNoRightLinear(const double &xval) {
87+
double evalfLeftNoRightLinear(const double &xval) const{
9088
double y;
9189
if (xval > xmax) { // linear extrapolation
9290
y = this->y(n - 1) + ypxmax*(xval - xmax);
9391
return y;
9492
}
9593

94+
Eigen::VectorXd x_in_poly(5), y_in_poly(5);
9695
int i = adjustIndexToBoundaries(binarySearch(this->x, xval));
9796
for (int k = 0; k < 5; k++) {
9897
x_in_poly(k) = this->x(i - 2 + k);
@@ -108,13 +107,15 @@ class PolyInterpolator {
108107
* Useful when the density is interpolated.
109108
* @param x x value at which to evaluate the function
110109
*/
111-
double evalfLeftNoRightZero(const double &xval) {
110+
double evalfLeftNoRightZero(const double &xval) const{
112111
double y;
113-
if (xval > xmax) { // linear extrapolation
112+
if (xval > xmax) { // constant
114113
y = 0.0;
115114
return y;
116115
}
117116

117+
Eigen::VectorXd x_in_poly(5), y_in_poly(5);
118+
int j = adjustIndexToBoundaries(binarySearch(this->x, xval));
118119
int i = adjustIndexToBoundaries(binarySearch(this->x, xval));
119120
for (int k = 0; k < 5; k++) {
120121
x_in_poly(k) = this->x(i - 2 + k);
@@ -127,7 +128,7 @@ class PolyInterpolator {
127128
int adjustIndexToBoundaries(int i) const {
128129
int j = i;
129130
if (i == 0) j = 2;
130-
if (i == 1) i = 2;
131+
if (i == 1) j = 2;
131132
if (i == n - 1) j = n - 3;
132133
if (i == n - 2) j = n - 3;
133134
return j;

0 commit comments

Comments
 (0)