From 667e31cb46e02fdbe9d2bfbf13e600cb9f27e82e Mon Sep 17 00:00:00 2001 From: Ed J Date: Wed, 30 Oct 2024 22:59:06 +0000 Subject: [PATCH] approx_artol handle compare inf to inf - #34 --- Basic/Primitive/primitive.pd | 4 +++- Basic/t/core.t | 4 ++-- Basic/t/primitive-misc.t | 3 +++ Basic/t/tp-is_pdl.t | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Basic/Primitive/primitive.pd b/Basic/Primitive/primitive.pd index 25e29dc72..5b094c4ea 100644 --- a/Basic/Primitive/primitive.pd +++ b/Basic/Primitive/primitive.pd @@ -3586,7 +3586,9 @@ if (PDL_ISNAN_$PPSYM()($got()) || PDL_ISNAN_$PPSYM()(expctd)) { $result() = 0; c 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, diff --git a/Basic/t/core.t b/Basic/t/core.t index a03f360d4..3844e19b1 100644 --- a/Basic/t/core.t +++ b/Basic/t/core.t @@ -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"}; } { diff --git a/Basic/t/primitive-misc.t b/Basic/t/primitive-misc.t index c968b4424..c39bf7f2d 100644 --- a/Basic/t/primitive-misc.t +++ b/Basic/t/primitive-misc.t @@ -76,6 +76,9 @@ 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"; }; done_testing; diff --git a/Basic/t/tp-is_pdl.t b/Basic/t/tp-is_pdl.t index 097910f9a..88ebb5e60 100644 --- a/Basic/t/tp-is_pdl.t +++ b/Basic/t/tp-is_pdl.t @@ -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 );