Skip to content

Commit

Permalink
strict, warnings, Test::More in test
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 2, 2022
1 parent 43d00fc commit f4f0c95
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ WriteMakefile(
'PDL' => '2.063',
'PDL::LinearAlgebra' => 0,
},
TEST_REQUIRES => { "Test::More" => '0.88' },
META_MERGE => {
"meta-spec" => { version => 2 },
resources => {
Expand Down
57 changes: 30 additions & 27 deletions t/1.t
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#!/usr/bin/perl
use strict;
use warnings;
use PDL::LiteF;
use PDL::Opt::NonLinear;
use Test;
use Test::More;

BEGIN { plan tests => 2 };

sub fapprox {
my($a,$b) = @_;
PDL::abs($a-$b)->max < 0.0001;
sub approx_ok {
my($got,$expected,$label) = @_;
if (PDL::abs($got-$expected)->max < 0.0001) {
pass $label;
} else {
fail $label;
diag "got=$got\nexpected=$expected\n";
}
}

$res = pdl([1,1,1,1,1]);



$x = random(5);
my $res = ones(5);
my $x = random(5);

$gx = rosen_grad($x);
$hx = rosen_hess($x);
$fx = rosen($x);
$xtol = pdl(1e-16);
$gtol = pdl(1e-8);
my $gx = rosen_grad($x);
my $hx = rosen_hess($x);
my $fx = rosen($x);
my $xtol = pdl(1e-16);
my $gtol = pdl(1e-8);
#$stepmx = pdl(0.5);
$maxit = pdl(long, 50);
my $maxit = pdl(long, 50);
sub min_func{
my ($fx, $x) = @_;
$fx .= rosen($x);
Expand All @@ -40,22 +41,22 @@ tensoropt($fx, $gx, $hx, $x,
ones(5),0.5,$xtol,$gtol,2,6,
\&min_func, \&grad_func, \&hess_func);

ok(fapprox($x,$res));
approx_ok $x,$res,'tensoropt';

$x = random(5);
$gx = rosen_grad($x);
$fx = rosen($x);
$diag = zeroes(5);
my $diag = zeroes(5);

$xtol = pdl(1e-16);
$gtol = pdl(0.9);
$eps = pdl(1e-10);
$print = ones(2);
$maxfc = pdl(long,100);
my $eps = pdl(1e-10);
my $print = ones(2);
my $maxfc = pdl(long,100);
$maxit = pdl(long,50);
$info = pdl(long,0);
$diagco= pdl(long,0);
$m = pdl(long,10);
my $info = pdl(long,0);
my $diagco= pdl(long,0);
my $m = pdl(long,10);

sub fdiag{};
sub fg_func{
Expand All @@ -66,4 +67,6 @@ sub fg_func{
}
lbfgs($fx, $gx, $x, $diag, $diagco, $m, $maxit, $maxfc, $eps, $xtol, $gtol,
$print,$info,\&fg_func,\&fdiag);
ok(fapprox($x,$res));
approx_ok $x,$res,'lbfgs';

done_testing;

0 comments on commit f4f0c95

Please sign in to comment.