Changeset 1650 for trunk/yat/regression


Ignore:
Timestamp:
Dec 14, 2008, 11:13:48 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Addresses #466. Added checks for GSL errors, improved docs, added some more tests.

Location:
trunk/yat/regression
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/regression/GSLInterpolation.cc

    r1648 r1650  
    3434                                     const utility::VectorBase& x,
    3535                                     const utility::VectorBase& y)
     36    : evaluation_(0.0), gsl_status_(0)
    3637  {
    3738    assert(x.size()==y.size());
     
    4445    }
    4546    interpolator_ = gsl_interp_alloc(interpolator_type, size);
    46     gsl_interp_init(interpolator_, x_, y_, size);
     47    gsl_status_=gsl_interp_init(interpolator_, x_, y_, size);
    4748    accelerator_ = gsl_interp_accel_alloc();
    4849  }
     
    6566
    6667
     68  int GSLInterpolation::error_status(void) const
     69  {
     70    return gsl_status_;
     71  }
     72
     73
    6774  double GSLInterpolation::evaluate(double x)
    68   {
    69     return gsl_interp_eval(interpolator_, x_, y_, x, accelerator_);
     75  {
     76    gsl_status_=gsl_interp_eval_e(interpolator_, x_, y_, x, accelerator_,
     77                                  &evaluation_);
     78    return evaluation_;
    7079  }
    7180
     
    7382  double GSLInterpolation::evaluate_derivative(double x)
    7483  {
    75     return gsl_interp_eval_deriv(interpolator_, x_, y_, x, accelerator_);
     84    gsl_status_=gsl_interp_eval_deriv_e(interpolator_, x_, y_, x, accelerator_,
     85                                        &evaluation_);
     86    return evaluation_;
    7687  }
    7788
     
    7990  double GSLInterpolation::evaluate_derivative2(double x)
    8091  {
    81     return gsl_interp_eval_deriv2(interpolator_, x_, y_, x, accelerator_);
     92    gsl_status_=gsl_interp_eval_deriv2_e(interpolator_, x_, y_, x, accelerator_,
     93                                         &evaluation_);
     94    return evaluation_;
    8295  }
    8396
     
    8598  double GSLInterpolation::evaluate_integral(double a, double b)
    8699  {
    87     return gsl_interp_eval_integ(interpolator_, x_, y_, a, b, accelerator_);
     100    gsl_status_=gsl_interp_eval_integ_e(interpolator_, x_, y_, a, b,
     101                                        accelerator_, &evaluation_);
     102    return evaluation_;
     103  }
     104
     105
     106  double GSLInterpolation::evaluation(void) const
     107  {
     108    return evaluation_;
    88109  }
    89110
  • trunk/yat/regression/GSLInterpolation.h

    r1648 r1650  
    3535     \brief Base class for interfacing GSL interpolation.
    3636
    37      The GSL interpolation is descibed in
     37     The GSL interpolation is described in
    3838     http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html. The
    3939     GSL library provides a variety of interpolation methods,
     
    4444
    4545     Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$
    46      the sub classescompute a continuous interpolating function \f$
     46     the sub classes compute a continuous interpolating function \f$
    4747     y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is
    4848     piecewise smooth, and its behavior at the end-points is
    4949     determined by the type of interpolation used.
     50
     51     Some underlying GSL functions return GSL error codes. The error
     52     code is stored internally and should be checked for by the caller
     53     using GSLInterpolation::error_status(void). Refer to the
     54     gsl_errno.h for the error code listing.
    5055  */
    5156  class GSLInterpolation
     
    6570
    6671    /**
     72       \brief Check the error status
     73
     74       Some underlying GSL functions return GSL error codes. The error
     75       code is stored internally and should be checked for by the
     76       caller. Refer to the gsl_errno.h for the error code listing.
     77
     78       \return The current error status. A zero return values
     79       indicates no errors where encountered.
     80    */
     81    int error_status(void) const;
     82
     83    /**
    6784       \brief Calculate the interpolated value for \a x.
     85
     86       GSL error status is set if evaluation is requested outside the
     87       range defined by the interpolation algorithm. Use function
     88       error_status to check for errors.
    6889
    6990       \return The interpolated value of \f$ y \f$ for a given point
    7091       \a x.
     92
     93       \see error_status(void)
    7194    */
    7295    double evaluate(double x);
     
    7699       \a x.
    77100
     101       GSL error status is set if evaluation is requested outside the
     102       range defined by the interpolation algorithm. Use function
     103       error_status to check for errors.
     104
    78105       \return The derivative.
     106
     107       \see error_status(void)
    79108    */
    80109    double evaluate_derivative(double x);
     
    84113       function at \a x.
    85114
     115       GSL error status is set if evaluation is requested outside the
     116       range defined by the interpolation algorithm. Use function
     117       error_status to check for errors.
     118
    86119       \return The 2nd derivative.
     120
     121       \see error_status(void)
    87122    */
    88123    double evaluate_derivative2(double x);
     
    92127       function over the range \f$ [a,b] \f$.
    93128
     129       GSL error status is set if evaluation is requested outside the
     130       range defined by the interpolation algorithm. Use function
     131       error_status to check for errors.
     132
    94133       \return The integral.
     134
     135       \see error_status(void)
    95136    */
    96137    double evaluate_integral(double a, double b);
     138
     139    /**
     140       \brief The result of the latest evaluaion function call is
     141       stored and can be retrieved with this function.
     142
     143       \return The latest evaluated value.
     144     */
     145    double evaluation(void) const;
    97146
    98147    /**
     
    111160       \brief The default constructor
    112161
    113        Initializion of the interpolation object for the data \f$ (x,
     162       Initialization of the interpolation object for the data \f$ (x,
    114163       y) \f$ where \a x and \a y are vector like objects of the same
    115164       size. The content of \a x and \a y are copied for internal
     
    117166       increasing \a x values; the behavior for other arrangements is
    118167       not defined.
     168
     169       Some underlying GSL functions return GSL error codes. The error
     170       code is stored internally and should be checked for by the
     171       caller. Refer to the gsl_errno.h for the error code listing.
     172
     173       \see error_status(void)
    119174    */
    120175    GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x,
     
    133188
    134189    gsl_interp_accel* accelerator_;
     190    double evaluation_;
    135191    gsl_interp* interpolator_;
     192    int gsl_status_;
    136193    double* x_;
    137194    double* y_;
Note: See TracChangeset for help on using the changeset viewer.