ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
bspline.hpp
Go to the documentation of this file.
1/*
2 * $Id: bspline.hpp 257 2012-08-22 16:14:53Z jdl3 $
3 * Copyright (C) 2012, 2018, 2020 John D Lamb
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef CCGSL_BSPLINE_HPP
21#define CCGSL_BSPLINE_HPP
22
23#include<gsl/gsl_bspline.h>
24#include"vector.hpp"
25#include"matrix.hpp"
26
27namespace gsl {
31 namespace bspline {
32 class workspace {
33 public:
38 ccgsl_pointer = 0;
39 count = 0; // initially nullptr will do
40 }
41 // Refines random access container
42 // Refines assignable
49 explicit workspace( size_t const k, size_t const nbreak ){
50 ccgsl_pointer = gsl_bspline_alloc( k, nbreak );
51 // just plausibly we could allocate bspline but not count
52 try { count = new size_t; } catch( std::bad_alloc& e ){
53 // try to tidy up before rethrowing
54 gsl_bspline_free( ccgsl_pointer );
55 throw e;
56 }
57 *count = 1; // initially there is just one reference to ccgsl_pointer
58 }
65 explicit workspace( gsl_bspline_workspace* v ){
66 ccgsl_pointer = v;
67 // just plausibly we could fail to allocate count: no further action needed.
68 count = new size_t;
69 *count = 1; // initially there is just one reference to ccgsl_pointer
70 }
71 // copy constructor
77 count = v.count; if( count != 0 ) ++*count; }
78 // assignment operator
84 // first, possibly delete anything pointed to by this
85 if( count == 0 or --*count == 0 ){
86 if( ccgsl_pointer != 0 ) gsl_bspline_free( ccgsl_pointer );
87 delete count;
88 } // Then copy
89 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
90 }
91 // destructor
96 if( count == 0 or --*count == 0 ){
97 // could have allocated null pointer
98 if( ccgsl_pointer != 0 ) gsl_bspline_free( ccgsl_pointer );
99 delete count;
100 }
101 }
102#ifdef __GXX_EXPERIMENTAL_CXX0X__
108 std::swap( count, v.count );
109 v.ccgsl_pointer = nullptr;
110 }
117 workspace( std::move( v ) ).swap( *this );
118 return *this;
119 }
120#endif
121 // Refines equality comparable
122 // == operator
129 bool operator==( workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
130 // != operator
137 bool operator!=( workspace const& v ) const { return not operator==( v ); }
138 // Refines forward container
139 // Refines less than comparable
140 // operator<
149 bool operator<( workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
150 // operator>
159 bool operator>( workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
160 // operator<=
169 bool operator<=( workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
170 // operator>=
179 bool operator>=( workspace const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
184 bool empty() const { return ccgsl_pointer == 0; }
185 // swap() --- should work even if sizes don't match
191 void swap( workspace& v ){
192 std::swap( ccgsl_pointer, v.ccgsl_pointer );
193 std::swap( count, v.count );
194 }
195 private:
199 gsl_bspline_workspace* ccgsl_pointer;
203 size_t* count;
204 public:
205 // shared reference functions
210 gsl_bspline_workspace* get() const { return ccgsl_pointer; }
216 bool unique() const { return count != 0 and *count == 1; }
221 size_t use_count() const { return count == 0 ? 0 : *count; }
227#ifdef __GXX_EXPERIMENTAL_CXX0X__
228 explicit
229#endif
230 operator bool() const { return ccgsl_pointer != 0; }
237 gsl::vector return_value;
239 return return_value;
240 }
241 };
242
248 inline size_t ncoeffs( workspace& w ){ return gsl_bspline_ncoeffs( w.get() ); }
249
255 inline size_t order( workspace& w ){ return gsl_bspline_order( w.get() ); }
256
262 inline size_t nbreak( workspace& w ){ return gsl_bspline_nbreak( w.get() ); }
263
270 inline double breakpoint( size_t i, workspace& w ){
271 return gsl_bspline_breakpoint( i, w.get() ); }
272
279 inline double greville_abscissa( size_t i, workspace& w ){
280 return gsl_bspline_greville_abscissa( i, w.get() ); }
281
288 inline int knots( vector const& breakpts, workspace& w ){
289 return gsl_bspline_knots( breakpts.get(), w.get() ); }
290
298 inline int knots_uniform( double const a, double const b, workspace& w ){
299 return gsl_bspline_knots_uniform( a, b, w.get() ); }
300
309 inline int eval( double const x, vector& B, workspace& w ){
310 return gsl_bspline_eval( x, B.get(), w.get() ); }
311
312#ifndef DOXYGEN_SKIP
322 inline int eval_nonzero( double const x, vector& Bk, size_t* istart,
323 size_t* iend, workspace& w ){
324 return gsl_bspline_eval_nonzero( x, Bk.get(), istart, iend, w.get() ); }
325#endif /* DOXYGEN_SKIP */
335 inline int eval_nonzero( double const x, vector& Bk, size_t& istart,
336 size_t& iend, workspace& w ){
337 return gsl_bspline_eval_nonzero( x, Bk.get(), &istart, &iend, w.get() ); }
338
347 inline int deriv_eval( double const x, size_t const nderiv, matrix& dB,
348 workspace& w ){
349 return gsl_bspline_deriv_eval( x, nderiv, dB.get(), w.get() ); }
350
351#ifndef DOXYGEN_SKIP
362 inline int deriv_eval_nonzero( double const x, size_t const nderiv, matrix& dB,
363 size_t* istart, size_t* iend, workspace& w ){
364 return gsl_bspline_deriv_eval_nonzero( x, nderiv, dB.get(), istart, iend, w.get() ); }
365#endif /* DOXYGEN_SKIP */
376 inline int deriv_eval_nonzero( double const x, size_t const nderiv, matrix& dB,
377 size_t& istart, size_t& iend, workspace& w ){
378 return gsl_bspline_deriv_eval_nonzero( x, nderiv, dB.get(), &istart, &iend, w.get() ); }
379
380 }
381}
382#endif
bool operator==(workspace const &v) const
Two workspace are identically equal if their elements are identical.
Definition: bspline.hpp:129
workspace(workspace &&v)
Move constructor.
Definition: bspline.hpp:107
bool operator>(workspace const &v) const
A container needs to define an ordering for sorting.
Definition: bspline.hpp:159
workspace()
The default constructor is only really useful for assigning to.
Definition: bspline.hpp:37
bool empty() const
Find if the workspace is empty.
Definition: bspline.hpp:184
gsl::vector knots()
Get the knots vector.
Definition: bspline.hpp:236
bool operator!=(workspace const &v) const
Two workspace are different if their elements are not identical.
Definition: bspline.hpp:137
size_t use_count() const
Find how many workspace objects share this pointer.
Definition: bspline.hpp:221
bool unique() const
Find if this is the only object sharing the gsl_bspline.
Definition: bspline.hpp:216
workspace & operator=(workspace const &v)
The assignment operator.
Definition: bspline.hpp:83
workspace(size_t const k, size_t const nbreak)
The default constructor creates a new workspace of order k for data with nbreak breakpoints.
Definition: bspline.hpp:49
~workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: bspline.hpp:95
bool operator<=(workspace const &v) const
A container needs to define an ordering for sorting.
Definition: bspline.hpp:169
workspace(gsl_bspline_workspace *v)
Could construct from a gsl_bspline_workspace.
Definition: bspline.hpp:65
void swap(workspace &v)
Swap two workspace objects.
Definition: bspline.hpp:191
bool operator>=(workspace const &v) const
A container needs to define an ordering for sorting.
Definition: bspline.hpp:179
gsl_bspline_workspace * ccgsl_pointer
The shared pointer.
Definition: bspline.hpp:199
workspace(workspace const &v)
The copy constructor.
Definition: bspline.hpp:76
size_t * count
The shared reference count.
Definition: bspline.hpp:203
bool operator<(workspace const &v) const
A container needs to define an ordering for sorting.
Definition: bspline.hpp:149
workspace & operator=(workspace &&v)
Move operator.
Definition: bspline.hpp:116
gsl_bspline_workspace * get() const
Get the gsl_bspline_workspace.
Definition: bspline.hpp:210
This class handles matrix objects as shared handles.
Definition: matrix.hpp:72
gsl_matrix * get()
Get the gsl_matrix.
Definition: matrix.hpp:1207
This class handles vector objects as shared handles.
Definition: vector.hpp:74
gsl_vector * get()
Get the gsl_vector.
Definition: vector.hpp:1320
void wrap_gsl_vector_without_ownership(gsl_vector *v)
This function is intended mainly for internal use.
Definition: vector.hpp:272
size_t ncoeffs(workspace &w)
C++ version of gsl_bspline_ncoeffs().
Definition: bspline.hpp:248
int knots_uniform(double const a, double const b, workspace &w)
C++ version of gsl_bspline_knots_uniform().
Definition: bspline.hpp:298
int eval(double const x, vector &B, workspace &w)
C++ version of gsl_bspline_eval().
Definition: bspline.hpp:309
size_t order(workspace &w)
C++ version of gsl_bspline_order().
Definition: bspline.hpp:255
double breakpoint(size_t i, workspace &w)
C++ version of gsl_bspline_breakpoint().
Definition: bspline.hpp:270
int knots(vector const &breakpts, workspace &w)
C++ version of gsl_bspline_knots().
Definition: bspline.hpp:288
int deriv_eval_nonzero(double const x, size_t const nderiv, matrix &dB, size_t &istart, size_t &iend, workspace &w)
C++ version of gsl_bspline_deriv_eval_nonzero().
Definition: bspline.hpp:376
int deriv_eval(double const x, size_t const nderiv, matrix &dB, workspace &w)
C++ version of gsl_bspline_deriv_eval().
Definition: bspline.hpp:347
size_t nbreak(workspace &w)
C++ version of gsl_bspline_nbreak().
Definition: bspline.hpp:262
int eval_nonzero(double const x, vector &Bk, size_t &istart, size_t &iend, workspace &w)
C++ version of gsl_bspline_eval_nonzero().
Definition: bspline.hpp:335
double greville_abscissa(size_t i, workspace &w)
C++ version of gsl_bspline_greville_abscissa().
Definition: bspline.hpp:279
double b(int order, double qq)
C++ version of gsl_sf_mathieu_b().
Definition: sf_mathieu.hpp:298
double a(int order, double qq)
C++ version of gsl_sf_mathieu_a().
Definition: sf_mathieu.hpp:272
The gsl package creates an interface to the GNU Scientific Library for C++.
Definition: blas.hpp:34