Skip to content

Commit e2dbd16

Browse files
committed
remove CopyBadStatusCode key from PP
1 parent 5a1ee34 commit e2dbd16

File tree

5 files changed

+15
-74
lines changed

5 files changed

+15
-74
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- add "update_data_from" method as streamlined get_dataref/upd_data
2424
- add Ops::csqrt{,_up} (#524) - thanks @wlmb
2525
- Core::upd_data now sets DATACHANGED so will work for flowing ops
26+
- remove CopyBadStatusCode key from PP (#517)
2627

2728
2.098 2025-01-03
2829
- fix Windows build problems

lib/PDL/Bad.pd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,13 @@ EOF
820820
$GENERIC(b) a_val = $a();
821821
$b() = PDL_IF_BAD($ISBADVAR(a_val,a) ? replace : ,) a_val;
822822
%}
823+
PDL->propagate_badflag( $PDL(b), 0 ); /* always make sure the output is "good" */
823824
},
824-
CopyBadStatusCode => q{
825-
PDL->propagate_badflag( b, 0 ); /* always make sure the output is "good" */
826-
},
825+
NewXSFindBadStatusNS => <<'EOF',
826+
PDL_RETERROR(PDL_err, PDL->trans_check_pdls(__privtrans));
827+
char $BADFLAGCACHE() = PDL->trans_badflag_from_inputs(__privtrans);
828+
$BADFLAGCACHE() = 0; /* override, but still need to call the above */
829+
EOF
827830
GenericTypes => $A,
828831
);
829832

lib/PDL/BadValues.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ but it will run slower since you are going to have to handle the presence of bad
100100
If you create an ndarray, it will have its bad-value flag set to 0. To change
101101
this, use C<< $pdl->badflag($new_bad_status) >>, where C<$new_bad_status> can be 0 or 1.
102102
When a routine creates an ndarray, its bad-value flag will depend on the input
103-
ndarrays: unless over-ridden (see the C<CopyBadStatusCode> option to C<pp_def>), the
104-
bad-value flag will be set true if any of the input ndarrays contain bad values.
103+
ndarrays: the
104+
bad-value flag will be set true if any of the input ndarrays have the bad-value flag.
105105
To check that an ndarray really contains bad data, use the C<check_badflag> method.
106106

107107
I<NOTE>: propagation of the badflag

lib/PDL/PP.pm

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ sub dosubst_private {
371371
CROAK => sub {"return PDL->make_error(PDL_EUSERERROR, \"Error in $name:\" @{[join ',', @_]})"},
372372
NAME => sub {return $name},
373373
MODULE => sub {return $::PDLMOD},
374-
SETPDLSTATEBAD => sub { "$_[0]\->state |= PDL_BADVAL" },
375-
SETPDLSTATEGOOD => sub { "$_[0]\->state &= ~PDL_BADVAL" },
376-
ISPDLSTATEBAD => \&badflag_isset,
377-
ISPDLSTATEGOOD => sub {"!".badflag_isset($_[0])},
378374
BADFLAGCACHE => sub { "badflag_cache" },
379375
PDLSTATESETBAD => sub { ($sig->objs->{$_[0]}//confess "Can't get PDLSTATESETBAD for unknown ndarray '$_[0]'")->do_pdlaccess."->state |= PDL_BADVAL" },
380376
PDLSTATESETGOOD => sub { ($sig->objs->{$_[0]}->do_pdlaccess//confess "Can't get PDLSTATESETGOOD for unknown ndarray '$_[0]'")."->state &= ~PDL_BADVAL" },
@@ -1180,10 +1176,10 @@ $PDL::PP::deftbl =
11801176
PDL::PP::Rule::Returns->new("Doc", [], 'Sets the default doc string',
11811177
"\n=for ref\n\ninfo not available\n"),
11821178

1183-
PDL::PP::Rule->new("BadDoc", [qw(BadFlag Name CopyBadStatusCode?)],
1179+
PDL::PP::Rule->new("BadDoc", [qw(BadFlag Name)],
11841180
'Sets the default documentation for handling of bad values',
11851181
sub {
1186-
my ($bf, $name, $code) = @_;
1182+
my ($bf, $name) = @_;
11871183
my $str;
11881184
if ( not defined($bf) ) {
11891185
$str = "C<$name> does not process bad values.\n";
@@ -1192,14 +1188,8 @@ $PDL::PP::deftbl =
11921188
} else {
11931189
$str = "C<$name> ignores the bad-value flag of the input ndarrays.\n";
11941190
}
1195-
if ( not defined($code) ) {
1196-
$str .= "It will set the bad-value flag of all output ndarrays if " .
1197-
"the flag is set for any of the input ndarrays.\n";
1198-
} elsif ( $code eq '' ) {
1199-
$str .= "The output ndarrays will NOT have their bad-value flag set.\n";
1200-
} else {
1201-
$str .= "The state of the bad-value flag of the output ndarrays is unknown.\n";
1202-
}
1191+
$str .= "It will set the bad-value flag of all output ndarrays if " .
1192+
"the flag is set for any of the input ndarrays.\n";
12031193
}
12041194
),
12051195

@@ -1957,15 +1947,6 @@ char \$BADFLAGCACHE() = PDL->trans_badflag_from_inputs($_[0]); (void)\$BADFLAGCA
19571947
EOF
19581948
}),
19591949

1960-
PDL::PP::Rule->new("NewXSCopyBadStatusNS",
1961-
["CopyBadStatusCode"],
1962-
"Use CopyBadStatusCode if given",
1963-
sub {
1964-
my ($badcode) = @_;
1965-
confess "PDL::PP ERROR: CopyBadStatusCode contains '\$PRIV(bvalflag)'; replace with \$BADFLAGCACHE()"
1966-
if $badcode =~ m/\$PRIV(bvalflag)/;
1967-
$badcode;
1968-
}),
19691950
PDL::PP::Rule->new("NewXSCopyBadStatusNS",
19701951
["SignatureObj"],
19711952
"Rule to copy the bad value status to the output ndarrays",
@@ -1977,7 +1958,7 @@ EOF
19771958
return '' if @{$sig->names} == (my @outs = $sig->names_out); # no input pdls, no badflag copying needed
19781959
!@outs ? '' : PDL::PP::indent(2, join '', # no outs, ditto
19791960
"if (\$BADFLAGCACHE()) {\n",
1980-
(map " \$SETPDLSTATEBAD($_);\n", @outs),
1961+
(map " $_->state |= PDL_BADVAL;\n", @outs),
19811962
"}\n");
19821963
}),
19831964

lib/PDL/PP.pod

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,22 +1175,7 @@ I<TODO:> mention C<$PISBAD()> etc macros.
11751175
=head2 PDL STATE macros
11761176

11771177
If you want access to the value of the badflag for a given
1178-
ndarray, you can use the PDL STATE macros,
1179-
for use in L</CopyBadStatusCode>.
1180-
1181-
=over 4
1182-
1183-
=item $ISPDLSTATEBAD(pdl)
1184-
1185-
=item $ISPDLSTATEGOOD(pdl)
1186-
1187-
=item $SETPDLSTATEBAD(pdl)
1188-
1189-
=item $SETPDLSTATEGOOD(pdl)
1190-
1191-
=back
1192-
1193-
And for use in C<Code> sections:
1178+
ndarray, you can use the PDL STATE macros.
11941179

11951180
=over 4
11961181

@@ -1871,21 +1856,6 @@ completeness.
18711856

18721857
=back
18731858

1874-
If bad values are being used, care must be taken to ensure the
1875-
propagation of the badflag when inplace is being used;
1876-
consider this excerpt from F<lib/PDL/Bad.pd>:
1877-
1878-
pp_def('setbadtoval',
1879-
HandleBad => 1,
1880-
Pars => 'a(); [o]b();',
1881-
OtherPars => 'double newval',
1882-
Inplace => 1,
1883-
CopyBadStatusCode => 'PDL->propagate_badflag( b, 0 );',
1884-
...
1885-
1886-
Since this routine removes all bad values, the output ndarray had
1887-
its bad flag cleared. This is then propagated to both parents and children.
1888-
18891859
The documentation for the routine is now (as of 2.099)
18901860
automatically flagged to indicate that it can be executed inplace,
18911861
similar to how C<HandleBad> sets C<BadDoc> if it's not
@@ -2462,20 +2432,6 @@ section will be reused, on the assumption it will use
24622432
C<#ifdef PDL_BAD_CODE> to handle bad values.
24632433
As of 2.073, you can, and are recommended to, use C<PDL_IF_BAD(iftrue,iffalse)>.
24642434

2465-
=head3 CopyBadStatusCode
2466-
2467-
As of 2.079, this is deprecated due to being largely unnecessary;
2468-
instead, just use C<$PDLSTATESETBAD(pdlname)> in your C<Code> section
2469-
and the badflag setting will be propagated to all its parents and
2470-
children.
2471-
2472-
The default code here sets the bad flag of the output ndarrays if
2473-
C<$BADFLAGCACHE()> is true after the code has been
2474-
evaluated. Sometimes C<CopyBadStatusCode> is set to an empty string,
2475-
with the responsibility of setting the badflag of the output ndarray
2476-
left to the C<BadCode> section (e.g. the C<xxxover> routines
2477-
in F<lib/PDL/Ufunc.pd>).
2478-
24792435
=head3 GenericTypes
24802436

24812437
An array reference. The array may contain any subset of the one-character

0 commit comments

Comments
 (0)