LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 174 of file Interpolate.cc.

Constructor & Destructor Documentation

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

Definition at line 218 of file Interpolate.cc.

218  {
219  ::gsl_interp_free(_interp);
220  ::gsl_interp_accel_free(_acc);
221 }
::gsl_interp_accel * _acc
Definition: Interpolate.cc:184
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 188 of file Interpolate.cc.

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

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

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

Definition at line 185 of file Interpolate.cc.

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

Definition at line 183 of file Interpolate.cc.


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