1 2# Test Script for the PDL interface to the GSL library 3# This tests mainly that the interface is working, i.e. that the 4# functions can be called. 5# The GSL library already has a extensive test suite, and we 6# do not want to duplicate that effort here. 7 8use PDL; 9use Test::More; 10 11BEGIN 12{ 13 use PDL::Config; 14 if ( $PDL::Config{WITH_GSL} ) { 15 eval " use PDL::GSL::MROOT; "; 16 unless ($@) { 17 ## plan tests => 2; 18 plan skip_all => "PDL::GSL::MROOT doesn't work with PDL_Index, yet"; 19 } else { 20 plan skip_all => "PDL::GSL::MROOT not installed"; 21 } 22 } else { 23 plan skip_all => "PDL::GSL::MROOT not compiled."; 24 } 25} 26 27my $init = pdl (-10.00, -5.0); 28my $epsabs = 1e-7; 29 30$res = gslmroot_fsolver($init, \&rosenbrock,{Method => 0, EpsAbs => $epsabs}); 31 32my @res = list ($res); 33 34ok(abs($res[0]- 1) < 1e-6 ); 35ok(abs($res[1]- 1) < 1e-6 ); 36 37 38sub rosenbrock{ 39 my ($x) = @_; 40 my $a = 1; 41 my $b = 10; 42 my $y = zeroes($x); 43 my $tmp; # work around perl -d "feature" 44 ($tmp = $y->slice(0)) .= $a * (1 - $x->slice(0)); 45 ($tmp = $y->slice(1)) .= $b * ($x->slice(1) - $x->slice(0)**2); 46 return $y; 47} 48