Changeset 1650
 Timestamp:
 Dec 14, 2008, 11:13:48 PM (13 years ago)
 Location:
 trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/interpolation_test.cc
r1648 r1650 75 75 w(10)=25; z(10)=119.43138; 76 76 77 for (size_t i=0; i<w.size(); ++i) 77 for (size_t i=0; i<w.size(); ++i) { 78 78 if (!suite.equal(cspline.evaluate(w(i)),z(i),1e9)) { 79 79 suite.err() << "cspline test failed for i=" << i << std::endl; 80 80 suite.add(false); 81 81 } 82 // Check for errors 83 if (cspline.error_status()) { 84 suite.err() << "cspline test failed with GSL_EDOM error" << std::endl; 85 suite.add(false); 86 } 87 } 88 89 // An error should be generated, if not test fails 90 cspline.evaluate(w(0)5); 91 if (!cspline.error_status()) { 92 suite.err() << "cspline test failed no GSL_EDOM error occured" << std::endl; 93 suite.add(false); 94 } 82 95 83 96 // lazy testing, at least try to create the objects 
trunk/yat/regression/GSLInterpolation.cc
r1648 r1650 34 34 const utility::VectorBase& x, 35 35 const utility::VectorBase& y) 36 : evaluation_(0.0), gsl_status_(0) 36 37 { 37 38 assert(x.size()==y.size()); … … 44 45 } 45 46 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); 47 48 accelerator_ = gsl_interp_accel_alloc(); 48 49 } … … 65 66 66 67 68 int GSLInterpolation::error_status(void) const 69 { 70 return gsl_status_; 71 } 72 73 67 74 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_; 70 79 } 71 80 … … 73 82 double GSLInterpolation::evaluate_derivative(double x) 74 83 { 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_; 76 87 } 77 88 … … 79 90 double GSLInterpolation::evaluate_derivative2(double x) 80 91 { 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_; 82 95 } 83 96 … … 85 98 double GSLInterpolation::evaluate_integral(double a, double b) 86 99 { 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_; 88 109 } 89 110 
trunk/yat/regression/GSLInterpolation.h
r1648 r1650 35 35 \brief Base class for interfacing GSL interpolation. 36 36 37 The GSL interpolation is desc ibed in37 The GSL interpolation is described in 38 38 http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html. The 39 39 GSL library provides a variety of interpolation methods, … … 44 44 45 45 Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$ 46 the sub classes compute a continuous interpolating function \f$46 the sub classes compute a continuous interpolating function \f$ 47 47 y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is 48 48 piecewise smooth, and its behavior at the endpoints is 49 49 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. 50 55 */ 51 56 class GSLInterpolation … … 65 70 66 71 /** 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 /** 67 84 \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. 68 89 69 90 \return The interpolated value of \f$ y \f$ for a given point 70 91 \a x. 92 93 \see error_status(void) 71 94 */ 72 95 double evaluate(double x); … … 76 99 \a x. 77 100 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 78 105 \return The derivative. 106 107 \see error_status(void) 79 108 */ 80 109 double evaluate_derivative(double x); … … 84 113 function at \a x. 85 114 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 86 119 \return The 2nd derivative. 120 121 \see error_status(void) 87 122 */ 88 123 double evaluate_derivative2(double x); … … 92 127 function over the range \f$ [a,b] \f$. 93 128 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 94 133 \return The integral. 134 135 \see error_status(void) 95 136 */ 96 137 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; 97 146 98 147 /** … … 111 160 \brief The default constructor 112 161 113 Initializ ion of the interpolation object for the data \f$ (x,162 Initialization of the interpolation object for the data \f$ (x, 114 163 y) \f$ where \a x and \a y are vector like objects of the same 115 164 size. The content of \a x and \a y are copied for internal … … 117 166 increasing \a x values; the behavior for other arrangements is 118 167 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) 119 174 */ 120 175 GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x, … … 133 188 134 189 gsl_interp_accel* accelerator_; 190 double evaluation_; 135 191 gsl_interp* interpolator_; 192 int gsl_status_; 136 193 double* x_; 137 194 double* y_;
Note: See TracChangeset
for help on using the changeset viewer.