bad.pd (PDL-2.077) | : | bad.pd (PDL-2.078) | ||
---|---|---|---|---|
skipping to change at line 411 | skipping to change at line 411 | |||
=for bad | =for bad | |||
This method works with input ndarrays that are bad. The output ndarray | This method works with input ndarrays that are bad. The output ndarray | |||
will never contain bad values, but its bad value flag will be the | will never contain bad values, but its bad value flag will be the | |||
same as the input ndarray's flag. | same as the input ndarray's flag. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
Code => | Code => | |||
'$b() = 0;', | '$b() = PDL_IF_BAD($ISBAD(a()),0);', | |||
BadCode => | ||||
'$b() = $ISBAD(a());', | ||||
CopyBadStatusCode => '', | CopyBadStatusCode => '', | |||
GenericTypes => $A, | GenericTypes => $A, | |||
); | ); | |||
pp_def('isgood' . <<'=cut', | pp_def('isgood' . <<'=cut', | |||
=head2 isgood | =head2 isgood | |||
=for sig | =for sig | |||
skipping to change at line 452 | skipping to change at line 450 | |||
=for bad | =for bad | |||
This method works with input ndarrays that are bad. The output ndarray | This method works with input ndarrays that are bad. The output ndarray | |||
will never contain bad values, but its bad value flag will be the | will never contain bad values, but its bad value flag will be the | |||
same as the input ndarray's flag. | same as the input ndarray's flag. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
Code => | Code => | |||
'$b() = 1;', | '$b() = PDL_IF_BAD($ISGOOD(a()),1);', | |||
BadCode => | ||||
'$b() = $ISGOOD(a());', | ||||
CopyBadStatusCode => '', | CopyBadStatusCode => '', | |||
GenericTypes => $A, | GenericTypes => $A, | |||
); | ); | |||
# perhaps these should have pm code which returns the | # perhaps these should have pm code which returns the | |||
# answer if the bad flag is not set | # answer if the bad flag is not set | |||
pp_def('nbadover' . <<'=cut', | pp_def('nbadover' . <<'=cut', | |||
=head2 nbadover | =head2 nbadover | |||
skipping to change at line 496 | skipping to change at line 492 | |||
=for bad | =for bad | |||
nbadover processes input values that are bad. The output ndarray will not have | nbadover processes input values that are bad. The output ndarray will not have | |||
any bad values, but the bad flag will be set if the input ndarray had its bad | any bad values, but the bad flag will be set if the input ndarray had its bad | |||
flag set. | flag set. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
Code => '$b() = 0;', | Code => q{ | |||
BadCode => q{ | ||||
PDL_Indx cnt = 0; | PDL_Indx cnt = 0; | |||
loop(n) %{ | PDL_IF_BAD(loop(n) %{ | |||
if ( $ISBAD(a()) ) { cnt++; } | if ( $ISBAD(a()) ) { cnt++; } | |||
%} | %},) | |||
$b() = cnt; | $b() = cnt; | |||
}, | }, | |||
GenericTypes => $A, | GenericTypes => $A, | |||
); | ); | |||
pp_def('ngoodover' . <<'=cut', | pp_def('ngoodover' . <<'=cut', | |||
=head2 ngoodover | =head2 ngoodover | |||
=for sig | =for sig | |||
skipping to change at line 541 | skipping to change at line 536 | |||
$spectrum = ngoodover $image->transpose | $spectrum = ngoodover $image->transpose | |||
=for bad | =for bad | |||
ngoodover processes input values that are bad. The output ndarray will not have | ngoodover processes input values that are bad. The output ndarray will not have | |||
any bad values, but the bad flag will be set if the input ndarray had its bad | any bad values, but the bad flag will be set if the input ndarray had its bad | |||
flag set. | flag set. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
Code => | Code => | |||
'$b() = (PDL_Indx) $SIZE(n);', | 'PDL_Indx cnt = PDL_IF_BAD(0,$SIZE(n)); | |||
BadCode => | PDL_IF_BAD(loop(n) %{ | |||
'PDL_Indx cnt = 0; | ||||
loop(n) %{ | ||||
if ( $ISGOOD(a()) ) { cnt++; } | if ( $ISGOOD(a()) ) { cnt++; } | |||
%} | %},) | |||
$b() = cnt;', | $b() = cnt;', | |||
GenericTypes => $A, | GenericTypes => $A, | |||
); | ); | |||
# Generate small ops functions to do entire array | # Generate small ops functions to do entire array | |||
foreach my $op ( | foreach my $op ( | |||
['nbad','nbadover'], | ['nbad','nbadover'], | |||
['ngood','ngoodover'], | ['ngood','ngoodover'], | |||
) { | ) { | |||
pp_addpm(<<"EOD"); | pp_addpm(<<"EOD"); | |||
skipping to change at line 725 | skipping to change at line 717 | |||
The input ndarray can have bad values: any bad values in the input ndarrays | The input ndarray can have bad values: any bad values in the input ndarrays | |||
are copied across to the output ndarray. | are copied across to the output ndarray. | |||
Also see L</setvaltobad> and L</setnantobad>. | Also see L</setvaltobad> and L</setnantobad>. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
%setbadif_extra, | %setbadif_extra, | |||
Code => | Code => | |||
'if ( $mask() ) { | ||||
$SETBAD(b()); | ||||
} else { | ||||
$b() = $a(); | ||||
}', | ||||
BadCode => | ||||
'/* if the bad value == 0 then all points are going to be selected ... */ | '/* if the bad value == 0 then all points are going to be selected ... */ | |||
if ( $ISBAD(mask()) || $mask() ) { | if ( PDL_IF_BAD($ISBAD(mask()) ||,) $mask() ) { | |||
$SETBAD(b()); | $SETBAD(b()); | |||
} else { | } else { | |||
$b() = $a(); | $b() = $a(); | |||
}', | }', | |||
GenericTypes => $A, | GenericTypes => $A, | |||
); # pp_def: setbadif | ); # pp_def: setbadif | |||
# this is useful because $x->setbadif( $x == 23 ) | # this is useful because $x->setbadif( $x == 23 ) | |||
# is common and that can't be done inplace | # is common and that can't be done inplace | |||
# | ||||
# this doesn't need a BadCode section | ||||
pp_def('setvaltobad' . <<'=cut', | pp_def('setvaltobad' . <<'=cut', | |||
=head2 setvaltobad | =head2 setvaltobad | |||
=for sig | =for sig | |||
Signature: (a(); [o]b(); double value) | Signature: (a(); [o]b(); double value) | |||
=for ref | =for ref | |||
skipping to change at line 1005 | skipping to change at line 988 | |||
Code => q{ | Code => q{ | |||
if ( $ISBAD(a()) ) { | if ( $ISBAD(a()) ) { | |||
$b() = $TFDEGCH(NAN,NAN,NAN,NAN+I*NAN,NAN+I*NAN,NAN+I*NAN); | $b() = $TFDEGCH(NAN,NAN,NAN,NAN+I*NAN,NAN+I*NAN,NAN+I*NAN); | |||
} | } | |||
else { | else { | |||
$b() = $a(); | $b() = $a(); | |||
} | } | |||
}, | }, | |||
); # pp_def: setbadtonan | ); # pp_def: setbadtonan | |||
# renamed replacebad by setbadtoval | ||||
pp_def('setbadtoval' . <<'=cut', | pp_def('setbadtoval' . <<'=cut', | |||
=head2 setbadtoval | =head2 setbadtoval | |||
=for sig | =for sig | |||
Signature: (a(); [o]b(); double newval) | Signature: (a(); [o]b(); double newval) | |||
=for ref | =for ref | |||
skipping to change at line 1037 | skipping to change at line 1019 | |||
=for bad | =for bad | |||
The output always has its bad flag cleared. | The output always has its bad flag cleared. | |||
If the input ndarray does not have its bad flag set, then | If the input ndarray does not have its bad flag set, then | |||
values are copied with no replacement. | values are copied with no replacement. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
Inplace => 1, | Inplace => 1, | |||
Code => '$b() = $a();', | Code => q{ | |||
BadCode => q{ | ||||
$GENERIC(b) replace = ($GENERIC(b)) $COMP(newval); | ||||
$GENERIC(b) a_val; | $GENERIC(b) a_val; | |||
$GENERIC(b) replace = ($GENERIC(b)) $COMP(newval); | ||||
broadcastloop %{ | broadcastloop %{ | |||
a_val = $a(); | a_val = $a(); | |||
if ( $ISBADVAR(a_val,a) ) { | PDL_IF_BAD(if ( $ISBADVAR(a_val,a) ) { | |||
$b() = replace; | $b() = replace; | |||
} else { | } else,) { | |||
$b() = a_val; | $b() = a_val; | |||
} | } | |||
%} | %} | |||
}, | }, | |||
CopyBadStatusCode => q{ | CopyBadStatusCode => q{ | |||
/* propagate badflag if inplace AND its changed */ | /* propagate badflag if inplace AND its changed */ | |||
if ( a == b && $ISPDLSTATEBAD(a) ) PDL->propagate_badflag( b, 0 ); | if ( a == b && $ISPDLSTATEBAD(a) ) PDL->propagate_badflag( b, 0 ); | |||
/* always make sure the output is "good" */ | /* always make sure the output is "good" */ | |||
$SETPDLSTATEGOOD(b); | $SETPDLSTATEGOOD(b); | |||
}, | }, | |||
GenericTypes => $A, | GenericTypes => $A, | |||
); # pp_def: setbadtoval | ); # pp_def: setbadtoval | |||
skipping to change at line 1099 | skipping to change at line 1080 | |||
This handles input ndarrays that are bad. If either C<$x> | This handles input ndarrays that are bad. If either C<$x> | |||
or C<$mask> have bad values, those values will be marked | or C<$mask> have bad values, those values will be marked | |||
as bad in the output ndarray and the output ndarray will have | as bad in the output ndarray and the output ndarray will have | |||
its bad value flag set to true. | its bad value flag set to true. | |||
=cut | =cut | |||
HandleBad => 1, | HandleBad => 1, | |||
Inplace => [ 'a' ], | Inplace => [ 'a' ], | |||
Code => '$b() = $a();', | Code => q{ | |||
BadCode => q{ | PDL_IF_BAD(if ( $ISBAD(mask()) ) { | |||
if ( $ISBAD(mask()) ) { | ||||
$SETBAD(b()); | $SETBAD(b()); | |||
} else { | } else,) { | |||
$b() = $a(); | $b() = $a(); | |||
} | } | |||
}, | }, | |||
CopyBadStatusCode => q{ | CopyBadStatusCode => q{ | |||
if ( $BADFLAGCACHE() ) { | if ( $BADFLAGCACHE() ) { | |||
if ( a == b && $ISPDLSTATEGOOD(a) ) { | if ( a == b && $ISPDLSTATEGOOD(a) ) { | |||
/* have inplace op AND badflag has changed */ | /* have inplace op AND badflag has changed */ | |||
PDL->propagate_badflag( b, 1 ); | PDL->propagate_badflag( b, 1 ); | |||
} | } | |||
$SETPDLSTATEBAD(b); | $SETPDLSTATEBAD(b); | |||
End of changes. 19 change blocks. | ||||
37 lines changed or deleted | 17 lines changed or added |