Skip to content

Commit

Permalink
Add propagation of badflag with .= (Ops::assgn) for sf.net bug 3543056.
Browse files Browse the repository at this point in the history
This is a start for testing of the issue at <https://sourceforge.net/p/pdl/bugs/308/>, <#29>.
  • Loading branch information
Tim Haines authored and zmughal committed Mar 3, 2015
1 parent 79bc72e commit 6f8d393
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
18 changes: 15 additions & 3 deletions Basic/Ops/ops.pd
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,26 @@ sub PDL::log10 {
#
pp_def(
'assgn',
# HandleBad => 1,
HandleBad => 1,
Pars => 'a(); [o]b();',
Code =>
'$b() = $a();',
# BadCode =>
# 'if ( $ISBAD(a()) ) { $SETBAD(b()); } else { $b() = $a(); }',
BadCode =>
'if ( $ISBAD(a()) ) { $SETBAD(b()); } else { $b() = $a(); }',
Doc =>
'Plain numerical assignment. This is used to implement the ".=" operator',
BadDoc =>
'If C<a> is a child piddle (e.g., the result of a slice) and bad values are generated in C<b>,
the bad value flag is set in C<b>, but it is B<NOT> automatically propagated back to the parent of C<a>.
The following idiom ensures that the badflag is propagated back to the parent of C<a>:

$pdl->slice(":,(1)") .= PDL::Bad_aware_func();
$pdl->badflag(1);
$pdl->check_badflag();

This is unnecessary if $pdl->badflag is known to be 1 before the slice is performed.

See http://pdl.perl.org/PDLdocs/BadValues.html#dataflow_of_the_badflag for details.'
); # pp_def assgn

#pp_export_nothing();
Expand Down
20 changes: 19 additions & 1 deletion t/ops.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use Test::More tests => 44;
use Test::More tests => 45;
use PDL::LiteF;
use PDL::Config;
kill INT,$$ if $ENV{UNDER_DEBUGGER}; # Useful for debugging.

sub tapprox {
Expand Down Expand Up @@ -148,3 +149,20 @@ $b = $a->qsorti;
$c = $b % 3;
ok(all($c->double==pdl("0 1 2 " x 5)));
ok(longlong(10)%longlong(5)==0);

TODO: {
# Check badflag propagation with .= (Ops::assgn) sf.net bug 3543056
local $TODO = "Badflag needs to propagate via assignment";
todo_skip 'No BADVAL', 1 if !$PDL::Config{WITH_BADVAL};

$a = sequence(10);
$b = sequence(5);
$b->inplace->setvaltobad(3);
$a->slice('0:4') .= $b;
# NOTE TODO
# if you set the badflag manually, this will work, but to Do The Right
# Thing, this should be automatic:
# $a->badflag(1);
# $a->check_badflag();
ok($a->badflag == 1 && $a->nbad == 1);
}

0 comments on commit 6f8d393

Please sign in to comment.