LSST Applications g0fba68d861+5616995c1c,g1ebb85f214+2420ccdea7,g1fd858c14a+44c57a1f81,g21d47ad084+8e51fce9ac,g262e1987ae+1a7d68eb3b,g2cef7863aa+3bd8df3d95,g35bb328faa+fcb1d3bbc8,g36ff55ed5b+2420ccdea7,g47891489e3+5c6313fe9a,g53246c7159+fcb1d3bbc8,g646c943bdb+dbb9921566,g67b6fd64d1+5c6313fe9a,g6bd32b75b5+2420ccdea7,g74acd417e5+37fc0c974d,g786e29fd12+cf7ec2a62a,g86c591e316+6e13bcb9e9,g87389fa792+1e0a283bba,g89139ef638+5c6313fe9a,g90f42f885a+fce05a46d3,g9125e01d80+fcb1d3bbc8,g93e38de9ac+5345a64125,g95a1e89356+47d08a1cc6,g97be763408+bba861c665,ga9e4eb89a6+85210110a1,gb0b61e0e8e+1f27f70249,gb58c049af0+f03b321e39,gb89ab40317+5c6313fe9a,gc4e39d7843+4e09c98c3d,gd16ba4ae74+5402bcf54a,gd8ff7fe66e+2420ccdea7,gd9a9a58781+fcb1d3bbc8,gdab6d2f7ff+37fc0c974d,gde280f09ee+604b327636,ge278dab8ac+50e2446c94,ge410e46f29+5c6313fe9a,gef3c2e6661+6b480e0fb7,gf67bdafdda+5c6313fe9a,gffca2db377+fcb1d3bbc8,v29.2.0.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
gslinterpolator.cc
Go to the documentation of this file.
1#ifdef LSST_GAUSS2D_FIT_HAS_GSL
2
3#include <stdexcept>
4#include <vector>
5
7
9
10namespace lsst::gauss2d::fit {
11
12void _check_idx(size_t idx, size_t size) {
13 if (!(idx < size)) {
14 throw std::out_of_range("idx=" + std::to_string(idx) + " !< size=" + std::to_string(size));
15 }
16}
17
18GSLInterpolator::GSLInterpolator(std::vector<double> x, std::vector<double> y, const InterpType interp_type)
19 : _interp_type(interp_type), _n_knots(x.size()), _x(x), _y(y) {
20 if (!(_n_knots > 0)) {
21 throw std::invalid_argument("x.size()=" + std::to_string(_n_knots) + " !> 0");
22 }
23 if (_y.size() != _n_knots) {
24 throw std::invalid_argument("y.size()=" + std::to_string(y.size())
25 + " != x.size()=" + std::to_string(_n_knots));
26 }
27 _acc = gsl_interp_accel_alloc();
28 _spline = gsl_spline_alloc(GSLInterpTypes.at(interp_type), _n_knots);
29 gsl_spline_init(_spline, &x[0], &y[0], _n_knots);
30}
31
32GSLInterpolator::~GSLInterpolator() {
33 gsl_spline_free(_spline);
34 gsl_interp_accel_free(_acc);
35}
36
37const InterpType GSLInterpolator::get_interp_type() const { return _interp_type; }
38
39double GSLInterpolator::get_knot_x(size_t idx) const {
40 _check_idx(idx, this->_n_knots);
41 return _x[idx];
42}
43double GSLInterpolator::get_knot_y(size_t idx) const {
44 _check_idx(idx, this->_n_knots);
45 return _y[idx];
46}
47
48double GSLInterpolator::eval(double x) const { return gsl_spline_eval(_spline, x, _acc); }
49
50double GSLInterpolator::eval_deriv(double x) const { return gsl_spline_eval_deriv(_spline, x, _acc); }
51
52size_t GSLInterpolator::size() const { return _n_knots; }
53
54std::string GSLInterpolator::repr(bool name_keywords, std::string_view namespace_separator) const {
55 return std::string("GSLInterpolator(") + (name_keywords ? "n_knots=" : "") + std::to_string(_n_knots)
56 + ")";
57}
58
59std::string GSLInterpolator::str() const {
60 return "GSLInterpolator(n_knots=" + std::to_string(_n_knots) + ")";
61}
62} // namespace lsst::gauss2d::fit
63
64#endif // #ifdef LSST_GAUSS2D_FIT_HAS_GSL
T to_string(T... args)