Skip to content

Commit

Permalink
approx_artol handle compare inf to inf - #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 30, 2024
1 parent 8ba0b86 commit cefdd46
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions Basic/Primitive/primitive.pd
Original file line number Diff line number Diff line change
Expand Up @@ -3587,6 +3587,7 @@ PDL_IF_BAD(
if ((got_badflag && $ISBAD(got())) && (exp_badflag && $ISBADVAR(expctd,expected))) { $result() = 1; continue; }
if ((got_badflag && $ISBAD(got())) || (exp_badflag && $ISBADVAR(expctd,expected))) { $result() = 0; continue; }
,)
if ($got() == expctd) { $result() = 1; continue; }
$GENERIC() diff = $got() - expctd;
double abs_diff2 = PDL_IF_GENTYPE_REAL(
diff * diff,
Expand Down
4 changes: 2 additions & 2 deletions Basic/t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ is_pdl pdl([1], pdl[2,3,4], pdl[5]), pdl([[[1,0,0],[0,0,0]],[[2,3,4],[5,0,0]]]),
is_pdl $c, pdl([1,0,0],[2,3,4]), "implicit, undefval of undef falls back to 0";
$PDL::undefval = inf;
$c = pdl undef;
ok all($c == inf), "explicit, undefval of PDL scalar works" or diag("c=$c\n");
is_pdl $c, inf, "explicit, undefval of PDL scalar works";
$c = pdl [1], [2,3,4];
ok all($c == pdl([1,inf,inf],[2,3,4])), "implicit, undefval of a PDL scalar works" or diag("c=$c\n");
is_pdl $c, pdl([1,inf,inf],[2,3,4]), {rtol=>0, test_name=>"implicit, undefval of a PDL scalar works"};
}

{
Expand Down
6 changes: 6 additions & 0 deletions Basic/t/primitive-misc.t
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ subtest approx_artol => sub {
$got_a = $fgot->approx_artol($fexpected, 1e-6);
$exp_a_mask = pdl('1 1 1 0 0 1');
ok all($got_a == $exp_a_mask), 'bad values pattern' or diag "got=$got_a\nexp=$exp_a_mask";
$got_a = inf(1)->approx_artol(inf(1));
$exp_a_mask = pdl([1]);
ok all($got_a == $exp_a_mask), 'inf matches inf' or diag "got=$got_a\nexp=$exp_a_mask";
$got_a = pdl('inf bad')->approx_artol(pdl('inf bad'));
$exp_a_mask = pdl([1,1]);
ok all($got_a == $exp_a_mask), 'inf,bad matches inf,bad' or diag "got=$got_a\nexp=$exp_a_mask";
};

done_testing;
2 changes: 2 additions & 0 deletions Basic/t/tp-is_pdl.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ test_test( 'custom test name is also displayed correctly when supplied as an opt
# error is raised.
throws_ok { is_pdl( $got, $expected, pdl(1,1,1,1) ) }
qr/^error in arguments: third argument is an ndarray at /, 'third argument is an ndarray';
throws_ok { is_pdl( $got, $expected, 1e-4, "label" ) }
qr/^error in arguments: > 3 given/, '>3 argument given';

$expected = long( 4,5,6,7,8,9 );
$expected->badflag( 1 );
Expand Down

0 comments on commit cefdd46

Please sign in to comment.