1# This file was automatically generated by SWIG (http://www.swig.org). 2# Version 4.0.1 3# 4# Do not make changes to this file unless you know what you are doing--modify 5# the SWIG interface file instead. 6 7package Math::GSL::Histogram; 8use base qw(Exporter); 9use base qw(DynaLoader); 10package Math::GSL::Histogramc; 11bootstrap Math::GSL::Histogram; 12package Math::GSL::Histogram; 13@EXPORT = qw(); 14 15# ---------- BASE METHODS ------------- 16 17package Math::GSL::Histogram; 18 19sub TIEHASH { 20 my ($classname,$obj) = @_; 21 return bless $obj, $classname; 22} 23 24sub CLEAR { } 25 26sub FIRSTKEY { } 27 28sub NEXTKEY { } 29 30sub FETCH { 31 my ($self,$field) = @_; 32 my $member_func = "swig_${field}_get"; 33 $self->$member_func(); 34} 35 36sub STORE { 37 my ($self,$field,$newval) = @_; 38 my $member_func = "swig_${field}_set"; 39 $self->$member_func($newval); 40} 41 42sub this { 43 my $ptr = shift; 44 return tied(%$ptr); 45} 46 47 48# ------- FUNCTION WRAPPERS -------- 49 50package Math::GSL::Histogram; 51 52*gsl_error = *Math::GSL::Histogramc::gsl_error; 53*gsl_stream_printf = *Math::GSL::Histogramc::gsl_stream_printf; 54*gsl_strerror = *Math::GSL::Histogramc::gsl_strerror; 55*gsl_set_error_handler = *Math::GSL::Histogramc::gsl_set_error_handler; 56*gsl_set_error_handler_off = *Math::GSL::Histogramc::gsl_set_error_handler_off; 57*gsl_set_stream_handler = *Math::GSL::Histogramc::gsl_set_stream_handler; 58*gsl_set_stream = *Math::GSL::Histogramc::gsl_set_stream; 59*gsl_histogram_alloc = *Math::GSL::Histogramc::gsl_histogram_alloc; 60*gsl_histogram_calloc = *Math::GSL::Histogramc::gsl_histogram_calloc; 61*gsl_histogram_calloc_uniform = *Math::GSL::Histogramc::gsl_histogram_calloc_uniform; 62*gsl_histogram_free = *Math::GSL::Histogramc::gsl_histogram_free; 63*gsl_histogram_increment = *Math::GSL::Histogramc::gsl_histogram_increment; 64*gsl_histogram_accumulate = *Math::GSL::Histogramc::gsl_histogram_accumulate; 65*gsl_histogram_find = *Math::GSL::Histogramc::gsl_histogram_find; 66*gsl_histogram_get = *Math::GSL::Histogramc::gsl_histogram_get; 67*gsl_histogram_get_range = *Math::GSL::Histogramc::gsl_histogram_get_range; 68*gsl_histogram_max = *Math::GSL::Histogramc::gsl_histogram_max; 69*gsl_histogram_min = *Math::GSL::Histogramc::gsl_histogram_min; 70*gsl_histogram_bins = *Math::GSL::Histogramc::gsl_histogram_bins; 71*gsl_histogram_reset = *Math::GSL::Histogramc::gsl_histogram_reset; 72*gsl_histogram_calloc_range = *Math::GSL::Histogramc::gsl_histogram_calloc_range; 73*gsl_histogram_set_ranges = *Math::GSL::Histogramc::gsl_histogram_set_ranges; 74*gsl_histogram_set_ranges_uniform = *Math::GSL::Histogramc::gsl_histogram_set_ranges_uniform; 75*gsl_histogram_memcpy = *Math::GSL::Histogramc::gsl_histogram_memcpy; 76*gsl_histogram_clone = *Math::GSL::Histogramc::gsl_histogram_clone; 77*gsl_histogram_max_val = *Math::GSL::Histogramc::gsl_histogram_max_val; 78*gsl_histogram_max_bin = *Math::GSL::Histogramc::gsl_histogram_max_bin; 79*gsl_histogram_min_val = *Math::GSL::Histogramc::gsl_histogram_min_val; 80*gsl_histogram_min_bin = *Math::GSL::Histogramc::gsl_histogram_min_bin; 81*gsl_histogram_equal_bins_p = *Math::GSL::Histogramc::gsl_histogram_equal_bins_p; 82*gsl_histogram_add = *Math::GSL::Histogramc::gsl_histogram_add; 83*gsl_histogram_sub = *Math::GSL::Histogramc::gsl_histogram_sub; 84*gsl_histogram_mul = *Math::GSL::Histogramc::gsl_histogram_mul; 85*gsl_histogram_div = *Math::GSL::Histogramc::gsl_histogram_div; 86*gsl_histogram_scale = *Math::GSL::Histogramc::gsl_histogram_scale; 87*gsl_histogram_shift = *Math::GSL::Histogramc::gsl_histogram_shift; 88*gsl_histogram_sigma = *Math::GSL::Histogramc::gsl_histogram_sigma; 89*gsl_histogram_mean = *Math::GSL::Histogramc::gsl_histogram_mean; 90*gsl_histogram_sum = *Math::GSL::Histogramc::gsl_histogram_sum; 91*gsl_histogram_fwrite = *Math::GSL::Histogramc::gsl_histogram_fwrite; 92*gsl_histogram_fread = *Math::GSL::Histogramc::gsl_histogram_fread; 93*gsl_histogram_fprintf = *Math::GSL::Histogramc::gsl_histogram_fprintf; 94*gsl_histogram_fscanf = *Math::GSL::Histogramc::gsl_histogram_fscanf; 95*gsl_histogram_pdf_alloc = *Math::GSL::Histogramc::gsl_histogram_pdf_alloc; 96*gsl_histogram_pdf_init = *Math::GSL::Histogramc::gsl_histogram_pdf_init; 97*gsl_histogram_pdf_free = *Math::GSL::Histogramc::gsl_histogram_pdf_free; 98*gsl_histogram_pdf_sample = *Math::GSL::Histogramc::gsl_histogram_pdf_sample; 99 100############# Class : Math::GSL::Histogram::gsl_histogram ############## 101 102package Math::GSL::Histogram::gsl_histogram; 103use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 104@ISA = qw( Math::GSL::Histogram ); 105%OWNER = (); 106%ITERATORS = (); 107*swig_n_get = *Math::GSL::Histogramc::gsl_histogram_n_get; 108*swig_n_set = *Math::GSL::Histogramc::gsl_histogram_n_set; 109*swig_range_get = *Math::GSL::Histogramc::gsl_histogram_range_get; 110*swig_range_set = *Math::GSL::Histogramc::gsl_histogram_range_set; 111*swig_bin_get = *Math::GSL::Histogramc::gsl_histogram_bin_get; 112*swig_bin_set = *Math::GSL::Histogramc::gsl_histogram_bin_set; 113sub new { 114 my $pkg = shift; 115 my $self = Math::GSL::Histogramc::new_gsl_histogram(@_); 116 bless $self, $pkg if defined($self); 117} 118 119sub DESTROY { 120 return unless $_[0]->isa('HASH'); 121 my $self = tied(%{$_[0]}); 122 return unless defined $self; 123 delete $ITERATORS{$self}; 124 if (exists $OWNER{$self}) { 125 Math::GSL::Histogramc::delete_gsl_histogram($self); 126 delete $OWNER{$self}; 127 } 128} 129 130sub DISOWN { 131 my $self = shift; 132 my $ptr = tied(%$self); 133 delete $OWNER{$ptr}; 134} 135 136sub ACQUIRE { 137 my $self = shift; 138 my $ptr = tied(%$self); 139 $OWNER{$ptr} = 1; 140} 141 142 143############# Class : Math::GSL::Histogram::gsl_histogram_pdf ############## 144 145package Math::GSL::Histogram::gsl_histogram_pdf; 146use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 147@ISA = qw( Math::GSL::Histogram ); 148%OWNER = (); 149%ITERATORS = (); 150*swig_n_get = *Math::GSL::Histogramc::gsl_histogram_pdf_n_get; 151*swig_n_set = *Math::GSL::Histogramc::gsl_histogram_pdf_n_set; 152*swig_range_get = *Math::GSL::Histogramc::gsl_histogram_pdf_range_get; 153*swig_range_set = *Math::GSL::Histogramc::gsl_histogram_pdf_range_set; 154*swig_sum_get = *Math::GSL::Histogramc::gsl_histogram_pdf_sum_get; 155*swig_sum_set = *Math::GSL::Histogramc::gsl_histogram_pdf_sum_set; 156sub new { 157 my $pkg = shift; 158 my $self = Math::GSL::Histogramc::new_gsl_histogram_pdf(@_); 159 bless $self, $pkg if defined($self); 160} 161 162sub DESTROY { 163 return unless $_[0]->isa('HASH'); 164 my $self = tied(%{$_[0]}); 165 return unless defined $self; 166 delete $ITERATORS{$self}; 167 if (exists $OWNER{$self}) { 168 Math::GSL::Histogramc::delete_gsl_histogram_pdf($self); 169 delete $OWNER{$self}; 170 } 171} 172 173sub DISOWN { 174 my $self = shift; 175 my $ptr = tied(%$self); 176 delete $OWNER{$ptr}; 177} 178 179sub ACQUIRE { 180 my $self = shift; 181 my $ptr = tied(%$self); 182 $OWNER{$ptr} = 1; 183} 184 185 186# ------- VARIABLE STUBS -------- 187 188package Math::GSL::Histogram; 189 190*GSL_VERSION = *Math::GSL::Histogramc::GSL_VERSION; 191*GSL_MAJOR_VERSION = *Math::GSL::Histogramc::GSL_MAJOR_VERSION; 192*GSL_MINOR_VERSION = *Math::GSL::Histogramc::GSL_MINOR_VERSION; 193*GSL_POSZERO = *Math::GSL::Histogramc::GSL_POSZERO; 194*GSL_NEGZERO = *Math::GSL::Histogramc::GSL_NEGZERO; 195*GSL_SUCCESS = *Math::GSL::Histogramc::GSL_SUCCESS; 196*GSL_FAILURE = *Math::GSL::Histogramc::GSL_FAILURE; 197*GSL_CONTINUE = *Math::GSL::Histogramc::GSL_CONTINUE; 198*GSL_EDOM = *Math::GSL::Histogramc::GSL_EDOM; 199*GSL_ERANGE = *Math::GSL::Histogramc::GSL_ERANGE; 200*GSL_EFAULT = *Math::GSL::Histogramc::GSL_EFAULT; 201*GSL_EINVAL = *Math::GSL::Histogramc::GSL_EINVAL; 202*GSL_EFAILED = *Math::GSL::Histogramc::GSL_EFAILED; 203*GSL_EFACTOR = *Math::GSL::Histogramc::GSL_EFACTOR; 204*GSL_ESANITY = *Math::GSL::Histogramc::GSL_ESANITY; 205*GSL_ENOMEM = *Math::GSL::Histogramc::GSL_ENOMEM; 206*GSL_EBADFUNC = *Math::GSL::Histogramc::GSL_EBADFUNC; 207*GSL_ERUNAWAY = *Math::GSL::Histogramc::GSL_ERUNAWAY; 208*GSL_EMAXITER = *Math::GSL::Histogramc::GSL_EMAXITER; 209*GSL_EZERODIV = *Math::GSL::Histogramc::GSL_EZERODIV; 210*GSL_EBADTOL = *Math::GSL::Histogramc::GSL_EBADTOL; 211*GSL_ETOL = *Math::GSL::Histogramc::GSL_ETOL; 212*GSL_EUNDRFLW = *Math::GSL::Histogramc::GSL_EUNDRFLW; 213*GSL_EOVRFLW = *Math::GSL::Histogramc::GSL_EOVRFLW; 214*GSL_ELOSS = *Math::GSL::Histogramc::GSL_ELOSS; 215*GSL_EROUND = *Math::GSL::Histogramc::GSL_EROUND; 216*GSL_EBADLEN = *Math::GSL::Histogramc::GSL_EBADLEN; 217*GSL_ENOTSQR = *Math::GSL::Histogramc::GSL_ENOTSQR; 218*GSL_ESING = *Math::GSL::Histogramc::GSL_ESING; 219*GSL_EDIVERGE = *Math::GSL::Histogramc::GSL_EDIVERGE; 220*GSL_EUNSUP = *Math::GSL::Histogramc::GSL_EUNSUP; 221*GSL_EUNIMPL = *Math::GSL::Histogramc::GSL_EUNIMPL; 222*GSL_ECACHE = *Math::GSL::Histogramc::GSL_ECACHE; 223*GSL_ETABLE = *Math::GSL::Histogramc::GSL_ETABLE; 224*GSL_ENOPROG = *Math::GSL::Histogramc::GSL_ENOPROG; 225*GSL_ENOPROGJ = *Math::GSL::Histogramc::GSL_ENOPROGJ; 226*GSL_ETOLF = *Math::GSL::Histogramc::GSL_ETOLF; 227*GSL_ETOLX = *Math::GSL::Histogramc::GSL_ETOLX; 228*GSL_ETOLG = *Math::GSL::Histogramc::GSL_ETOLG; 229*GSL_EOF = *Math::GSL::Histogramc::GSL_EOF; 230 231@EXPORT_OK = qw/ 232 gsl_histogram_alloc 233 gsl_histogram_calloc 234 gsl_histogram_calloc_uniform 235 gsl_histogram_free 236 gsl_histogram_increment 237 gsl_histogram_accumulate 238 gsl_histogram_find 239 gsl_histogram_get 240 gsl_histogram_get_range 241 gsl_histogram_max 242 gsl_histogram_min 243 gsl_histogram_bins 244 gsl_histogram_reset 245 gsl_histogram_calloc_range 246 gsl_histogram_set_ranges 247 gsl_histogram_set_ranges_uniform 248 gsl_histogram_memcpy 249 gsl_histogram_clone 250 gsl_histogram_max_val 251 gsl_histogram_max_bin 252 gsl_histogram_min_val 253 gsl_histogram_min_bin 254 gsl_histogram_equal_bins_p 255 gsl_histogram_add 256 gsl_histogram_sub 257 gsl_histogram_mul 258 gsl_histogram_div 259 gsl_histogram_scale 260 gsl_histogram_shift 261 gsl_histogram_sigma 262 gsl_histogram_mean 263 gsl_histogram_sum 264 gsl_histogram_fwrite 265 gsl_histogram_fread 266 gsl_histogram_fprintf 267 gsl_histogram_fscanf 268 gsl_histogram_pdf_alloc 269 gsl_histogram_pdf_init 270 gsl_histogram_pdf_free 271 gsl_histogram_pdf_sample 272 /; 273%EXPORT_TAGS = ( all => \@EXPORT_OK ); 274 275=head1 NAME 276 277=encoding utf8 278 279Math::GSL::Histogram - Create and manipulate histograms of data 280 281=head1 SYNOPSIS 282 283 use Math::GSL::Histogram qw/:all/; 284 285 my $H = gsl_histogram_alloc(100); 286 gsl_histogram_set_ranges_uniform($H,0,101); 287 gsl_histogram_increment($H, -50 ); # ignored 288 gsl_histogram_increment($H, 70 ); 289 gsl_histogram_increment($H, 85.2 ); 290 291 my $G = gsl_histogram_clone($H); 292 my $value = gsl_histogram_get($G, 70); 293 my ($max,$min) = (gsl_histogram_min_val($H), gsl_histogram_max_val($H) ); 294 my $sum = gsl_histogram_sum($H); 295 296=cut 297 298=head1 DESCRIPTION 299 300Here is a list of all the functions included in this module : 301 302=over 1 303 304=item C<gsl_histogram_alloc($n)> - This function allocates memory for a histogram with $n bins, and returns a pointer to a newly created gsl_histogram struct. The bins and ranges are not initialized, and should be prepared using one of the range-setting functions below in order to make the histogram ready for use. 305 306=item C<gsl_histogram_calloc > 307 308=item C<gsl_histogram_calloc_uniform > 309 310=item C<gsl_histogram_free($h)> - This function frees the histogram $h and all of the memory associated with it. 311 312=item C<gsl_histogram_increment($h, $x)> - This function updates the histogram $h by adding one (1.0) to the bin whose range contains the coordinate $x. If $x lies in the valid range of the histogram then the function returns zero to indicate success. If $x is less than the lower limit of the histogram then the function returns $GSL_EDOM, and none of bins are modified. Similarly, if the value of $x is greater than or equal to the upper limit of the histogram then the function returns $GSL_EDOM, and none of the bins are modified. The error handler is not called, however, since it is often necessary to compute histograms for a small range of a larger dataset, ignoring the values outside the range of interest. 313 314=item C<gsl_histogram_accumulate($h, $x, $weight)> - This function is similar to gsl_histogram_increment but increases the value of the appropriate bin in the histogram $h by the floating-point number weight. 315 316=item C<gsl_histogram_find($h, $x)> - This function finds the bin number which covers the coordinate $x in the histogram $h. The bin is located using a binary search. The search includes an optimization for histograms with uniform range, and will return the correct bin immediately in this case. If $x is found in the range of the histogram then the function returns the bin number and returns $GSL_SUCCESS. If $x lies outside the valid range of the histogram then the function returns $GSL_EDOM and the error handler is invoked. 317 318=item C<gsl_histogram_get($h, $i)> - This function returns the contents of the $i-th bin of the histogram $h. If $i lies outside the valid range of indices for the histogram then the error handler is called with an error code of GSL_EDOM and the function returns 0. 319 320=item C<gsl_histogram_get_range($h, $i)> - This function finds the upper and lower range limits of the $i-th bin of the histogram $h. If the index $i is valid then the corresponding range limits are returned after the 0 in this order : lower and then upper. The lower limit is inclusive (i.e. events with this coordinate are included in the bin) and the upper limit is exclusive (i.e. events with the coordinate of the upper limit are excluded and fall in the neighboring higher bin, if it exists). The function returns 0 to indicate success. If i lies outside the valid range of indices for the histogram then the error handler is called and the function returns an error code of $GSL_EDOM. 321 322=item C<gsl_histogram_max($h)> - This function returns the maximum upper limit of the histogram $h. It provides a way of determining this value without accessing the gsl_histogram struct directly. 323 324=item C<gsl_histogram_min($h)> - This function returns the minimum lower range limit of the histogram $h. It provides a way of determining this value without accessing the gsl_histogram struct directly. 325 326=item C<gsl_histogram_bins($h)> - This function returns the number of bins of the histogram $h limit. It provides a way of determining this value without accessing the gsl_histogram struct directly. 327 328=item C<gsl_histogram_reset($h)> - This function resets all the bins in the histogram $h to zero. 329 330=item C<gsl_histogram_calloc_range> 331 332=item C<gsl_histogram_set_ranges($h, $range, $size)> - This function sets the ranges of the existing histogram $h using the array $range of size $size. The values of the histogram bins are reset to zero. The $range array should contain the desired bin limits. The ranges can be arbitrary, subject to the restriction that they are monotonically increasing. Note that the size of the $range array should be defined to be one element bigger than the number of bins. The additional element is required for the upper value of the final bin. 333 334=item C<gsl_histogram_set_ranges_uniform($h, $xmin, $xmax)> - This function sets the ranges of the existing histogram $h to cover the range $xmin to $xmax uniformly. The values of the histogram bins are reset to zero. The bin ranges are shown in the table below, 335 336=back 337 338=over 339 340=item bin[0] corresponds to xmin <= x < xmin + d 341 342=item bin[1] corresponds to xmin + d <= x < xmin + 2 d 343 344=item ...... 345 346=item bin[n-1] corresponds to xmin + (n-1)d <= x < xmax 347 348=back 349 350where d is the bin spacing, d = (xmax-xmin)/n. 351 352=over 353 354=item C<gsl_histogram_memcpy($dest, $src)> - This function copies the histogram $src into the pre-existing histogram $dest, making $dest into an exact copy of $src. The two histograms must be of the same size. 355 356=item C<gsl_histogram_clone($src)> - This function returns a pointer to a newly created histogram which is an exact copy of the histogram $src. 357 358=item C<gsl_histogram_max_val($h)> - This function returns the maximum value contained in the histogram bins. 359 360=item C<gsl_histogram_max_bin($h)> - This function returns the index of the bin containing the maximum value. In the case where several bins contain the same maximum value the smallest index is returned. 361 362=item C<gsl_histogram_min_val($h)> - This function returns the minimum value contained in the histogram bins. 363 364=item C<gsl_histogram_min_bin($h)> - This function returns the index of the bin containing the minimum value. In the case where several bins contain the same maximum value the smallest index is returned. 365 366=item C<gsl_histogram_equal_bins_p($h1, $h2)> - This function returns 1 if the all of the individual bin ranges of the two histograms are identical, and 0 otherwise. 367 368=item C<gsl_histogram_add($h1, $h2)> - This function adds the contents of the bins in histogram $h2 to the corresponding bins of histogram $h1, i.e. h'_1(i) = h_1(i) + h_2(i). The two histograms must have identical bin ranges. 369 370=item C<gsl_histogram_sub($h1, $h2)> - This function subtracts the contents of the bins in histogram $h2 from the corresponding bins of histogram $h1, i.e. h'_1(i) = h_1(i) - h_2(i). The two histograms must have identical bin ranges. 371 372=item C<gsl_histogram_mul($h1, $h2)> - This function multiplies the contents of the bins of histogram $h1 by the contents of the corresponding bins in histogram $h2, i.e. h'_1(i) = h_1(i) * h_2(i). The two histograms must have identical bin ranges. 373 374=item C<gsl_histogram_div($h1, $h2)> - This function divides the contents of the bins of histogram $h1 by the contents of the corresponding bins in histogram $h2, i.e. h'_1(i) = h_1(i) / h_2(i). The two histograms must have identical bin ranges. 375 376=item C<gsl_histogram_scale($h, $scale)> - This function multiplies the contents of the bins of histogram $h by the constant $scale, i.e. h'_1(i) = h_1(i) * scale. 377 378=item C<gsl_histogram_shift($h, $offset)> - This function shifts the contents of the bins of histogram $h by the constant $offset, i.e. h'_1(i) = h_1(i) + offset. 379 380=item C<gsl_histogram_sigma($h)> - This function returns the standard deviation of the histogrammed variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation. The accuracy of the result is limited by the bin width. 381 382=item C<gsl_histogram_mean($h)> - This function returns the mean of the histogrammed variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation. The accuracy of the result is limited by the bin width. 383 384=item C<gsl_histogram_sum($h)> - This function returns the sum of all bin values. Negative bin values are included in the sum. 385 386=item C<gsl_histogram_fwrite($stream, $h)> - This function writes the ranges and bins of the histogram $h to the stream $stream, which has been opened by the gsl_fopen function from the Math::GSL module, in binary format. The return value is 0 for success and $GSL_EFAILED if there was a problem writing to the file. Since the data is written in the native binary format it may not be portable between different architectures. 387 388=item C<gsl_histogram_fread($stream, $h)> - This function reads into the histogram $h from the open stream $stream, which has been opened by the gsl_fopen function from the Math::GSL module, in binary format. The histogram $h must be preallocated with the correct size since the function uses the number of bins in $h to determine how many bytes to read. The return value is 0 for success and $GSL_EFAILED if there was a problem reading from the file. The data is assumed to have been written in the native binary format on the same architecture. 389 390=item C<gsl_histogram_fprintf($stream, $h, $range_format, $bin_format)> - This function writes the ranges and bins of the histogram $h line-by-line to the stream $stream (from the gsl_fopen function from the Math::GSL module) using the format specifiers $range_format and $bin_format. These should be one of the %g, %e or %f formats for floating point numbers. The function returns 0 for success and $GSL_EFAILED if there was a problem writing to the file. The histogram output is formatted in three columns, and the columns are separated by spaces, like this, 391 392=over 393 394=item range[0] range[1] bin[0] 395 396=item range[1] range[2] bin[1] 397 398=item range[2] range[3] bin[2] 399 400=item .... 401 402=item range[n-1] range[n] bin[n-1] 403 404=back 405 406The values of the ranges are formatted using range_format and the value of the bins are formatted using bin_format. Each line contains the lower and upper limit of the range of the bins and the value of the bin itself. Since the upper limit of one bin is the lower limit of the next there is duplication of these values between lines but this allows the histogram to be manipulated with line-oriented tools. 407 408=item C<gsl_histogram_fscanf($stream, $h)> - This function reads formatted data from the stream $stream, which has been opened by the gsl_fopen function from the Math::GSL module, into the histogram $h. The data is assumed to be in the three-column format used by gsl_histogram_fprintf. The histogram $h must be preallocated with the correct length since the function uses the size of $h to determine how many numbers to read. The function returns 0 for success and $GSL_EFAILED if there was a problem reading from the file. 409 410=item C<gsl_histogram_pdf_alloc($n)> - This function allocates memory for a probability distribution with $n bins and returns a pointer to a newly initialized gsl_histogram_pdf struct. If insufficient memory is available a null pointer is returned and the error handler is invoked with an error code of $GSL_ENOMEM. 411 412=item C<gsl_histogram_pdf_init($p, $h)> - This function initializes the probability distribution $p with the contents of the histogram $h. If any of the bins of $h are negative then the error handler is invoked with an error code of $GSL_EDOM because a probability distribution cannot contain negative values. 413 414=item C<gsl_histogram_pdf_free($p)> - This function frees the probability distribution function $p and all of the memory associated with it. 415 416=item C<gsl_histogram_pdf_sample($p, $r)> - This function uses $r, a uniform random number between zero and one, to compute a single random sample from the probability distribution $p. The algorithm used to compute the sample s is given by the following formula, s = range[i] + delta * (range[i+1] - range[i]) where i is the index which satisfies sum[i] <= r < sum[i+1] and delta is (r - sum[i])/(sum[i+1] - sum[i]). 417 418=back 419 420=head1 EXAMPLES 421 422 The following example shows how to create a histogram with logarithmic bins with ranges [1,10), [10,100) and [100,1000). 423 424 $h = gsl_histogram_alloc (3); 425 426 # bin[0] covers the range 1 <= x < 10 427 # bin[1] covers the range 10 <= x < 100 428 # bin[2] covers the range 100 <= x < 1000 429 430 $range = [ 1.0, 10.0, 100.0, 1000.0 ]; 431 432 gsl_histogram_set_ranges($h, $range, 4); 433 434=head1 AUTHORS 435 436Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> 437 438=head1 COPYRIGHT AND LICENSE 439 440Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan 441 442This program is free software; you can redistribute it and/or modify it 443under the same terms as Perl itself. 444 445=cut 446 4471; 448