ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
chebyshev.hpp
Go to the documentation of this file.
1/*
2 * $Id: chebyshev.hpp 293 2012-12-17 20:27:36Z jdl3 $
3 * Copyright (C) 2012, 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_CHEB_HPP
21#define CCGSL_CHEB_HPP
22
23#include<new>
24#include<gsl/gsl_chebyshev.h>
25#include"mode.hpp"
26#include"function_scl.hpp"
27
28namespace gsl {
32 namespace cheb {
36 class series {
37 public:
42 ccgsl_pointer = 0;
43 count = 0; // initially nullptr will do
44 }
45 // Refines random access container
46 // Refines assignable
51 explicit series( size_t const order ){
52 ccgsl_pointer = gsl_cheb_alloc( order );
53 // just plausibly we could allocate series but not count
54 try { count = new size_t; } catch( std::bad_alloc& e ){
55 // try to tidy up before rethrowing
56 gsl_cheb_free( ccgsl_pointer );
57 throw e;
58 }
59 *count = 1; // initially there is just one reference to ccgsl_pointer
60 }
67 explicit series( gsl_cheb_series* v ){
68 ccgsl_pointer = v;
69 // just plausibly we could fail to allocate count: no further action needed.
70 count = new size_t;
71 *count = 1; // initially there is just one reference to ccgsl_pointer
72 }
73 // copy constructor
79 count = v.count; if( count != 0 ) ++*count; }
80 // assignment operator
85 series& operator=( series const& v ){
86 // first, possibly delete anything pointed to by this
87 if( count == 0 or --*count == 0 ){
88 if( ccgsl_pointer != 0 ) gsl_cheb_free( ccgsl_pointer );
89 delete count;
90 } // Then copy
91 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
92 }
93 // destructor
98 if( count == 0 or --*count == 0 ){
99 // could have allocated null pointer
100 if( ccgsl_pointer != 0 ) gsl_cheb_free( ccgsl_pointer );
101 delete count;
102 }
103 }
104#ifdef __GXX_EXPERIMENTAL_CXX0X__
109 series( series&& v ) : ccgsl_pointer( v.ccgsl_pointer ), count( nullptr ){
110 std::swap( count, v.count );
111 v.ccgsl_pointer = nullptr;
112 }
119 series( std::move( v ) ).swap( *this );
120 return *this;
121 }
122#endif
123 // Refines equality comparable
124 // == operator
131 bool operator==( series const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
132 // != operator
139 bool operator!=( series const& v ) const { return not operator==( v ); }
140 // Refines forward container
141 // Refines less than comparable
142 // operator<
151 bool operator<( series const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
152 // operator>
161 bool operator>( series const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
162 // operator<=
171 bool operator<=( series const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
172 // operator>=
181 bool operator>=( series const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
186 bool empty() const { return ccgsl_pointer == 0; }
187 // swap() --- should work even if sizes don't match
193 void swap( series& v ){
194 std::swap( ccgsl_pointer, v.ccgsl_pointer );
195 std::swap( count, v.count );
196 }
197 private:
201 gsl_cheb_series* ccgsl_pointer;
205 size_t* count;
206 public:
207 // shared reference functions
212 gsl_cheb_series* get() const { return ccgsl_pointer; }
218 bool unique() const { return count != 0 and *count == 1; }
223 size_t use_count() const { return count == 0 ? 0 : *count; }
229#ifdef __GXX_EXPERIMENTAL_CXX0X__
230 explicit
231#endif
232 operator bool() const { return ccgsl_pointer != 0; }
233 public:
241 int init( function_scl const& func, double const a, double const b ){
242 return gsl_cheb_init( get(), &func, a, b ); }
250 int init( gsl_function const* func, double const a, double const b ){
251 return gsl_cheb_init( get(), func, a, b ); }
252 };
253
262 inline int init( series& cs, function_scl const& func, double const a, double const b ){
263 return gsl_cheb_init( cs.get(), &func, a, b ); }
272 inline int init( series& cs, gsl_function const* func, double const a, double const b ){
273 return gsl_cheb_init( cs.get(), func, a, b ); }
274
280 inline size_t order( series const& cs ){ return gsl_cheb_order( cs.get() ); }
281
287 inline size_t size( series const& cs ){ return gsl_cheb_size( cs.get() ); }
288
294 inline double* coeffs( series const& cs ){ return gsl_cheb_coeffs( cs.get() ); }
295
302 inline double eval( series const& cs, double const x )
303 { return gsl_cheb_eval( cs.get(), x ); }
304
305#ifndef DOXYGEN_SKIP
314 inline int eval_err( series const& cs, double const x, double* result, double* abserr ){
315 return gsl_cheb_eval_err( cs.get(), x, result, abserr ); }
316#endif /* DOXYGEN_SKIP */
325 inline int eval_err( series const& cs, double const x, double& result, double& abserr ){
326 return gsl_cheb_eval_err( cs.get(), x, &result, &abserr ); }
327
335 inline double eval_n( series const& cs, size_t const order, double const x ){
336 return gsl_cheb_eval_n( cs.get(), order, x ); }
337
338#ifndef DOXYGEN_SKIP
348 inline int eval_n_err( series const& cs, size_t const order, double const x,
349 double* result, double* abserr ){
350 return gsl_cheb_eval_n_err( cs.get(), order, x, result, abserr ); }
351#endif /* DOXYGEN_SKIP */
361 inline int eval_n_err( series const& cs, size_t const order, double const x,
362 double& result, double& abserr ){
363 return gsl_cheb_eval_n_err( cs.get(), order, x, &result, &abserr ); }
364
372 inline double eval_mode( series const& cs, double const x, gsl::mode_t mode ){
373 return gsl_cheb_eval_mode( cs.get(), x, mode ); }
374
375#ifndef DOXYGEN_SKIP
385 inline int eval_mode_e( series const& cs, double const x, gsl_mode_t mode,
386 double* result, double* abserr ){
387 return gsl_cheb_eval_mode_e( cs.get(), x, mode, result, abserr ); }
388#endif /* DOXYGEN_SKIP */
398 inline int eval_mode_e( series const& cs, double const x, gsl_mode_t mode,
399 double& result, double& abserr ){
400 return gsl_cheb_eval_mode_e( cs.get(), x, mode, &result, &abserr ); }
401
408 inline int calc_deriv( series& deriv, series const& cs ){
409 return gsl_cheb_calc_deriv( deriv.get(), cs.get() ); }
410
417 inline int calc_integ( series& integ, series const& cs ){
418 return gsl_cheb_calc_integ( integ.get(), cs.get() ); }
419 }
420}
421#endif
Workspace for Chebyshev series.
Definition: chebyshev.hpp:36
void swap(series &v)
Swap two series objects.
Definition: chebyshev.hpp:193
bool operator>=(series const &v) const
A container needs to define an ordering for sorting.
Definition: chebyshev.hpp:181
series(series &&v)
Move constructor.
Definition: chebyshev.hpp:109
bool operator==(series const &v) const
Two series are identically equal if their elements are identical.
Definition: chebyshev.hpp:131
bool operator<=(series const &v) const
A container needs to define an ordering for sorting.
Definition: chebyshev.hpp:171
series(gsl_cheb_series *v)
Could construct from a gsl_cheb_series.
Definition: chebyshev.hpp:67
series(series const &v)
The copy constructor.
Definition: chebyshev.hpp:78
size_t use_count() const
Find how many series objects share this pointer.
Definition: chebyshev.hpp:223
int init(gsl_function const *func, double const a, double const b)
C++ version of gsl_cheb_init().
Definition: chebyshev.hpp:250
series(size_t const order)
The default constructor creates a new series with n elements.
Definition: chebyshev.hpp:51
int init(function_scl const &func, double const a, double const b)
C++ version of gsl_cheb_init().
Definition: chebyshev.hpp:241
size_t * count
The shared reference count.
Definition: chebyshev.hpp:205
series & operator=(series &&v)
Move operator.
Definition: chebyshev.hpp:118
series & operator=(series const &v)
The assignment operator.
Definition: chebyshev.hpp:85
bool operator<(series const &v) const
A container needs to define an ordering for sorting.
Definition: chebyshev.hpp:151
series()
The default constructor is only really useful for assigning to.
Definition: chebyshev.hpp:41
bool operator!=(series const &v) const
Two series are different if their elements are not identical.
Definition: chebyshev.hpp:139
bool operator>(series const &v) const
A container needs to define an ordering for sorting.
Definition: chebyshev.hpp:161
gsl_cheb_series * ccgsl_pointer
The shared pointer.
Definition: chebyshev.hpp:201
bool empty() const
Find if the series is empty.
Definition: chebyshev.hpp:186
bool unique() const
Find if this is the only object sharing the gsl_cheb_series.
Definition: chebyshev.hpp:218
gsl_cheb_series * get() const
Get the gsl_cheb_series.
Definition: chebyshev.hpp:212
~series()
The destructor only deletes the pointers if count reaches zero.
Definition: chebyshev.hpp:97
Class that extends gsl_function so that it can be constructed from arbitrary function objects.
size_t order(series const &cs)
C++ version of gsl_cheb_order().
Definition: chebyshev.hpp:280
double eval_mode(series const &cs, double const x, gsl::mode_t mode)
C++ version of gsl_cheb_eval_mode().
Definition: chebyshev.hpp:372
size_t size(series const &cs)
C++ version of gsl_cheb_size().
Definition: chebyshev.hpp:287
int eval_err(series const &cs, double const x, double &result, double &abserr)
C++ version of gsl_cheb_eval_err().
Definition: chebyshev.hpp:325
int eval_n_err(series const &cs, size_t const order, double const x, double &result, double &abserr)
C++ version of gsl_cheb_eval_n_err().
Definition: chebyshev.hpp:361
int init(series &cs, function_scl const &func, double const a, double const b)
C++ version of gsl_cheb_init().
Definition: chebyshev.hpp:262
int calc_integ(series &integ, series const &cs)
C++ version of gsl_cheb_calc_integ().
Definition: chebyshev.hpp:417
double eval(series const &cs, double const x)
C++ version of gsl_cheb_eval().
Definition: chebyshev.hpp:302
int calc_deriv(series &deriv, series const &cs)
C++ version of gsl_cheb_calc_deriv().
Definition: chebyshev.hpp:408
double eval_n(series const &cs, size_t const order, double const x)
C++ version of gsl_cheb_eval_n().
Definition: chebyshev.hpp:335
double * coeffs(series const &cs)
C++ version of gsl_cheb_coeffs().
Definition: chebyshev.hpp:294
int eval_mode_e(series const &cs, double const x, gsl_mode_t mode, double &result, double &abserr)
C++ version of gsl_cheb_eval_mode_e().
Definition: chebyshev.hpp:398
double deriv(int const m, int const n, double const x)
C++ version of gsl_sf_hermite_deriv().
Definition: sf_hermite.hpp:126
double func(int const n, double const x)
C++ version of gsl_sf_hermite_func().
Definition: sf_hermite.hpp:154
double series(int const n, double const x, DATA const &a)
C++ version of gsl_sf_hermite_series().
Definition: sf_hermite.hpp:422
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
gsl_sf_result result
Typedef for gsl_sf_result.
Definition: sf_result.hpp:30
The gsl package creates an interface to the GNU Scientific Library for C++.
Definition: blas.hpp:34
gsl_mode_t mode_t
A typedef for gsl_mode_t.
Definition: mode.hpp:29