25#include "ElementsKernel/Exception.h"
42 if (i < 0 || i >=
static_cast<ssize_t
>(
m_knots.size())) {
55 auto n_less = first_x - xs.
begin();
58 auto o = out.
begin() + n_less;
62 auto x = xs.
begin() + n_less;
63 while (x < xs.
end() && *x ==
m_knots.front()) {
73 while (o != out.
end() && current_knot <
m_knots.end()) {
75 auto i = current_knot -
m_knots.begin();
88 double integrate(
const double a,
const double b)
const override {
102 if (knotIter !=
m_knots.begin()) {
105 auto i = knotIter -
m_knots.begin();
106 while (++knotIter !=
m_knots.end()) {
107 auto prevKnotIter = knotIter - 1;
108 if (max <= *prevKnotIter) {
111 if (min < *knotIter) {
112 double down = (min > *prevKnotIter) ? min : *prevKnotIter;
113 double up = (max < *knotIter) ? max : *knotIter;
118 return direction * result;
133 for (
size_t i = 0; i < x.
size() - 1; i++) {
134 double dx = (x[i + 1] - x[i]);
136 coef1[i] = (y[i + 1] - y[i]) / dx;
137 coef0[i] = y[i] - coef1[i] * x[i];
LinearInterpolator(std::vector< double > knots, std::vector< double > coef0, std::vector< double > coef1)
const std::vector< double > m_coef0
std::unique_ptr< NAryFunction > clone() const override
void operator()(const std::vector< double > &xs, std::vector< double > &out) const override
double integrate(const double a, const double b) const override
double antiderivative(int i, double x) const
const std::vector< double > m_coef1
virtual ~LinearInterpolator()=default
double operator()(double x) const override
ssize_t findKnot(double x) const
PiecewiseBase(std::vector< double > knots)
std::vector< double > m_knots
A vector where the knots are kept.
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.