"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Basic/Bad/bad.pd" between
PDL-2.078.tar.gz and PDL-2.079.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

bad.pd  (PDL-2.078):bad.pd  (PDL-2.079)
skipping to change at line 83 skipping to change at line 83
use PDL::Primitive; use PDL::Primitive;
############################################################ ############################################################
############################################################ ############################################################
!NO!SUBS! !NO!SUBS!
# we want the following to be in PDL, not PDL::Bad, hence # we want the following to be in PDL, not PDL::Bad, hence
my $xshdr = "MODULE = PDL::Bad PACKAGE = PDL"; my $xshdr = "MODULE = PDL::Bad PACKAGE = PDL";
#
# we want badflag() to avoid unnecessary calls to PDL->propagate_badflag(),
# since it has to recurse through all the children of an ndarray
#
pp_addxs( <<"!WITH!SUBS!"); pp_addxs( <<"!WITH!SUBS!");
$xshdr $xshdr
int int
badflag(x,newval=0) badflag(x,newval=0)
pdl *x pdl *x
int newval int newval
CODE: CODE:
if (items>1) { if (items>1)
int oldval = ((x->state & PDL_BADVAL) > 0); PDL->propagate_badflag( x, newval );
if ( !newval && oldval ) {
/* asked to unset, present value is set */
x->state &= ~PDL_BADVAL;
PDL->propagate_badflag( x, 0 );
} else if ( newval && !oldval ) {
/* asked to set, present value is unset */
x->state |= PDL_BADVAL;
PDL->propagate_badflag( x, 1 );
}
}
RETVAL = ((x->state & PDL_BADVAL) > 0); RETVAL = ((x->state & PDL_BADVAL) > 0);
OUTPUT: OUTPUT:
RETVAL RETVAL
!WITH!SUBS! !WITH!SUBS!
pp_addpm(<<'!NO!SUBS!'); pp_addpm(<<'!NO!SUBS!');
############################################################ ############################################################
############################################################ ############################################################
skipping to change at line 223 skipping to change at line 208
=for bad =for bad
This method does not care if you call it on an input ndarray This method does not care if you call it on an input ndarray
that has bad values. It always returns a Perl scalar that has bad values. It always returns a Perl scalar
with the original bad value for the associated type. with the original bad value for the associated type.
=head2 check_badflag =head2 check_badflag
=for ref =for ref
Clear the bad-value flag of an ndarray if it does not Clear the badflag of an ndarray if it does not
contain any bad values contain any bad values
Given an ndarray whose bad flag is set, check whether it Given an ndarray whose bad flag is set, check whether it
actually contains any bad values and, if not, clear the flag. actually contains any bad values and, if not, clear the flag.
It returns the final state of the bad-value flag. It returns the final state of the badflag.
=for example =for example
print "State of bad flag == ", $pdl->check_badflag; print "State of bad flag == ", $pdl->check_badflag;
=for bad =for bad
This method accepts ndarrays with or without bad values. It This method accepts ndarrays with or without bad values. It
returns an ndarray with the final bad-value. returns an ndarray with the final badflag.
=cut =cut
*check_badflag = \&PDL::check_badflag; *check_badflag = \&PDL::check_badflag;
sub PDL::check_badflag { sub PDL::check_badflag {
my $pdl = shift; my $pdl = shift;
$pdl->badflag(0) if $pdl->badflag and $pdl->nbad == 0; $pdl->badflag(0) if $pdl->badflag and $pdl->nbad == 0;
return $pdl->badflag; return $pdl->badflag;
} # sub: check_badflag() } # sub: check_badflag()
skipping to change at line 408 skipping to change at line 393
print $y, "\n"; print $y, "\n";
[0 1 0] [0 1 0]
=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() = PDL_IF_BAD($ISBAD(a()),0);', '$b() = PDL_IF_BAD($ISBAD(a()),0);',
CopyBadStatusCode => '',
GenericTypes => $A, GenericTypes => $A,
); );
pp_def('isgood' . <<'=cut', pp_def('isgood' . <<'=cut',
=head2 isgood =head2 isgood
=for sig =for sig
Signature: (a(); int [o]b()) Signature: (a(); int [o]b())
skipping to change at line 451 skipping to change at line 434
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() = PDL_IF_BAD($ISGOOD(a()),1);', '$b() = PDL_IF_BAD($ISGOOD(a()),1);',
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
=for sig =for sig
skipping to change at line 657 skipping to change at line 639
# done inplace, and the flag cleared. Hence the setbadif() # done inplace, and the flag cleared. Hence the setbadif()
# call is NOT done inplace. # call is NOT done inplace.
# #
# Don't want to play around with inplace-type code to # Don't want to play around with inplace-type code to
# try and fix this (doubt will be easy) # try and fix this (doubt will be easy)
# #
my %setbadif_extra = ( ); my %setbadif_extra = ( );
if ( 0 ) { if ( 0 ) {
## ie if fix inplace issues ## ie if fix inplace issues
$setbadif_extra{Inplace} = [ 'a' ]; $setbadif_extra{Inplace} = [ 'a' ];
$setbadif_extra{CopyBadStatusCode} =
'if ( a == b && $ISPDLSTATEGOOD(a) )
PDL->propagate_badflag( b, 1 ); /* propagate badflag if inplace */
$SETPDLSTATEBAD(b); /* always make sure the output is "bad" */
';
} else { } else {
# always make sure the output is "bad"
$setbadif_extra{CopyBadStatusCode} =
'$SETPDLSTATEBAD(b);';
} }
# always make sure the output is "bad"
# note: have made the mask be an integer # note: have made the mask be an integer
pp_def('setbadif' . <<'=cut', pp_def('setbadif' . <<'=cut',
=head2 setbadif =head2 setbadif
=for sig =for sig
Signature: (a(); int mask(); [o]b()) Signature: (a(); int mask(); [o]b())
skipping to change at line 717 skipping to change at line 692
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 the bad value == 0 then all points are going to be selected ... */ '
broadcastloop %{
/* if the bad value == 0 then all points are going to be selected ... */
if ( PDL_IF_BAD($ISBAD(mask()) ||,) $mask() ) { if ( PDL_IF_BAD($ISBAD(mask()) ||,) $mask() ) {
$SETBAD(b()); $SETBAD(b());
} else { } else {
$b() = $a(); $b() = $a();
}', }
%}
$PDLSTATESETBAD(b);
',
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
pp_def('setvaltobad' . <<'=cut', pp_def('setvaltobad' . <<'=cut',
=head2 setvaltobad =head2 setvaltobad
=for sig =for sig
skipping to change at line 762 skipping to change at line 742
The output always has its bad flag set, even if it does not contain The output always has its bad flag set, even if it does not contain
any bad values (use L</check_badflag> to check any bad values (use L</check_badflag> to check
whether there are any bad values in the output). whether there are any bad values in the output).
Any bad values in the input ndarrays are copied across to the output ndarray. Any bad values in the input ndarrays are copied across to the output ndarray.
=cut =cut
HandleBad => 1, HandleBad => 1,
Inplace => 1, Inplace => 1,
CopyBadStatusCode => q{
if ( a == b && $ISPDLSTATEGOOD(a) )
PDL->propagate_badflag( b, 1 ); /* propagate badflag if inplace */
$SETPDLSTATEBAD(b); /* always make sure the output is "bad" */
},
Code => q[ Code => q[
broadcastloop %{
if ( $a() == ($GENERIC(a)) $COMP(value) ) { if ( $a() == ($GENERIC(a)) $COMP(value) ) {
$SETBAD(b()); $SETBAD(b());
} else { } else {
$b() = $a(); $b() = $a();
} }
%}
$PDLSTATESETBAD(b);
], ],
GenericTypes => $A, GenericTypes => $A,
); # pp_def: setvaltobad ); # pp_def: setvaltobad
pp_def('setnantobad' . <<'=cut', pp_def('setnantobad' . <<'=cut',
=head2 setnantobad =head2 setnantobad
=for sig =for sig
skipping to change at line 810 skipping to change at line 788
(before version 2.040 the test was for "not finite") (before version 2.040 the test was for "not finite")
is also set to bad in the output ndarray. If all values from the input is also set to bad in the output ndarray. If all values from the input
ndarray are good, the output ndarray will B<not> have its ndarray are good, the output ndarray will B<not> have its
bad flag set. bad flag set.
=cut =cut
HandleBad => 1, HandleBad => 1,
GenericTypes => $AF, GenericTypes => $AF,
Inplace => 1, Inplace => 1,
CopyBadStatusCode => q{
/* note: not quite the normal check since set b bad within Code */
/* we propagate the bad flag even if a was originally bad since */
/* there is no easy way to pass this information around */
if ( a == b && $ISPDLSTATEBAD(b) )
PDL->propagate_badflag( b, 1 ); /* propagate badflag if inplace */
},
Code => q[ Code => q[
int flag = 0; int flag = 0;
broadcastloop %{ broadcastloop %{
if ( PDL_ISNAN_$PPSYM()($a()) ) { if ( PDL_ISNAN_$PPSYM()($a()) ) {
$SETBAD(b()); $SETBAD(b());
flag = 1; flag = 1;
} }
else { else {
$b() = $a(); $b() = $a();
} }
skipping to change at line 864 skipping to change at line 835
are propagated into the output ndarray. Any value that is not finite are propagated into the output ndarray. Any value that is not finite
is also set to bad in the output ndarray. If all values from the input is also set to bad in the output ndarray. If all values from the input
ndarray are finite, the output ndarray will B<not> have its ndarray are finite, the output ndarray will B<not> have its
bad flag set. bad flag set.
=cut =cut
HandleBad => 1, HandleBad => 1,
GenericTypes => $AF, GenericTypes => $AF,
Inplace => 1, Inplace => 1,
CopyBadStatusCode => q{
/* note: not quite the normal check since set b bad within Code */
/* we propagate the bad flag even if a was originally bad since */
/* there is no easy way to pass this information around */
if ( a == b && $ISPDLSTATEBAD(b) )
PDL->propagate_badflag( b, 1 ); /* propagate badflag if inplace */
},
Code => q[ Code => q[
int flag = 0; int flag = 0;
broadcastloop %{ broadcastloop %{
if ( !PDL_ISFINITE_$PPSYM()($a()) && !PDL_ISNAN_$PPSYM()($a()) ) { if ( !PDL_ISFINITE_$PPSYM()($a()) && !PDL_ISNAN_$PPSYM()($a()) ) {
$SETBAD(b()); $SETBAD(b());
flag = 1; flag = 1;
} }
else { else {
$b() = $a(); $b() = $a();
} }
skipping to change at line 918 skipping to change at line 882
are propagated into the output ndarray. Any value that is not finite are propagated into the output ndarray. Any value that is not finite
is also set to bad in the output ndarray. If all values from the input is also set to bad in the output ndarray. If all values from the input
ndarray are finite, the output ndarray will B<not> have its ndarray are finite, the output ndarray will B<not> have its
bad flag set. bad flag set.
=cut =cut
HandleBad => 1, HandleBad => 1,
GenericTypes => $AF, GenericTypes => $AF,
Inplace => 1, Inplace => 1,
CopyBadStatusCode => q{
/* note: not quite the normal check since set b bad within Code */
/* we propagate the bad flag even if a was originally bad since */
/* there is no easy way to pass this information around */
if ( a == b && $ISPDLSTATEBAD(b) )
PDL->propagate_badflag( b, 1 ); /* propagate badflag if inplace */
},
Code => q[ Code => q[
int flag = 0; int flag = 0;
broadcastloop %{ broadcastloop %{
if ( !PDL_ISFINITE_$PPSYM()($a()) ) { if ( !PDL_ISFINITE_$PPSYM()($a()) ) {
$SETBAD(b()); $SETBAD(b());
flag = 1; flag = 1;
} }
else { else {
$b() = $a(); $b() = $a();
} }
skipping to change at line 972 skipping to change at line 929
This method processes input ndarrays with bad values. The output ndarrays will This method processes input ndarrays with bad values. The output ndarrays will
not contain bad values (insofar as NaN is not Bad as far as PDL is concerned) not contain bad values (insofar as NaN is not Bad as far as PDL is concerned)
and the output ndarray does not have its bad flag set. As an inplace and the output ndarray does not have its bad flag set. As an inplace
operation, it clears the bad flag. operation, it clears the bad flag.
=cut =cut
HandleBad => 1, HandleBad => 1,
GenericTypes => $AF, GenericTypes => $AF,
Inplace => 1, Inplace => 1,
CopyBadStatusCode => q{
/* propagate cleared badflag if inplace */
if ( a == b ) PDL->propagate_badflag( b, 0 );
/* always make sure the output is "good" */
$SETPDLSTATEGOOD(b);
},
Code => q{ Code => q{
broadcastloop %{
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();
} }
%}
$PDLSTATESETGOOD(b);
}, },
); # pp_def: setbadtonan ); # pp_def: setbadtonan
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
Replace any bad values by a (non-bad) value. Replace any bad values by a (non-bad) value.
Can be done inplace. Also see Can be done inplace. Also see
L<badmask|PDL::Math/badmask>. L</badmask>.
=for example =for example
$x->inplace->setbadtoval(23); $x->inplace->setbadtoval(23);
print "a badflag: ", $x->badflag, "\n"; print "a badflag: ", $x->badflag, "\n";
a badflag: 0 a badflag: 0
=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 => q{ Code => q{
$GENERIC(b) a_val; $GENERIC(b) a_val;
$GENERIC(b) replace = ($GENERIC(b)) $COMP(newval); $GENERIC(b) replace = ($GENERIC(b)) $COMP(newval);
broadcastloop %{ broadcastloop %{
a_val = $a(); a_val = $a();
PDL_IF_BAD(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 */ PDL->propagate_badflag( b, 0 ); /* always make sure the output is "good"
if ( a == b && $ISPDLSTATEBAD(a) ) PDL->propagate_badflag( b, 0 ); */
/* always make sure the output is "good" */
$SETPDLSTATEGOOD(b);
}, },
GenericTypes => $A, GenericTypes => $A,
); # pp_def: setbadtoval ); # pp_def: setbadtoval
pp_def(
'badmask',
Pars => 'a(); b(); [o]c();',
Inplace => [ 'a' ],
HandleBad => 1,
Code => '
broadcastloop %{
$c() = ( isfinite((double) $a()) PDL_IF_BAD(&& $ISGOOD(a()),) ) ? $a() :
$b();
%}
$PDLSTATESETGOOD(c);
',
Doc =>
'=for ref
Clears all C<infs> and C<nans> in C<$a> to the corresponding value in C<$b>.
badmask can be run with C<$x> inplace:
badmask($x->inplace,0);
$x->inplace->badmask(0);
',
BadDoc =>
'If bad values are present, these are also cleared.',
);
pp_def('copybad'.<<'=cut', pp_def('copybad'.<<'=cut',
=head2 copybad =head2 copybad
=for sig =for sig
Signature: (a(); mask(); [o]b()) Signature: (a(); mask(); [o]b())
=for ref =for ref
skipping to change at line 1081 skipping to change at line 1055
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 => q{ Code => q{
char anybad = 0;
broadcastloop %{
PDL_IF_BAD(if ( $ISBAD(mask()) ) { PDL_IF_BAD(if ( $ISBAD(mask()) ) {
$SETBAD(b()); $SETBAD(b());
anybad = 1;
} else,) { } else,) {
$b() = $a(); $b() = $a();
} }
}, %}
CopyBadStatusCode => q{ if (anybad) $PDLSTATESETBAD(b);
if ( $BADFLAGCACHE() ) {
if ( a == b && $ISPDLSTATEGOOD(a) ) {
/* have inplace op AND badflag has changed */
PDL->propagate_badflag( b, 1 );
}
$SETPDLSTATEBAD(b);
}
}, },
GenericTypes => $A, GenericTypes => $A,
); # pp_def: copybad ); # pp_def: copybad
pp_def('locf', pp_def('locf',
Pars => 'a(n); [o]b(n);', Pars => 'a(n); [o]b(n);',
HandleBad => 1, HandleBad => 1,
GenericTypes => $A, GenericTypes => $A,
Doc => <<'EOF', Doc => <<'EOF',
=for ref =for ref
 End of changes. 30 change blocks. 
81 lines changed or deleted 53 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)