LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst.afw.math::InterpolateGsl Class Reference
Inheritance diagram for lsst.afw.math::InterpolateGsl:
lsst.afw.math::Interpolate

Public Member Functions

virtual ~InterpolateGsl ()
 
virtual double interpolate (double const x) const
 
- Public Member Functions inherited from lsst.afw.math::Interpolate
virtual ~Interpolate ()
 

Private Member Functions

 InterpolateGsl (std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style)
 

Private Attributes

::gsl_interp_type const * _interpType
 
::gsl_interp_accel * _acc
 
::gsl_interp * _interp
 

Friends

boost::shared_ptr< InterpolatemakeInterpolate (std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style)
 

Additional Inherited Members

- Public Types inherited from lsst.afw.math::Interpolate
enum  Style {
  UNKNOWN = -1, CONSTANT = 0, LINEAR = 1, NATURAL_SPLINE = 2,
  CUBIC_SPLINE = 3, CUBIC_SPLINE_PERIODIC = 4, AKIMA_SPLINE = 5, AKIMA_SPLINE_PERIODIC = 6,
  NUM_STYLES
}
 
- Protected Member Functions inherited from lsst.afw.math::Interpolate
 Interpolate (std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=UNKNOWN)
 
 Interpolate (std::pair< std::vector< double >, std::vector< double > > const xy, Interpolate::Style const style=UNKNOWN)
 
- Protected Attributes inherited from lsst.afw.math::Interpolate
std::vector< double > const _x
 
std::vector< double > const _y
 
Interpolate::Style const _style
 

Detailed Description

Definition at line 176 of file Interpolate.cc.

Constructor & Destructor Documentation

lsst.afw.math::InterpolateGsl::~InterpolateGsl ( )
virtual

Definition at line 220 of file Interpolate.cc.

220  {
221  ::gsl_interp_free(_interp);
222  ::gsl_interp_accel_free(_acc);
223 }
::gsl_interp_accel * _acc
Definition: Interpolate.cc:186
lsst.afw.math::InterpolateGsl::InterpolateGsl ( std::vector< double > const &  x,
std::vector< double > const &  y,
Interpolate::Style const  style 
)
private
Parameters
xthe x-values of points
ythe values at x[]
styledesired interpolator

Definition at line 190 of file Interpolate.cc.

193  :
194  Interpolate(x, y), _interpType(styleToGslInterpType(style))
195 {
196  _acc = ::gsl_interp_accel_alloc();
197  if (!_acc) {
198  throw LSST_EXCEPT(pex::exceptions::MemoryError, "gsl_interp_accel_alloc failed");
199  }
200 
201  _interp = ::gsl_interp_alloc(_interpType, _y.size());
202  if (!_interp) {
203  throw LSST_EXCEPT(pex::exceptions::OutOfRangeError,
204  str(boost::format("Failed to initialise spline for type %s, length %d")
205  % _interpType->name % _y.size()));
206 
207  }
208  // Note, "x" and "y" are vector<double>; gsl_inter_init requires double[].
209  // The &(x[0]) here is valid because std::vector guarantees that the values are
210  // stored contiguously in memory (for types other than bool); C++0X 23.3.6.1 for
211  // those of you reading along.
212  int const status = ::gsl_interp_init(_interp, &x[0], &y[0], _y.size());
213  if (status != 0) {
214  throw LSST_EXCEPT(pex::exceptions::RuntimeError,
215  str(boost::format("gsl_interp_init failed: %s [%d]")
216  % ::gsl_strerror(status) % status));
217  }
218 }
std::vector< double > const _y
Definition: Interpolate.h:68
::gsl_interp_accel * _acc
Definition: Interpolate.cc:186
::gsl_interp_type const * _interpType
Definition: Interpolate.cc:185
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int status
Interpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=UNKNOWN)
Definition: Interpolate.h:60

Member Function Documentation

double lsst.afw.math::InterpolateGsl::interpolate ( double const  x) const
virtual

Implements lsst.afw.math::Interpolate.

Definition at line 225 of file Interpolate.cc.

226 {
227  // New GSL versions refuse to extrapolate.
228  // gsl_interp_init() requires x to be ordered, so can just check
229  // the array endpoints for out-of-bounds.
230  if ((xInterp < _x.front() || (xInterp > _x.back()))) {
231  // do our own quadratic extrapolation.
232  // (GSL only provides first and second derivative functions)
233  /* could also just fail via:
234  throw LSST_EXCEPT(
235  pex::exceptions::InvalidParameterError,
236  (boost::format("Interpolation point %f outside range [%f, %f]")
237  % x % _x.front() % _x.back()).str()
238  );
239  */
240  double x0, y0;
241  if (xInterp < _x.front()) {
242  x0 = _x.front();
243  y0 = _y.front();
244  } else {
245  x0 = _x.back();
246  y0 = _y.back();
247  }
248  // first derivative at endpoint
249  double d = ::gsl_interp_eval_deriv(_interp, &_x[0], &_y[0], x0, _acc);
250  // second derivative at endpoint
251  double d2 = ::gsl_interp_eval_deriv2(_interp, &_x[0], &_y[0], x0, _acc);
252  return y0 + (xInterp - x0)*d + 0.5*(xInterp - x0)*(xInterp - x0)*d2;
253  }
254  assert(xInterp >= _x.front());
255  assert(xInterp <= _x.back());
256  return ::gsl_interp_eval(_interp, &_x[0], &_y[0], xInterp, _acc);
257 }
std::vector< double > const _y
Definition: Interpolate.h:68
::gsl_interp_accel * _acc
Definition: Interpolate.cc:186
int const x0
Definition: saturated.cc:45
int d
Definition: KDTree.cc:89
std::vector< double > const _x
Definition: Interpolate.h:67
int const y0
Definition: saturated.cc:45

Friends And Related Function Documentation

boost::shared_ptr< Interpolate > makeInterpolate ( std::vector< double > const &  x,
std::vector< double > const &  y,
Interpolate::Style const  style 
)
friend

A factory function to make Interpolate objects

Member Data Documentation

::gsl_interp_accel* lsst.afw.math::InterpolateGsl::_acc
private

Definition at line 186 of file Interpolate.cc.

::gsl_interp* lsst.afw.math::InterpolateGsl::_interp
private

Definition at line 187 of file Interpolate.cc.

::gsl_interp_type const* lsst.afw.math::InterpolateGsl::_interpType
private

Definition at line 185 of file Interpolate.cc.


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