source: trunk/yat/regression/GSLInterpolation.cc @ 1655

Last change on this file since 1655 was 1655, checked in by Jari Häkkinen, 12 years ago

Addresses #466. Removed bsearch from the GSL wrapper.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1// $Id: GSLInterpolation.cc 1655 2008-12-16 23:29:55Z jari $
2
3/*
4  Copyright (C) 2008 Jari Häkkinen
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "GSLInterpolation.h"
23
24#include "yat/utility/VectorBase.h"
25
26#include <cassert>
27
28namespace theplu {
29namespace yat {
30namespace regression {
31
32
33  GSLInterpolation::GSLInterpolation(const gsl_interp_type* interpolator_type,
34                                     const utility::VectorBase& x,
35                                     const utility::VectorBase& y)
36    : evaluation_(0.0), gsl_status_(0)
37  {
38    assert(x.size()==y.size());
39    size_t size=x.size();
40    x_=new double[size];
41    y_=new double[size];
42    for (size_t i=0; i<size; ++i) {
43      x_[i]=x(i);
44      y_[i]=y(i);
45    }
46    interpolator_ = gsl_interp_alloc(interpolator_type, size);
47    gsl_status_=gsl_interp_init(interpolator_, x_, y_, size);
48    accelerator_ = gsl_interp_accel_alloc();
49  }
50
51
52  GSLInterpolation::~GSLInterpolation(void)
53  {
54    gsl_interp_free(interpolator_);
55    gsl_interp_accel_free(accelerator_);
56    delete x_;
57    delete y_;
58  }
59
60
61  int GSLInterpolation::error_status(void) const
62  {
63    return gsl_status_;
64  }
65
66
67  double GSLInterpolation::evaluate(double x)
68  {
69    gsl_status_=gsl_interp_eval_e(interpolator_, x_, y_, x, accelerator_,
70                                  &evaluation_);
71    return evaluation_;
72  }
73
74
75  double GSLInterpolation::evaluate_derivative(double x)
76  {
77    gsl_status_=gsl_interp_eval_deriv_e(interpolator_, x_, y_, x, accelerator_,
78                                        &evaluation_);
79    return evaluation_;
80  }
81
82
83  double GSLInterpolation::evaluate_derivative2(double x)
84  {
85    gsl_status_=gsl_interp_eval_deriv2_e(interpolator_, x_, y_, x, accelerator_,
86                                         &evaluation_);
87    return evaluation_;
88  }
89
90
91  double GSLInterpolation::evaluate_integral(double a, double b)
92  {
93    gsl_status_=gsl_interp_eval_integ_e(interpolator_, x_, y_, a, b,
94                                        accelerator_, &evaluation_);
95    return evaluation_;
96  }
97
98
99  double GSLInterpolation::evaluation(void) const
100  {
101    return evaluation_;
102  }
103
104
105  unsigned int GSLInterpolation::min_size(void) const
106  {
107    return gsl_interp_min_size(interpolator_);
108  }
109
110
111}}} // of namespaces regression, yat, and theplu
Note: See TracBrowser for help on using the repository browser.