45 <<
"size: X=" << x.
size() <<
", Y=" << y.
size();
51 return make_unique<FunctionAdapter>([c](
double) {
return c; });
54 return make_unique<FunctionAdapter>([c, sx](
double v) {
return c * (v == sx); });
68 if (x[i] == x[i - 1] && y[i] == y[i - 1]) {
71 if (x[i] < x[i - 1]) {
73 <<
"but found " << x[i] <<
" after " << x[i - 1];
90 if (dataset.
size() == 1) {
91 auto c = dataset.
front();
93 return make_unique<FunctionAdapter>([c](
double) {
return c.second; });
95 return make_unique<FunctionAdapter>([c](
double v) {
return c.second * (v == c.first); });
102 for (
auto& pair : dataset) {
104 if (pair.first == x.
back() && pair.second == y.
back()) {
107 if (pair.first < x.
back()) {
109 <<
"but found " << pair.first <<
" after " << x.
back();
132 if (xp.
size() == 1) {
133 return (extrapolate || xp.
front() == x) ? yp.
front() : 0.;
136 if ((x < xp.
front() || x > xp.
back()) && !extrapolate) {
145 if (i == xp.
size()) {
146 if (!extrapolate && x > xp.
back())
155 double within = ((x >= x0) & (x <= x1)) | extrapolate;
156 double coef1 = (y1 - y0) / (x1 - x0);
157 double coef0 = y0 - coef1 * x0;
158 return within * (coef0 + coef1 * x);
static Elements::Logging logger
Logger.
static Logging getLogger(const std::string &name="")
This module provides an interface for accessing two dimensional datasets (pairs of (X,...
const std::pair< double, double > & front() const
Returns a reference to the first pair of the dataset.
size_t size() const
Get the size of the vector container.
T emplace_back(T... args)
ELEMENTS_API std::unique_ptr< Function > interpolate(const std::vector< double > &x, const std::vector< double > &y, InterpolationType type, bool extrapolate=false)
ELEMENTS_API double simple_interpolation(double x, const std::vector< double > &xp, const std::vector< double > &yp, bool extrapolate=false)
std::unique_ptr< Function > splineInterpolation(const std::vector< double > &x, const std::vector< double > &y, bool extrapolate)
Performs cubic spline interpolation for the given set of data points.
InterpolationType
Enumeration of the different supported interpolation types.
std::unique_ptr< Function > linearInterpolation(const std::vector< double > &x, const std::vector< double > &y, bool extrapolate)
Performs linear interpolation for the given set of data points.