Repository navigation
Conversation
Owner
|
Thank you for the pull request. There was another request to allow extrapolation for out of bounds values. I've pushed a branch that allows configuring the out-of-bounds value when extrapolation is disabled and does a "reasonable" extrapolation when enabled. The interface looks like this TEST_CASE("Extrapolation settings") {
_1D::CubicSplineInterpolator<double> interp;
int N = 100;
double xmin = 0, xmax = 2 * M_PI;
double dx = (xmax - xmin) / (N - 1);
_1D::CubicSplineInterpolator<double>::VectorType xx(N), yy(N);
CHECK_THROWS_AS(interp(1), std::logic_error);
for (int i = 0; i < N; i++) {
xx(i) = dx * i;
yy(i) = sin(xx(i));
}
interp.setData(xx, yy);
CHECK(interp(-1) == 0);
CHECK(interp(8) == 0);
CHECK(!std::isnan(interp(-1)));
CHECK(!std::isnan(interp(-4)));
interp.setOutOfBoundsValue(1);
CHECK(interp(-1) == 1);
CHECK(interp(8) == 1);
CHECK(!std::isnan(interp(-1)));
CHECK(!std::isnan(interp(-4)));
interp.setOutOfBoundsNaN();
CHECK(interp(-1) != std::numeric_limits<double>::quiet_NaN());
CHECK(interp(8) != std::numeric_limits<double>::quiet_NaN());
CHECK(std::isnan(interp(-1)));
CHECK(std::isnan(interp(-4)));
interp.enableExtrapolation();
CHECK(interp(-1) == Approx(-1));
CHECK(interp(8) == Approx(8 - 2 * M_PI));
}
Does this do what you are looking for? |
Owner
|
#35 would be resolved with feat-extrapolation-configuration branch too. |
Author
|
Yes, that would be an even better interface than my quick proposal, thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I'm using your interpolators in my code. Unfortunately when x is out of bounds they return
0, which is not easy to discriminate if a valid interpolations may also return0.I'm therefore proposing this change so the caller may chose a different invalid value to return (typically
std::numeric_limits<float>::quiet_NaN()), whilst guaranteeing backward-compatilibity.