3 use base
qw(DynaLoader);
6 use Math
::GSL
::Machine qw
/:all/;
7 use Math
::GSL
::Const qw
/:all/;
8 use Math
::GSL
::Errno qw
/:all/;
13 use Scalar
::Util qw
/looks_like_number/;
15 our @EXPORT_OK = qw( ok_similar ok_status is_similar is_similar_relative verify verify_results $GSL_MODE_DEFAULT $GSL_PREC_DOUBLE $GSL_PREC_SINGLE $GSL_PREC_APPROX);
21 our ($GSL_PREC_DOUBLE, $GSL_PREC_SINGLE, $GSL_PREC_APPROX ) = 0..2;
22 our $GSL_MODE_DEFAULT = $GSL_PREC_DOUBLE;
27 Math::GSL - Perl interface to the GNU Scientific Library (GSL) using SWIG
37 use Math::GSL qw/:all/;
38 use Math::GSL qw/ok_similar is_similar/;
39 use Math::GSL qw/$GSL_MODE_DEFAULT $GSL_PREC_DOUBLE $GSL_PREC_SINGLE $GSL_PREC_APPROX/;
41 This module contains a few helper functions and global variables. Each GSL subsystem has it's own
42 module. For example, the random number generator subsystem is Math::GSL::RNG .
46 Math::GSL::BSpline - BSplines
49 Math::GSL::CDF - Cumulative Distribution Functions
50 Math::GSL::Chebyshev - Chebyshev Polynomials
51 Math::GSL::Combination - Combinatoric Functions
52 Math::GSL::Complex - Complex Numbers
53 Math::GSL::Const - Various Constants
54 Math::GSL::DHT - Discrete Hilbert Transform
55 Math::GSL::Deriv - Numerical Derivative
57 Math::GSL::Eigen - Eigenvalues and Eigenvectors
58 Math::GSL::Errno - Error Handling
59 Math::GSL::FFT - Fast Fourier Transform
60 Math::GSL::Fit - Curve Fitting
61 Math::GSL::Heapsort - Sorting Heaps
62 Math::GSL::Histograma - Histograms
63 Math::GSL::Histogram2D - 2D Histograms
64 Math::GSL::Integration - Numerical Integration
65 Math::GSL::Interp - Interpolation
66 Math::GSL::Linalg - Linear Algebra
67 Math::GSL::Machine - Machine Specific Information
68 Math::GSL::Matrix - NxM Matrices
69 Math::GSL::Min - Minimization
70 Math::GSL::Mode - GSL Precision Modes
71 Math::GSL::Monte - Monte Carlo Integrations
72 Math::GSL::Multifit - Multivariable Fitting
73 Math::GSL::Multimin - Multivariable Minimization
74 Math::GSL::Multiroots - Muiltvariable Root Finding
75 Math::GSL::NTuple - N Tuples
76 Math::GSL::ODEIV - Ordinary Differential Equation Solvers (Initial Value Problems)
77 Math::GSL::Permutation - Permutations
78 Math::GSL::Poly - Polynmials
79 Math::GSL::PowInt - Integer Power Functions
80 Math::GSL::QRNG - Quasi-Random Number Generators
81 Math::GSL::RNG - Random Number Generators
82 Math::GSL::Randist - Random Number Distributions
83 Math::GSL::Roots - Root Finding Algorithms
84 Math::GSL::SF - Special Functions
85 Math::GSL::Siman - Simulated Annealing
86 Math::GSL::Sort - Sorting
87 Math::GSL::Spline - Splines
88 Math::GSL::Statistics - Statistics Functions
89 Math::GSL::Sum - Summation
90 Math::GSL::Sys - Sytem utility functions
91 Math::GSL::Vector - N-dimensional Vectors
92 Math::GSL::Wavelet - Basic Wavelets
93 Math::GSL::Wavelet2D - 2D Wavelets
98 Jonathan Leto, C<< <jonathan@leto.net> >> and Thierry Moisan C<< <thierry.moisan@gmail.com> >>
102 This software is still in active development, we appreciate your detailed bug reports.
103 Please report any bugs or feature requests to the authors directly.
108 You can find documentation for this module with the perldoc command.
112 or online at L<http://leto.net/code/Math-GSL/>
116 =item * AnnoCPAN: Annotated CPAN documentation
118 L<http://annocpan.org/dist/Math::GSL>
122 L<http://cpanratings.perl.org/d/Math::GSL>
126 L<http://search.cpan.org/dist/Math::GSL>
132 If you would like the help develop Math::GSL, email the authors
135 git clone http://leto.net/code/Math-GSL.git
137 git checkout -b bleed # create new local branch
138 git pull origin bleed # pull in remote bleed
140 to get the latest source, which is a two-headed beast with branches master and
141 bleed. The master branch is our stable branch, which is periodically sync-ed
142 with bleed. To view the latest source code online, go to
143 L<http://leto.net/gitweb/>. The latest version of Git can be found at
146 =head1 ACKNOWLEDGEMENTS
149 =head1 COPYRIGHT & LICENSE
151 Copyright 2008 Jonathan Leto, Thierry Moisan all rights reserved.
153 This program is free software; you can redistribute it and/or modify it
154 under the same terms as Perl itself.
160 my ($self,$args) = @_;
161 my $class = ref $self || $self || 'Math::GSL';
169 Diff Machine Statistics
170 Block Eigen Matrix Poly
172 CBLAS FFT Min IEEEUtils
174 Chebyshev Monte RNG Vector
175 Heapsort Multifit Randist Roots
176 Combination Histogram Multimin Wavelet
177 Complex Histogram2D Multiroots Wavelet2D
179 Integration NTuple Sort
181 Deriv Linalg Permutation Spline
187 my ($x,$y, $eps, $similarity_function) = @_;
189 if (ref $x eq 'ARRAY' && ref $y eq 'ARRAY') {
191 warn "is_similar(): argument of different lengths, $#$x != $#$y !!!";
195 my $delta = abs($x->[$_] - $y->[$_]);
197 warn "\n\tElements start differing at index $_, delta = $delta\n";
198 warn qq{\t\t\$x->[$_] = } . $x->[$_] . "\n";
199 warn qq{\t\t\$y->[$_] = } . $y->[$_] . "\n";
206 if( ref $similarity_function eq 'CODE') {
207 $similarity_function->($x,$y) <= $eps ? return 1 : return 0;
209 abs($x-$y) <= $eps ? return 1 : return 0;
214 my ($got, $expected) = @_;
215 ok( $got == $expected, gsl_strerror($expected) );
218 my ($x,$y, $msg, $eps) = @_;
219 ok(is_similar($x,$y,$eps), $msg);
222 sub is_similar_relative {
223 my ($x,$y, $eps) = @_;
224 return is_similar($x,$y,$eps, sub { abs( ($_[0] - $_[1])/abs($_[1]) ) } );
227 # this is a huge hack
230 my ($results,$class) = @_;
231 # GSL uses a factor of 100
233 my $eps = 2048*$Math::GSL::Machine::GSL_DBL_EPSILON; # TOL3
236 croak "Usage: verify_results(%results, \$class)" unless $class;
237 while (my($code,$expected)=each %$results){
238 my $r = Math::GSL::SF::gsl_sf_result_struct->new;
239 my $status = eval qq{${class}::$code};
241 ok(0, qq{'$code' died} ) if !defined $status;
243 if ( defined $r && $code =~ /_e\(.*\$r/) {
245 $eps = $factor*$r->{err};
246 $res = abs($x-$expected);
250 print "got $code = $x\n";
251 printf "expected : %.18g\n", $expected ;
252 printf "difference : %.18g\n", $res;
253 printf "unexpected error of %.18g\n", $res-$eps if ($res-$eps>0);
256 if ($x =~ /nan|inf/i) {
257 ok( $expected eq $x, "'$expected'?='$x'" );
259 ok( $res <= $eps, "$code ?= $x,\nres= +-$res, eps=$eps" );
266 my ($results,$class) = @_;
267 croak "Usage: verify(%results, \$class)" unless $class;
268 while (my($code,$result)=each %$results){
269 my $x = eval qq{${class}::$code};
274 ($expected,$eps)=@$result;
276 ($expected,$eps)=($result,1e-8);
278 my $res = abs($x - $expected);
279 if ($x =~ /nan|inf/i ){
280 ok( $expected eq $x, "'$expected' ?='$x'" );
282 ok( $res <= $eps, "$code ?= $x,\nres= +-$res, eps=$eps" );
290 printf "result->err: %.18g\n", $r->{err};
291 printf "result->val: %.18g\n", $r->{val};