LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lsst::afw::math::detail::Spline Class Reference

#include <Spline.h>

Inheritance diagram for lsst::afw::math::detail::Spline:
lsst::afw::math::detail::SmoothedSpline lsst::afw::math::detail::TautSpline

Public Member Functions

virtual ~Spline ()=default
 
 Spline (Spline const &)=default
 
 Spline (Spline &&)=default
 
Splineoperator= (Spline const &)=default
 
Splineoperator= (Spline &&)=default
 
void interpolate (std::vector< double > const &x, std::vector< double > &y) const
 Interpolate a Spline.
 
void derivative (std::vector< double > const &x, std::vector< double > &dydx) const
 Find the derivative of a Spline.
 
std::vector< double > roots (double const value, double const x0, double const x1) const
 Find the roots of Spline - val = 0 in the range [x0, x1).
 

Protected Member Functions

 Spline ()=default
 
void _allocateSpline (int const nknot)
 Allocate the storage a Spline needs.
 

Protected Attributes

std::vector< double > _knots
 
std::vector< std::vector< double > > _coeffs
 

Detailed Description

Definition at line 14 of file Spline.h.

Constructor & Destructor Documentation

◆ ~Spline()

virtual lsst::afw::math::detail::Spline::~Spline ( )
virtualdefault

◆ Spline() [1/3]

lsst::afw::math::detail::Spline::Spline ( Spline const & )
default

◆ Spline() [2/3]

lsst::afw::math::detail::Spline::Spline ( Spline && )
default

◆ Spline() [3/3]

lsst::afw::math::detail::Spline::Spline ( )
protecteddefault

Member Function Documentation

◆ _allocateSpline()

void lsst::afw::math::detail::Spline::_allocateSpline ( int const nknot)
protected

Allocate the storage a Spline needs.

Definition at line 21 of file Spline.cc.

21 {
22 _knots.resize(nknot);
23 _coeffs.resize(4);
24 for (unsigned int i = 0; i != _coeffs.size(); ++i) {
25 _coeffs[i].reserve(nknot);
26 }
27}
std::vector< double > _knots
Definition Spline.h:55
std::vector< std::vector< double > > _coeffs
Definition Spline.h:56
T reserve(T... args)
T resize(T... args)
T size(T... args)

◆ derivative()

void lsst::afw::math::detail::Spline::derivative ( std::vector< double > const & x,
std::vector< double > & dydx ) const

Find the derivative of a Spline.

Parameters
[in]xpoints to evaluate derivative at
[out]dydxderivatives at x

Definition at line 57 of file Spline.cc.

57 {
58 int const nknot = _knots.size();
59 int const n = x.size();
60
61 dydx.resize(n); // may default-construct elements which is a little inefficient
62 /*
63 * For _knots[i] <= x <= _knots[i+1], the * interpolant has the form
64 * val = _coeff[0][i] +dx*(_coeff[1][i] + dx*(_coeff[2][i]/2 + dx*_coeff[3][i]/6))
65 * with
66 * dx = x - knots[i]
67 * so the derivative is
68 * val = _coeff[1][i] + dx*(_coeff[2][i] + dx*_coeff[3][i]/2))
69 */
70
71 int ind = -1; // no idea initially
72 for (int i = 0; i != n; ++i) {
73 ind = search_array(x[i], &_knots[0], nknot, ind);
74
75 if (ind < 0) { // off bottom
76 ind = 0;
77 } else if (ind >= nknot) { // off top
78 ind = nknot - 1;
79 }
80
81 double const dx = x[i] - _knots[ind];
82 dydx[i] = _coeffs[1][ind] + dx * (_coeffs[2][ind] + dx * _coeffs[3][ind] / 2);
83 }
84}

◆ interpolate()

void lsst::afw::math::detail::Spline::interpolate ( std::vector< double > const & x,
std::vector< double > & y ) const

Interpolate a Spline.

Parameters
[in]xpoints to interpolate at
[out]yvalues of spline interpolation at x

Definition at line 29 of file Spline.cc.

29 {
30 int const nknot = _knots.size();
31 int const n = x.size();
32
33 y.resize(n); // may default-construct elements which is a little inefficient
34 /*
35 * For _knots[i] <= x <= _knots[i+1], the interpolant
36 * has the form
37 * val = _coeff[0][i] +dx*(_coeff[1][i] + dx*(_coeff[2][i]/2 + dx*_coeff[3][i]/6))
38 * with
39 * dx = x - knots[i]
40 */
41 int ind = -1; // no idea initially
42 for (int i = 0; i != n; ++i) {
43 ind = search_array(x[i], &_knots[0], nknot, ind);
44
45 if (ind < 0) { // off bottom
46 ind = 0;
47 } else if (ind >= nknot) { // off top
48 ind = nknot - 1;
49 }
50
51 double const dx = x[i] - _knots[ind];
52 y[i] = _coeffs[0][ind] +
53 dx * (_coeffs[1][ind] + dx * (_coeffs[2][ind] / 2 + dx * _coeffs[3][ind] / 6));
54 }
55}
int y
Definition SpanSet.cc:48

◆ operator=() [1/2]

Spline & lsst::afw::math::detail::Spline::operator= ( Spline && )
default

◆ operator=() [2/2]

Spline & lsst::afw::math::detail::Spline::operator= ( Spline const & )
default

◆ roots()

std::vector< double > lsst::afw::math::detail::Spline::roots ( double const value,
double const x0,
double const x1 ) const

Find the roots of Spline - val = 0 in the range [x0, x1).

Return a vector of all the roots found

Parameters
valuedesired value
x0,x1specify desired range is [x0,x1)

Definition at line 1226 of file Spline.cc.

1226 {
1227 /*
1228 * Strategy: we know that the interpolant has the form
1229 * val = coef[0][i] +dx*(coef[1][i] + dx*(coef[2][i]/2 + dx*coef[3][i]/6))
1230 * so we can use the usual analytic solution for a cubic. Note that the
1231 * cubic quoted above returns dx, the distance from the previous knot,
1232 * rather than x itself
1233 */
1234 std::vector<double> roots; /* the roots found */
1235 double x0 = a; // lower end of current range
1236 double const x1 = b;
1237 int const nknot = _knots.size();
1238
1239 int i0 = search_array(x0, &_knots[0], nknot, -1);
1240 int const i1 = search_array(x1, &_knots[0], nknot, i0);
1241 assert(i1 >= i0 && i1 <= nknot - 1);
1242
1243 std::vector<double> newRoots; // the roots we find in some interval
1244 /*
1245 * Deal with special case that x0 may be off one end or the other of
1246 * the array of knots.
1247 */
1248 if (i0 < 0) { /* off bottom */
1249 i0 = 0;
1250 do_cubic(_coeffs[3][i0] / 6, _coeffs[2][i0] / 2, _coeffs[1][i0], _coeffs[0][i0] - value, newRoots);
1251 //
1252 // Could use
1253 // std::transform(newRoots.begin(), newRoots.end(), newRoots.begin(),
1254 // std::bind(std::plus<double>(), _1, _knots[i0]));
1255 // but let's not
1256 //
1257 for (unsigned int j = 0; j != newRoots.size(); ++j) {
1258 newRoots[j] += _knots[i0];
1259 }
1260 keep_valid_roots(roots, newRoots, x0, _knots[i0]);
1261
1262 x0 = _knots[i0];
1263 } else if (i0 >= nknot) { /* off top */
1264 i0 = nknot - 1;
1265 assert(i0 >= 0);
1266 do_cubic(_coeffs[3][i0] / 6, _coeffs[2][i0] / 2, _coeffs[1][i0], _coeffs[0][i0] - value, newRoots);
1267
1268 for (unsigned int j = 0; j != newRoots.size(); ++j) {
1269 newRoots[j] += _knots[i0];
1270 }
1271 keep_valid_roots(roots, newRoots, x0, x1);
1272
1273 return roots;
1274 }
1275 /*
1276 * OK, now search in main body of spline. Note that i1 may be nknot - 1, and
1277 * in any case the right hand limit of the last segment is at x1, not a knot
1278 */
1279 for (int i = i0; i <= i1; i++) {
1280 do_cubic(_coeffs[3][i] / 6, _coeffs[2][i] / 2, _coeffs[1][i], _coeffs[0][i] - value, newRoots);
1281
1282 for (unsigned int j = 0; j != newRoots.size(); ++j) {
1283 newRoots[j] += _knots[i];
1284 }
1285 keep_valid_roots(roots, newRoots, ((i == i0) ? x0 : _knots[i]), ((i == i1) ? x1 : _knots[i + 1]));
1286 }
1287
1288 return roots;
1289}
table::Key< int > b
table::Key< int > a
std::vector< double > roots(double const value, double const x0, double const x1) const
Find the roots of Spline - val = 0 in the range [x0, x1).
Definition Spline.cc:1226

Member Data Documentation

◆ _coeffs

std::vector<std::vector<double> > lsst::afw::math::detail::Spline::_coeffs
protected

Definition at line 56 of file Spline.h.

◆ _knots

std::vector<double> lsst::afw::math::detail::Spline::_knots
protected

Definition at line 55 of file Spline.h.


The documentation for this class was generated from the following files: