PDL::Bad#
Bad values: PDL’s marker for missing data, and the functions that find, make and replace them.
use PDL;
my $x = pdl(1, 2, -1, 4);
$x->inplace->setvaltobad(-1);
print "$x ", $x->nbad, " ", $x->ngood, " ", $x->badflag, "\n"; # [1 2 BAD 4] 1 3 1
print isbad($x), " ", $x->setbadtoval(0), " ", locf($x), "\n"; # [0 0 1 0] [1 2 0 4] [1 2 2 4]
print $x->sum, " ", $x->avg, "\n"; # 7 2.33333333333333
print setbadif(pdl(1, 2, 3), pdl(0, 1, 0)), " ", pdl(1, 9**9**9)->setinftobad, "\n"; # [1 BAD 3] [1 BAD]
An element is bad when it holds its type’s bad value and the ndarray’s bad flag is set (badflag). Operations skip bad elements - sum and avg above count the three good ones - and a result computed from a bad element is bad. Each type has a default bad value, which an ndarray can override for itself: badvalue reads or sets either, called on an ndarray or on a type, and orig_badvalue gives a type’s built-in default. Floating-point types can use NaN instead. nbad and ngood count, check_badflag clears the flag of an ndarray that has no bad element left.
This is PDL::Bad of PDL 2.106. The kernels are PDL’s own, through pperl’s engine; badvalue, orig_badvalue, check_badflag, nbad, ngood and setbadat (one element made bad, by position) are upstream’s Perl unchanged.