20#ifndef CCGSL_HISTOGRAM_HPP
21#define CCGSL_HISTOGRAM_HPP
24#include<gsl/gsl_histogram.h>
49 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
99#ifdef __GXX_EXPERIMENTAL_CXX0X__
105 std::swap(
count, v.count );
106 v.ccgsl_pointer =
nullptr;
114 histogram( std::move( v ) ).swap( *
this );
224#ifdef __GXX_EXPERIMENTAL_CXX0X__
244 inline static histogram calloc_uniform(
size_t const n,
double const xmin,
double const xmax ){
245 return histogram( gsl_histogram_calloc_uniform(
n, xmin, xmax ) ); }
253 int increment(
double x ){
return gsl_histogram_increment(
get(), x ); }
262 return gsl_histogram_accumulate(
get(), x, weight ); }
271 int find(
double const x,
size_t* i )
const {
272 return gsl_histogram_find(
get(), x, i ); }
280 int find(
double const x,
size_t& i )
const {
281 return gsl_histogram_find(
get(), x, &i ); }
288 double get(
size_t i )
const {
return gsl_histogram_get(
get(), i ); }
295 double operator[](
size_t i )
const {
return gsl_histogram_get(
get(), i ); }
304 int get_range(
size_t i,
double* lower,
double* upper )
const {
305 return gsl_histogram_get_range(
get(), i, lower, upper ); }
313 int get_range(
size_t i,
double& lower,
double& upper )
const {
314 return gsl_histogram_get_range(
get(), i, &lower, &upper ); }
320 double max()
const {
return gsl_histogram_max(
get() ); }
326 double min()
const {
return gsl_histogram_min(
get() ); }
332 size_t bins()
const {
return gsl_histogram_bins(
get() ); }
346 inline static histogram calloc_range(
size_t n,
double* range ){
347 return histogram( gsl_histogram_calloc_range(
n, range ) ); }
354 template<
typename RANGE>
355 inline static histogram calloc_range( RANGE& range ){
356 return histogram( gsl_histogram_calloc_range( range.size(), range.data() ) ); }
365 template<
typename RANGE>
367 return gsl_histogram_set_ranges(
get(), range.data(), range.size() ); }
376 return gsl_histogram_set_ranges_uniform(
get(), xmin, xmax ); }
395 double max_val()
const {
return gsl_histogram_max_val(
get() ); }
401 size_t max_bin()
const {
return gsl_histogram_max_bin(
get() ); }
407 double min_val()
const {
return gsl_histogram_min_val(
get() ); }
413 size_t min_bin()
const {
return gsl_histogram_min_bin(
get() ); }
422 return gsl_histogram_equal_bins_p(
get(), h2.
get() ) != 0; }
470 double sigma()
const {
return gsl_histogram_sigma(
get() ); }
476 double mean()
const {
return gsl_histogram_mean(
get() ); }
482 double sum()
const {
return gsl_histogram_sum(
get() ); }
489 int fwrite( FILE* stream )
const {
return gsl_histogram_fwrite( stream,
get() ); }
496 int fread( FILE* stream ){
return gsl_histogram_fread( stream,
get() ); }
505 int fprintf( FILE* stream,
char const* range_format,
char const* bin_format )
const {
506 return gsl_histogram_fprintf( stream,
get(), range_format, bin_format ); }
513 int fscanf( FILE* stream ){
return gsl_histogram_fscanf( stream,
get() ); }
534 explicit pdf(
size_t const n ){
537 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
550 explicit pdf( gsl_histogram_pdf* v ){
589#ifdef __GXX_EXPERIMENTAL_CXX0X__
595 std::swap(
count, v.count );
596 v.ccgsl_pointer =
nullptr;
604 pdf( std::move( v ) ).swap( *
this );
714#ifdef __GXX_EXPERIMENTAL_CXX0X__
731 double sample(
double r ){
return gsl_histogram_pdf_sample(
get(), r ); }
Histogram probability (empirical) density functions.
bool empty() const
Find if the pdf is empty.
bool operator<(pdf const &v) const
A container needs to define an ordering for sorting.
void swap(pdf &v)
Swap two pdf objects.
bool operator==(pdf const &v) const
Two pdf are identically equal if their elements are identical.
int init(histogram const &h)
C++ version of gsl_histogram_pdf_init().
size_t use_count() const
Find how many pdf objects share this pointer.
pdf(pdf const &v)
The copy constructor.
pdf & operator=(pdf const &v)
The assignment operator.
bool operator>=(pdf const &v) const
A container needs to define an ordering for sorting.
size_t * count
The shared reference count.
pdf()
The default constructor is only really useful for assigning to.
pdf(gsl_histogram_pdf *v)
Could construct from a gsl_histogram_pdf.
gsl_histogram_pdf * ccgsl_pointer
The shared pointer.
bool operator!=(pdf const &v) const
Two pdf are different if their elements are not identical.
pdf(pdf &&v)
Move constructor.
bool operator<=(pdf const &v) const
A container needs to define an ordering for sorting.
double sample(double r)
C++ version of gsl_histogram_pdf_sample().
gsl_histogram_pdf * get() const
Get the gsl_histogram_pdf.
pdf(size_t const n)
The default constructor creates a new pdf with n elements.
bool unique() const
Find if this is the only object sharing the gsl_histogram_pdf.
bool operator>(pdf const &v) const
A container needs to define an ordering for sorting.
~pdf()
The destructor only deletes the pointers if count reaches zero.
pdf & operator=(pdf &&v)
Move operator.
void swap(histogram &v)
Swap two histogram objects.
int get_range(size_t i, double &lower, double &upper) const
C++ version of gsl_histogram_get_range().
double operator[](size_t i) const
C++ version of gsl_histogram_get().
int fread(FILE *stream)
C++ version of gsl_histogram_fread().
double min_val() const
C++ version of gsl_histogram_min_val().
double mean() const
C++ version of gsl_histogram_mean().
double get(size_t i) const
C++ version of gsl_histogram_get().
bool empty() const
Find if the histogram is empty.
int fscanf(FILE *stream)
C++ version of gsl_histogram_fscanf().
int mul(histogram const &h2)
C++ version of gsl_histogram_mul().
bool operator==(histogram const &v) const
Two histogram are identically equal if their elements are identical.
size_t min_bin() const
C++ version of gsl_histogram_min_bin().
histogram clone() const
C++ version of gsl_histogram_clone().
int sub(histogram const &h2)
C++ version of gsl_histogram_sub().
bool operator<=(histogram const &v) const
A container needs to define an ordering for sorting.
int memcpy(histogram const &source)
C++ version of gsl_histogram_memcpy().
bool operator>(histogram const &v) const
A container needs to define an ordering for sorting.
int fprintf(FILE *stream, char const *range_format, char const *bin_format) const
C++ version of gsl_histogram_fprintf().
int find(double const x, size_t &i) const
C++ version of gsl_histogram_find().
bool unique() const
Find if this is the only object sharing the gsl_histogram.
double sigma() const
C++ version of gsl_histogram_sigma().
double min() const
C++ version of gsl_histogram_min().
void reset()
C++ version of gsl_histogram_reset().
histogram()
The default constructor is only really useful for assigning to.
size_t bins() const
C++ version of gsl_histogram_bins().
int increment(double x)
C++ version of gsl_histogram_increment().
histogram(histogram const &v)
The copy constructor.
bool operator>=(histogram const &v) const
A container needs to define an ordering for sorting.
~histogram()
The destructor only deletes the pointers if count reaches zero.
int add(histogram const &h2)
C++ version of gsl_histogram_add().
int scale(double const scale)
C++ version of gsl_histogram_scale().
size_t * count
The shared reference count.
gsl_histogram * get() const
Get the gsl_histogram.
int set_ranges(RANGE const &range)
C++ version of gsl_histogram_set_ranges().
int get_range(size_t i, double *lower, double *upper) const
C++ version of gsl_histogram_get_range().
histogram(gsl_histogram *v)
Could construct from a gsl_histogram.
bool operator<(histogram const &v) const
A container needs to define an ordering for sorting.
gsl_histogram * ccgsl_pointer
The shared pointer.
histogram(histogram &&v)
Move constructor.
size_t max_bin() const
C++ version of gsl_histogram_max_bin().
size_t use_count() const
Find how many histogram objects share this pointer.
bool equal_bins_p(histogram const &h2) const
C++ version of gsl_histogram_equal_bins_p().
histogram(size_t const n)
The default constructor creates a new histogram with n elements.
int fwrite(FILE *stream) const
C++ version of gsl_histogram_fwrite().
histogram & operator=(histogram const &v)
The assignment operator.
int div(histogram const &h2)
C++ version of gsl_histogram_div().
int set_ranges_uniform(double xmin, double xmax)
C++ version of gsl_histogram_set_ranges_uniform().
int accumulate(double x, double weight)
C++ version of gsl_histogram_accumulate().
histogram & operator=(histogram &&v)
Move operator.
bool operator!=(histogram const &v) const
Two histogram are different if their elements are not identical.
int shift(double const shift)
C++ version of gsl_histogram_shift().
double max_val() const
C++ version of gsl_histogram_max_val().
double sum() const
C++ version of gsl_histogram_sum().
double max() const
C++ version of gsl_histogram_max().
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
The gsl package creates an interface to the GNU Scientific Library for C++.