Loading [MathJax]/extensions/tex2jax.js
LSST Applications g04dff08e69+fafbcb10e2,g0d33ba9806+e09a96fa4e,g0fba68d861+cc01b48236,g1e78f5e6d3+fb95f9dda6,g1ec0fe41b4+f536777771,g1fd858c14a+ae46bc2a71,g35bb328faa+fcb1d3bbc8,g4af146b050+dd94f3aad7,g4d2262a081+7ee6f976aa,g53246c7159+fcb1d3bbc8,g5a012ec0e7+b20b785ecb,g60b5630c4e+e09a96fa4e,g6273192d42+bf8cfc5e62,g67b6fd64d1+4086c0989b,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+831c06c8fc,g8852436030+54b48a5987,g89139ef638+4086c0989b,g9125e01d80+fcb1d3bbc8,g94187f82dc+e09a96fa4e,g989de1cb63+4086c0989b,g9f33ca652e+64be6d9d51,g9f7030ddb1+d11454dffd,ga2b97cdc51+e09a96fa4e,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+23605820ec,gb58c049af0+f03b321e39,gb89ab40317+4086c0989b,gcf25f946ba+54b48a5987,gd6cbbdb0b4+af3c3595f5,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+15f2daff9d,ge278dab8ac+d65b3c2b70,ge410e46f29+4086c0989b,gf67bdafdda+4086c0989b,v29.0.0.rc5
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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)