[Pdl-porters] badflag dataflow with assgn

Tim Haines communist.goatboy at gmail.com
Wed Jul 11 14:51:12 HST 2012


Greetings, all.

I am not very familiar with PDL::Bad, but it looks like the badflag isn't
flowing on elemental assignment.  From the docs, "assgn does not process
bad values. It will set the bad-value flag of all output piddles if the
flag is set for any of the input piddles."

use PDL;

print 'Bad status = ', $PDL::Bad::Status, "\n";  # 'Bad status = 1'
print 'Using badval = ', double->badvalue, "\n";  # Using badval =
-1.79769313486232e+308

$a = sequence(double,10);
$b = zeroes(double,10,2);
my $mask = $a >= 6;
$b->slice(':,(1)') .= $a->setbadif($mask);
print $b, "\n", 'badflag = ', $b->badflag();

#OUTPUT
#*******************************************************************************************************************************************************
#[
# [              0               0               0
0               0               0               0
0               0               0]
# [              0               1               2
3               4               5 -1.7976931e+308 -1.7976931e+308
-1.7976931e+308 -1.7976931e+308]
#]
#
# badflag = 0


A quick inspection of PDL/Basic/Ops/ops.pd shows

# note: the extra code that adding 'HandleBad => 1' creates is
# unneeded here. Things could be made clever enough to work this out,
# but it's very low priority.
# It does add doc information though, and lets people know it's been
# looked at for bad value support
# DJB adds: not completely sure about this now that I have added code
# to avoid a valgrind-reported error (see the CacheBadFlagInit rule
# in PP.pm)
#
# Can't this be handled in Core.pm when '.=' is overloaded ?
#
pp_def(
       'assgn',
#       HandleBad => 1,
       Pars => 'a(); [o]b();',
       Code =>
       '$b() = $a();',
#       BadCode =>
#       'if ( $ISBAD(a()) ) { $SETBAD(b()); } else { $b() = $a(); }',
       Doc =>
'Plain numerical assignment. This is used to implement the ".=" operator',
); # pp_def assgn


However, PDL/Basic/Core/Core.pm.PL has

".="    => sub {
                        my @args = reverse &PDL::Core::rswap;
                        PDL::Ops::assgn(@args);
                        return $args[1];
                    },


Should we add a CopyBadStatus entry to assgn?


Many thanks.

- Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.jach.hawaii.edu/pipermail/pdl-porters/attachments/20120711/f0247150/attachment.html>


More information about the PDL-porters mailing list