1 | // $Id: GSLInterpolation.cc 1643 2008-12-13 00:23:39Z 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/VectorConstView.h" |
---|
25 | |
---|
26 | #include <cassert> |
---|
27 | |
---|
28 | namespace theplu { |
---|
29 | namespace yat { |
---|
30 | namespace regression { |
---|
31 | |
---|
32 | |
---|
33 | GSLInterpolation::GSLInterpolation(const gsl_interp_type* interpolator_type, |
---|
34 | const utility::VectorConstView& x, |
---|
35 | const utility::VectorConstView& y) |
---|
36 | { |
---|
37 | assert(x.size()==y.size()); |
---|
38 | size_t size=x.size(); |
---|
39 | x_=new double[size]; |
---|
40 | y_=new double[size]; |
---|
41 | for (size_t i=0; i<size; ++i) { |
---|
42 | x_[i]=x(i); |
---|
43 | y_[i]=y(i); |
---|
44 | } |
---|
45 | interpolator_=gsl_interp_alloc (interpolator_type, size); |
---|
46 | gsl_interp_init(interpolator_, x_, y_, size); |
---|
47 | accelerator_ = gsl_interp_accel_alloc(); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | GSLInterpolation::~GSLInterpolation(void) |
---|
52 | { |
---|
53 | gsl_interp_free(interpolator_); |
---|
54 | gsl_interp_accel_free(accelerator_); |
---|
55 | delete x_; |
---|
56 | delete y_; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | double GSLInterpolation::evaluate(const double x) const |
---|
61 | { |
---|
62 | return gsl_interp_eval(interpolator_,x_,y_,x,accelerator_); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | }}} // of namespaces regression, yat, and theplu |
---|