| 1 | # | ||
| 2 | # GENERATED WITH PDL::PP from lib/PDL/Bad.pd! Don't modify! | ||
| 3 | # | ||
| 4 | package PDL::Bad; | ||
| 5 | |||
| 6 | 71 | our @EXPORT_OK = qw(badflag check_badflag badvalue orig_badvalue nbad nbadover ngood ngoodover setbadat isbad isnan isgood nbadover ngoodover setbadif setvaltobad setnantobad setinftobad setnonfinitetobad setbadtonan setbadtoval badmask copybad locf ); | |
| 7 | 71 | our %EXPORT_TAGS = (Func=>\@EXPORT_OK); | |
| 8 | |||
| 9 | 71 | ▶ | use PDL::Core; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 71 | ▶ | use PDL::Exporter; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 71 | ▶ | use DynaLoader; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | 71 | our @ISA = ( 'PDL::Exporter','DynaLoader' ); | |
| 16 | 71 | push @PDL::Core::PP, __PACKAGE__; | |
| 17 | 71 | bootstrap PDL::Bad ; | |
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | #line 20 "lib/PDL/Bad.pd" | ||
| 27 | |||
| 28 | =head1 NAME | ||
| 29 | |||
| 30 | PDL::Bad - PDL always processes bad values | ||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | This module is loaded when you do C<use PDL>, | ||
| 35 | C<use PDL::Lite> or C<use PDL::LiteF>. | ||
| 36 | |||
| 37 | Implementation details are given in | ||
| 38 | L<PDL::BadValues>. | ||
| 39 | |||
| 40 | =head1 SYNOPSIS | ||
| 41 | |||
| 42 | use PDL::Bad; | ||
| 43 | print "\nBad value per PDL support in PDL is turned " . | ||
| 44 | $PDL::Bad::PerPdl ? "on" : "off" . ".\n"; | ||
| 45 | |||
| 46 | =head1 VARIABLES | ||
| 47 | |||
| 48 | =over 4 | ||
| 49 | |||
| 50 | =item $PDL::Bad::UseNaN | ||
| 51 | |||
| 52 | Set to 0 as of PDL 2.040, as no longer available, though NaN can be used | ||
| 53 | as a badvalue for a given PDL object. | ||
| 54 | |||
| 55 | =item $PDL::Bad::PerPdl | ||
| 56 | |||
| 57 | Set to 1 as of PDL 2.040 as always available. | ||
| 58 | |||
| 59 | =item $PDL::Bad::Status | ||
| 60 | |||
| 61 | Set to 1 as of PDL 2.035 as always available. | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =cut | ||
| 66 | #line 67 "lib/PDL/Bad.pm" | ||
| 67 | |||
| 68 | |||
| 69 | =head1 FUNCTIONS | ||
| 70 | |||
| 71 | =cut | ||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | #line 63 "lib/PDL/Bad.pd" | ||
| 78 | |||
| 79 | $PDL::Bad::Status = 1; | ||
| 80 | $PDL::Bad::UseNaN = 0; | ||
| 81 | $PDL::Bad::PerPdl = 1; | ||
| 82 | |||
| 83 | use strict; | ||
| 84 | |||
| 85 | use PDL::Types; | ||
| 86 | use PDL::Primitive; | ||
| 87 | |||
| 88 | ############################################################ | ||
| 89 | ############################################################ | ||
| 90 | |||
| 91 | #line 79 "lib/PDL/Bad.pd" | ||
| 92 | ############################################################ | ||
| 93 | ############################################################ | ||
| 94 | |||
| 95 | *badflag = \&PDL::badflag; | ||
| 96 | *badvalue = \&PDL::badvalue; | ||
| 97 | *orig_badvalue = \&PDL::orig_badvalue; | ||
| 98 | |||
| 99 | ############################################################ | ||
| 100 | ############################################################ | ||
| 101 | |||
| 102 | =head2 badflag | ||
| 103 | |||
| 104 | =for ref | ||
| 105 | |||
| 106 | getter/setter for the bad data flag | ||
| 107 | |||
| 108 | =for example | ||
| 109 | |||
| 110 | if ( $x->badflag() ) { | ||
| 111 | print "Data may contain bad values.\n"; | ||
| 112 | } | ||
| 113 | $x->badflag(1); # set bad data flag | ||
| 114 | $x->badflag(0); # unset bad data flag | ||
| 115 | |||
| 116 | When called as a setter, this modifies the ndarray on which | ||
| 117 | it is called. This always returns a Perl scalar with the | ||
| 118 | final value of the bad flag. | ||
| 119 | |||
| 120 | A return value of 1 does not guarantee the presence of | ||
| 121 | bad data in an ndarray; all it does is say that we need to | ||
| 122 | I<check> for the presence of such beasties. To actually | ||
| 123 | find out if there are any bad values present in an ndarray, | ||
| 124 | use the L</check_badflag> method. | ||
| 125 | |||
| 126 | =for bad | ||
| 127 | |||
| 128 | This function works with ndarrays that have bad values. It | ||
| 129 | always returns a Perl scalar, so it never returns bad values. | ||
| 130 | |||
| 131 | =head2 badvalue | ||
| 132 | |||
| 133 | =for ref | ||
| 134 | |||
| 135 | returns (or sets) the value used to indicate a missing (or bad) element | ||
| 136 | for the given ndarray type. You can give it an ndarray, | ||
| 137 | a PDL::Type object, or one of C<$PDL_B>, C<$PDL_S>, etc. | ||
| 138 | |||
| 139 | =for example | ||
| 140 | |||
| 141 | $badval = badvalue( float ); | ||
| 142 | $x = ones(ushort,10); | ||
| 143 | print "The bad data value for ushort is: ", | ||
| 144 | $x->badvalue(), "\n"; | ||
| 145 | |||
| 146 | This can act as a setter (e.g. C<< $x->badvalue(23) >>), | ||
| 147 | including with the value C<NaN> for floating-point types. | ||
| 148 | Note that this B<doesn't change the data in the ndarray> for | ||
| 149 | floating-point-typed ndarrays. | ||
| 150 | That is, if C<$x> already has bad values, they will not | ||
| 151 | be changed to use the given number and if any elements of | ||
| 152 | C<$x> have that value, they will unceremoniously be marked | ||
| 153 | as bad data. See L</setvaltobad>, L</setbadtoval>, and | ||
| 154 | L</setbadif> for ways to actually modify the data in ndarrays | ||
| 155 | |||
| 156 | It I<does> change data for integer-typed arrays, changing values that | ||
| 157 | had the old bad value to have the new one. | ||
| 158 | |||
| 159 | It is possible to change the bad value on a per-ndarray basis, so | ||
| 160 | |||
| 161 | $x = sequence (10); | ||
| 162 | $x->badvalue (3); $x->badflag (1); | ||
| 163 | $y = sequence (10); | ||
| 164 | $y->badvalue (4); $y->badflag (1); | ||
| 165 | |||
| 166 | will set $x to be C<[0 1 2 BAD 4 5 6 7 8 9]> and $y to be | ||
| 167 | C<[0 1 2 3 BAD 5 6 7 8 9]>. | ||
| 168 | |||
| 169 | =for bad | ||
| 170 | |||
| 171 | This method does not care if you call it on an input ndarray | ||
| 172 | that has bad values. It always returns an ndarray | ||
| 173 | with the current or new bad value. | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | sub PDL::badvalue { | ||
| 178 | my ( $self, $val ) = @_; | ||
| 179 | my $num; | ||
| 180 | if ( UNIVERSAL::isa($self,"PDL") ) { | ||
| 181 | $num = $self->get_datatype; | ||
| 182 | if ( $num < $PDL_F && defined($val) && $self->badflag ) { | ||
| 183 | $self->inplace->setbadtoval( $val ); | ||
| 184 | $self->badflag(1); | ||
| 185 | } | ||
| 186 | return PDL::Bad::_badvalue_per_pdl_int($self, $val, $num); | ||
| 187 | } elsif ( UNIVERSAL::isa($self,"PDL::Type") ) { | ||
| 188 | $num = $self->enum; | ||
| 189 | } else { | ||
| 190 | # assume it's a number | ||
| 191 | $num = $self; | ||
| 192 | } | ||
| 193 | PDL::Bad::_badvalue_int( $val, $num ); | ||
| 194 | } | ||
| 195 | |||
| 196 | =head2 orig_badvalue | ||
| 197 | |||
| 198 | =for ref | ||
| 199 | |||
| 200 | returns the original value used to represent bad values for | ||
| 201 | a given type. | ||
| 202 | |||
| 203 | This routine operates the same as L</badvalue>, | ||
| 204 | except you can not change the values. | ||
| 205 | |||
| 206 | It also has an I<awful> name. | ||
| 207 | |||
| 208 | =for example | ||
| 209 | |||
| 210 | $orig_badval = orig_badvalue( float ); | ||
| 211 | $x = ones(ushort,10); | ||
| 212 | print "The original bad data value for ushort is: ", | ||
| 213 | $x->orig_badvalue(), "\n"; | ||
| 214 | |||
| 215 | =for bad | ||
| 216 | |||
| 217 | This method does not care if you call it on an input ndarray | ||
| 218 | that has bad values. It always returns an ndarray | ||
| 219 | with the original bad value for the associated type. | ||
| 220 | |||
| 221 | =cut | ||
| 222 | |||
| 223 | sub PDL::orig_badvalue { | ||
| 224 | no strict 'refs'; | ||
| 225 | my $self = shift; | ||
| 226 | my $num; | ||
| 227 | if ( UNIVERSAL::isa($self,"PDL") ) { | ||
| 228 | $num = $self->get_datatype; | ||
| 229 | } elsif ( UNIVERSAL::isa($self,"PDL::Type") ) { | ||
| 230 | $num = $self->enum; | ||
| 231 | } else { | ||
| 232 | # assume it's a number | ||
| 233 | $num = $self; | ||
| 234 | } | ||
| 235 | PDL::Bad::_default_badvalue_int($num); | ||
| 236 | } | ||
| 237 | |||
| 238 | =head2 check_badflag | ||
| 239 | |||
| 240 | =for ref | ||
| 241 | |||
| 242 | Clear the badflag of an ndarray if it does not | ||
| 243 | contain any bad values | ||
| 244 | |||
| 245 | Given an ndarray whose bad flag is set, check whether it | ||
| 246 | actually contains any bad values and, if not, clear the flag. | ||
| 247 | It returns the final state of the badflag. | ||
| 248 | |||
| 249 | =for example | ||
| 250 | |||
| 251 | print "State of bad flag == ", $pdl->check_badflag; | ||
| 252 | |||
| 253 | =for bad | ||
| 254 | |||
| 255 | This method accepts ndarrays with or without bad values. It | ||
| 256 | returns an ndarray with the final badflag. | ||
| 257 | |||
| 258 | =cut | ||
| 259 | |||
| 260 | *check_badflag = \&PDL::check_badflag; | ||
| 261 | |||
| 262 | sub PDL::check_badflag { | ||
| 263 | my $pdl = shift; | ||
| 264 | $pdl->badflag(0) if $pdl->badflag and $pdl->nbad == 0; | ||
| 265 | return $pdl->badflag; | ||
| 266 | } # sub: check_badflag() | ||
| 267 | #line 268 "lib/PDL/Bad.pm" | ||
| 268 | |||
| 269 | |||
| 270 | =head2 isbad | ||
| 271 | |||
| 272 | =for sig | ||
| 273 | |||
| 274 | Signature: (a(); int [o]b()) | ||
| 275 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 276 | float double ldouble cfloat cdouble cldouble) | ||
| 277 | |||
| 278 | =for usage | ||
| 279 | |||
| 280 | $b = isbad($a); | ||
| 281 | isbad($a, $b); # all arguments given | ||
| 282 | $b = $a->isbad; # method call | ||
| 283 | $a->isbad($b); | ||
| 284 | |||
| 285 | =for ref | ||
| 286 | |||
| 287 | Returns a binary mask indicating which values of | ||
| 288 | the input are bad values | ||
| 289 | |||
| 290 | Returns a 1 if the value is bad, 0 otherwise. | ||
| 291 | Similar to L<isfinite|PDL::Math/isfinite>. | ||
| 292 | |||
| 293 | =for example | ||
| 294 | |||
| 295 | $x = pdl(1,2,3); | ||
| 296 | $x->badflag(1); | ||
| 297 | set($x,1,$x->badvalue); | ||
| 298 | $y = isbad($x); | ||
| 299 | print $y, "\n"; | ||
| 300 | [0 1 0] | ||
| 301 | |||
| 302 | =pod | ||
| 303 | |||
| 304 | Broadcasts over its inputs. | ||
| 305 | |||
| 306 | =for bad | ||
| 307 | |||
| 308 | This method works with input ndarrays that are bad. The output ndarray | ||
| 309 | will never contain bad values, but its bad value flag will be the | ||
| 310 | same as the input ndarray's flag. | ||
| 311 | |||
| 312 | =cut | ||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | *isbad = \&PDL::isbad; | ||
| 318 | |||
| 319 | |||
| 320 | |||
| 321 | |||
| 322 | |||
| 323 | |||
| 324 | =head2 isnan | ||
| 325 | |||
| 326 | =for sig | ||
| 327 | |||
| 328 | Signature: (a(); int [o]b()) | ||
| 329 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 330 | float double ldouble cfloat cdouble cldouble) | ||
| 331 | |||
| 332 | =for usage | ||
| 333 | |||
| 334 | $b = isnan($a); | ||
| 335 | isnan($a, $b); # all arguments given | ||
| 336 | $b = $a->isnan; # method call | ||
| 337 | $a->isnan($b); | ||
| 338 | |||
| 339 | =for ref | ||
| 340 | |||
| 341 | Returns a binary mask indicating which values of the input are C<NaN>. | ||
| 342 | |||
| 343 | Returns a 1 if the value is C<NaN>, 0 otherwise. | ||
| 344 | Similar to L<isfinite|PDL::Math/isfinite>. | ||
| 345 | |||
| 346 | =pod | ||
| 347 | |||
| 348 | Broadcasts over its inputs. | ||
| 349 | |||
| 350 | =for bad | ||
| 351 | |||
| 352 | C<isnan> does not process bad values. | ||
| 353 | It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. | ||
| 354 | |||
| 355 | =cut | ||
| 356 | |||
| 357 | |||
| 358 | |||
| 359 | |||
| 360 | *isnan = \&PDL::isnan; | ||
| 361 | |||
| 362 | |||
| 363 | |||
| 364 | |||
| 365 | |||
| 366 | |||
| 367 | =head2 isgood | ||
| 368 | |||
| 369 | =for sig | ||
| 370 | |||
| 371 | Signature: (a(); int [o]b()) | ||
| 372 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 373 | float double ldouble cfloat cdouble cldouble) | ||
| 374 | |||
| 375 | =for usage | ||
| 376 | |||
| 377 | $b = isgood($a); | ||
| 378 | isgood($a, $b); # all arguments given | ||
| 379 | $b = $a->isgood; # method call | ||
| 380 | $a->isgood($b); | ||
| 381 | |||
| 382 | =for ref | ||
| 383 | |||
| 384 | Is a value good? | ||
| 385 | |||
| 386 | Returns a 1 if the value is good, 0 otherwise. | ||
| 387 | Also see L<isfinite|PDL::Math/isfinite>. | ||
| 388 | |||
| 389 | =for example | ||
| 390 | |||
| 391 | $x = pdl(1,2,3); | ||
| 392 | $x->badflag(1); | ||
| 393 | set($x,1,$x->badvalue); | ||
| 394 | $y = isgood($x); | ||
| 395 | print $y, "\n"; | ||
| 396 | [1 0 1] | ||
| 397 | |||
| 398 | =pod | ||
| 399 | |||
| 400 | Broadcasts over its inputs. | ||
| 401 | |||
| 402 | =for bad | ||
| 403 | |||
| 404 | This method works with input ndarrays that are bad. The output ndarray | ||
| 405 | will never contain bad values, but its bad value flag will be the | ||
| 406 | same as the input ndarray's flag. | ||
| 407 | |||
| 408 | =cut | ||
| 409 | |||
| 410 | |||
| 411 | |||
| 412 | |||
| 413 | *isgood = \&PDL::isgood; | ||
| 414 | |||
| 415 | |||
| 416 | |||
| 417 | |||
| 418 | |||
| 419 | |||
| 420 | =head2 nbadover | ||
| 421 | |||
| 422 | =for sig | ||
| 423 | |||
| 424 | Signature: (a(n); indx [o] b()) | ||
| 425 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 426 | float double ldouble cfloat cdouble cldouble) | ||
| 427 | |||
| 428 | =for usage | ||
| 429 | |||
| 430 | $b = nbadover($a); | ||
| 431 | nbadover($a, $b); # all arguments given | ||
| 432 | $b = $a->nbadover; # method call | ||
| 433 | $a->nbadover($b); | ||
| 434 | |||
| 435 | =for ref | ||
| 436 | |||
| 437 | Find the number of bad elements along the 1st dimension. | ||
| 438 | |||
| 439 | This function reduces the dimensionality of an ndarray by one by finding the | ||
| 440 | number of bad elements along the 1st dimension. In this sense it shares | ||
| 441 | much in common with the functions defined in L<PDL::Ufunc>. In particular, | ||
| 442 | by using L<xchg|PDL::Slices/xchg> and similar dimension rearranging methods, | ||
| 443 | it is possible to perform this calculation over I<any> dimension. | ||
| 444 | |||
| 445 | =pod | ||
| 446 | |||
| 447 | Broadcasts over its inputs. | ||
| 448 | |||
| 449 | =for bad | ||
| 450 | |||
| 451 | nbadover processes input values that are bad. The output ndarray will not have | ||
| 452 | any bad values, but the bad flag will be set if the input ndarray had its bad | ||
| 453 | flag set. | ||
| 454 | |||
| 455 | =cut | ||
| 456 | |||
| 457 | |||
| 458 | |||
| 459 | |||
| 460 | *nbadover = \&PDL::nbadover; | ||
| 461 | |||
| 462 | |||
| 463 | |||
| 464 | |||
| 465 | |||
| 466 | |||
| 467 | =head2 ngoodover | ||
| 468 | |||
| 469 | =for sig | ||
| 470 | |||
| 471 | Signature: (a(n); indx [o] b()) | ||
| 472 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 473 | float double ldouble cfloat cdouble cldouble) | ||
| 474 | |||
| 475 | =for usage | ||
| 476 | |||
| 477 | $b = ngoodover($a); | ||
| 478 | ngoodover($a, $b); # all arguments given | ||
| 479 | $b = $a->ngoodover; # method call | ||
| 480 | $a->ngoodover($b); | ||
| 481 | |||
| 482 | =for ref | ||
| 483 | |||
| 484 | Find the number of good elements along the 1st dimension. | ||
| 485 | |||
| 486 | This function reduces the dimensionality of an ndarray | ||
| 487 | by one by finding the number of good elements | ||
| 488 | along the 1st dimension. | ||
| 489 | |||
| 490 | By using L<xchg|PDL::Slices/xchg> etc. it is possible to use | ||
| 491 | I<any> dimension. | ||
| 492 | |||
| 493 | =pod | ||
| 494 | |||
| 495 | Broadcasts over its inputs. | ||
| 496 | |||
| 497 | =for bad | ||
| 498 | |||
| 499 | ngoodover processes input values that are bad. The output ndarray will not have | ||
| 500 | any bad values, but the bad flag will be set if the input ndarray had its bad | ||
| 501 | flag set. | ||
| 502 | |||
| 503 | =cut | ||
| 504 | |||
| 505 | |||
| 506 | |||
| 507 | |||
| 508 | *ngoodover = \&PDL::ngoodover; | ||
| 509 | |||
| 510 | |||
| 511 | |||
| 512 | |||
| 513 | |||
| 514 | #line 477 "lib/PDL/Bad.pd" | ||
| 515 | |||
| 516 | *nbad = \&PDL::nbad; | ||
| 517 | sub PDL::nbad { | ||
| 518 | my($x) = @_; my $tmp; | ||
| 519 | $x->flat->nbadover($tmp=PDL->nullcreate($x) ); | ||
| 520 | return $tmp; | ||
| 521 | } | ||
| 522 | |||
| 523 | #line 477 "lib/PDL/Bad.pd" | ||
| 524 | *ngood = \&PDL::ngood; | ||
| 525 | sub PDL::ngood { | ||
| 526 | my($x) = @_; my $tmp; | ||
| 527 | $x->flat->ngoodover($tmp=PDL->nullcreate($x) ); | ||
| 528 | return $tmp; | ||
| 529 | } | ||
| 530 | |||
| 531 | #line 489 "lib/PDL/Bad.pd" | ||
| 532 | |||
| 533 | =head2 nbad | ||
| 534 | |||
| 535 | =for ref | ||
| 536 | |||
| 537 | Returns the number of bad values in an ndarray | ||
| 538 | |||
| 539 | =for bad | ||
| 540 | |||
| 541 | Accepts good and bad input ndarrays; output is an ndarray | ||
| 542 | and is always good. | ||
| 543 | |||
| 544 | =head2 ngood | ||
| 545 | |||
| 546 | =for ref | ||
| 547 | |||
| 548 | Returns the number of good values in an ndarray | ||
| 549 | |||
| 550 | =for usage | ||
| 551 | |||
| 552 | $x = ngood($data); | ||
| 553 | |||
| 554 | =for bad | ||
| 555 | |||
| 556 | Accepts good and bad input ndarrays; output is an ndarray | ||
| 557 | and is always good. | ||
| 558 | |||
| 559 | =head2 setbadat | ||
| 560 | |||
| 561 | =for ref | ||
| 562 | |||
| 563 | Set the value to bad at a given position. | ||
| 564 | |||
| 565 | =for usage | ||
| 566 | |||
| 567 | setbadat $ndarray, @position | ||
| 568 | |||
| 569 | C<@position> is a coordinate list, of size equal to the | ||
| 570 | number of dimensions in the ndarray. | ||
| 571 | This is a wrapper around L<set|PDL::Core/set> and is | ||
| 572 | probably mainly useful in test scripts! | ||
| 573 | |||
| 574 | =for example | ||
| 575 | |||
| 576 | pdl> $x = sequence 3,4 | ||
| 577 | pdl> $x->setbadat 2,1 | ||
| 578 | pdl> p $x | ||
| 579 | [ | ||
| 580 | [ 0 1 2] | ||
| 581 | [ 3 4 BAD] | ||
| 582 | [ 6 7 8] | ||
| 583 | [ 9 10 11] | ||
| 584 | ] | ||
| 585 | |||
| 586 | =for bad | ||
| 587 | |||
| 588 | This method can be called on ndarrays that have bad values. | ||
| 589 | The remainder of the arguments should be Perl scalars indicating | ||
| 590 | the position to set as bad. The output ndarray will have bad values | ||
| 591 | and will have its badflag turned on. | ||
| 592 | |||
| 593 | =cut | ||
| 594 | |||
| 595 | *setbadat = \&PDL::setbadat; | ||
| 596 | sub PDL::setbadat { | ||
| 597 | barf 'Usage: setbadat($pdl, $x, $y, ...)' if $#_<1; | ||
| 598 | my $self = shift; | ||
| 599 | PDL::Core::set_c ($self, [@_], $self->badvalue); | ||
| 600 | $self->badflag(1); | ||
| 601 | return $self; | ||
| 602 | } | ||
| 603 | #line 604 "lib/PDL/Bad.pm" | ||
| 604 | |||
| 605 | |||
| 606 | =head2 setbadif | ||
| 607 | |||
| 608 | =for sig | ||
| 609 | |||
| 610 | Signature: (a(); int mask(); [o]b()) | ||
| 611 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 612 | float double ldouble cfloat cdouble cldouble) | ||
| 613 | |||
| 614 | =for usage | ||
| 615 | |||
| 616 | $b = setbadif($a, $mask); | ||
| 617 | setbadif($a, $mask, $b); # all arguments given | ||
| 618 | $b = $a->setbadif($mask); # method call | ||
| 619 | $a->setbadif($mask, $b); | ||
| 620 | |||
| 621 | =for ref | ||
| 622 | |||
| 623 | Set elements bad based on the supplied mask, otherwise | ||
| 624 | copy across the data. | ||
| 625 | |||
| 626 | =for example | ||
| 627 | |||
| 628 | pdl> $x = sequence(5,5) | ||
| 629 | pdl> $x = $x->setbadif( $x % 2 ) | ||
| 630 | pdl> p "a badflag: ", $x->badflag, "\n" | ||
| 631 | a badflag: 1 | ||
| 632 | pdl> p "a is\n$x" | ||
| 633 | [ | ||
| 634 | [ 0 BAD 2 BAD 4] | ||
| 635 | [BAD 6 BAD 8 BAD] | ||
| 636 | [ 10 BAD 12 BAD 14] | ||
| 637 | [BAD 16 BAD 18 BAD] | ||
| 638 | [ 20 BAD 22 BAD 24] | ||
| 639 | ] | ||
| 640 | |||
| 641 | Unfortunately, this routine can I<not> be run inplace, since the | ||
| 642 | current implementation can not handle the same ndarray used as | ||
| 643 | C<a> and C<mask> (eg C<< $x->inplace->setbadif($x%2) >> fails). | ||
| 644 | Even more unfortunate: we can't catch this error and tell you. | ||
| 645 | |||
| 646 | =pod | ||
| 647 | |||
| 648 | Broadcasts over its inputs. | ||
| 649 | |||
| 650 | =for bad | ||
| 651 | |||
| 652 | The output always has its bad flag set, even if it does not contain | ||
| 653 | any bad values (use L</check_badflag> to check | ||
| 654 | whether there are any bad values in the output). | ||
| 655 | The input ndarray can have bad values: any bad values in the input ndarrays | ||
| 656 | are copied across to the output ndarray. | ||
| 657 | |||
| 658 | Also see L</setvaltobad> and L</setnantobad>. | ||
| 659 | |||
| 660 | =cut | ||
| 661 | |||
| 662 | |||
| 663 | |||
| 664 | |||
| 665 | *setbadif = \&PDL::setbadif; | ||
| 666 | |||
| 667 | |||
| 668 | |||
| 669 | |||
| 670 | |||
| 671 | |||
| 672 | =head2 setvaltobad | ||
| 673 | |||
| 674 | =for sig | ||
| 675 | |||
| 676 | Signature: (a(); [o]b(); double value) | ||
| 677 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 678 | float double ldouble cfloat cdouble cldouble) | ||
| 679 | |||
| 680 | =for usage | ||
| 681 | |||
| 682 | $b = setvaltobad($a, $value); | ||
| 683 | setvaltobad($a, $b, $value); # all arguments given | ||
| 684 | $b = $a->setvaltobad($value); # method call | ||
| 685 | $a->setvaltobad($b, $value); | ||
| 686 | $a->inplace->setvaltobad($value); # can be used inplace | ||
| 687 | setvaltobad($a->inplace, $value); | ||
| 688 | |||
| 689 | =for ref | ||
| 690 | |||
| 691 | Set bad all those elements which equal the supplied value. | ||
| 692 | |||
| 693 | =for example | ||
| 694 | |||
| 695 | $x = sequence(10) % 3; | ||
| 696 | $x->inplace->setvaltobad( 0 ); | ||
| 697 | print "$x\n"; | ||
| 698 | [BAD 1 2 BAD 1 2 BAD 1 2 BAD] | ||
| 699 | |||
| 700 | This is a simpler version of L</setbadif>, but this | ||
| 701 | function can be done inplace. See L</setnantobad> | ||
| 702 | if you want to convert NaN to the bad value. | ||
| 703 | |||
| 704 | =pod | ||
| 705 | |||
| 706 | Can operate inplace with C<a> as output C<b>. | ||
| 707 | Broadcasts over its inputs. | ||
| 708 | |||
| 709 | =for bad | ||
| 710 | |||
| 711 | The output always has its bad flag set, even if it does not contain | ||
| 712 | any bad values (use L</check_badflag> to check | ||
| 713 | whether there are any bad values in the output). | ||
| 714 | Any bad values in the input ndarrays are copied across to the output ndarray. | ||
| 715 | |||
| 716 | =cut | ||
| 717 | |||
| 718 | |||
| 719 | |||
| 720 | |||
| 721 | *setvaltobad = \&PDL::setvaltobad; | ||
| 722 | |||
| 723 | |||
| 724 | |||
| 725 | |||
| 726 | |||
| 727 | |||
| 728 | =head2 setnantobad | ||
| 729 | |||
| 730 | =for sig | ||
| 731 | |||
| 732 | Signature: (a(); [o]b()) | ||
| 733 | Types: (float ldouble cfloat cdouble cldouble double) | ||
| 734 | |||
| 735 | =for usage | ||
| 736 | |||
| 737 | $b = setnantobad($a); | ||
| 738 | setnantobad($a, $b); # all arguments given | ||
| 739 | $b = $a->setnantobad; # method call | ||
| 740 | $a->setnantobad($b); | ||
| 741 | $a->inplace->setnantobad; # can be used inplace | ||
| 742 | setnantobad($a->inplace); | ||
| 743 | |||
| 744 | =for ref | ||
| 745 | |||
| 746 | Sets NaN values (for complex, where either is NaN) in the input ndarray bad | ||
| 747 | (only relevant for floating-point ndarrays). | ||
| 748 | |||
| 749 | =pod | ||
| 750 | |||
| 751 | Can operate inplace with C<a> as output C<b>. | ||
| 752 | Broadcasts over its inputs. | ||
| 753 | |||
| 754 | =for bad | ||
| 755 | |||
| 756 | This method can process ndarrays with bad values: those bad values | ||
| 757 | are propagated into the output ndarray. Any value that is not a number | ||
| 758 | (before version 2.040 the test was for "not finite") | ||
| 759 | is also set to bad in the output ndarray. If all values from the input | ||
| 760 | ndarray are good, the output ndarray will B<not> have its | ||
| 761 | bad flag set. | ||
| 762 | |||
| 763 | =cut | ||
| 764 | |||
| 765 | |||
| 766 | |||
| 767 | |||
| 768 | *setnantobad = \&PDL::setnantobad; | ||
| 769 | |||
| 770 | |||
| 771 | |||
| 772 | |||
| 773 | |||
| 774 | |||
| 775 | =head2 setinftobad | ||
| 776 | |||
| 777 | =for sig | ||
| 778 | |||
| 779 | Signature: (a(); [o]b()) | ||
| 780 | Types: (float ldouble cfloat cdouble cldouble double) | ||
| 781 | |||
| 782 | =for usage | ||
| 783 | |||
| 784 | $b = setinftobad($a); | ||
| 785 | setinftobad($a, $b); # all arguments given | ||
| 786 | $b = $a->setinftobad; # method call | ||
| 787 | $a->setinftobad($b); | ||
| 788 | $a->inplace->setinftobad; # can be used inplace | ||
| 789 | setinftobad($a->inplace); | ||
| 790 | |||
| 791 | =for ref | ||
| 792 | |||
| 793 | Sets non-finite values (for complex, where either is non-finite) in | ||
| 794 | the input ndarray bad (only relevant for floating-point ndarrays). | ||
| 795 | |||
| 796 | =pod | ||
| 797 | |||
| 798 | Can operate inplace with C<a> as output C<b>. | ||
| 799 | Broadcasts over its inputs. | ||
| 800 | |||
| 801 | =for bad | ||
| 802 | |||
| 803 | This method can process ndarrays with bad values: those bad values | ||
| 804 | are propagated into the output ndarray. Any value that is not finite | ||
| 805 | is also set to bad in the output ndarray. If all values from the input | ||
| 806 | ndarray are finite, the output ndarray will B<not> have its | ||
| 807 | bad flag set. | ||
| 808 | |||
| 809 | =cut | ||
| 810 | |||
| 811 | |||
| 812 | |||
| 813 | |||
| 814 | *setinftobad = \&PDL::setinftobad; | ||
| 815 | |||
| 816 | |||
| 817 | |||
| 818 | |||
| 819 | |||
| 820 | |||
| 821 | =head2 setnonfinitetobad | ||
| 822 | |||
| 823 | =for sig | ||
| 824 | |||
| 825 | Signature: (a(); [o]b()) | ||
| 826 | Types: (float ldouble cfloat cdouble cldouble double) | ||
| 827 | |||
| 828 | =for usage | ||
| 829 | |||
| 830 | $b = setnonfinitetobad($a); | ||
| 831 | setnonfinitetobad($a, $b); # all arguments given | ||
| 832 | $b = $a->setnonfinitetobad; # method call | ||
| 833 | $a->setnonfinitetobad($b); | ||
| 834 | $a->inplace->setnonfinitetobad; # can be used inplace | ||
| 835 | setnonfinitetobad($a->inplace); | ||
| 836 | |||
| 837 | =for ref | ||
| 838 | |||
| 839 | Sets non-finite values (for complex, where either is non-finite) in | ||
| 840 | the input ndarray bad (only relevant for floating-point ndarrays). | ||
| 841 | |||
| 842 | =pod | ||
| 843 | |||
| 844 | Can operate inplace with C<a> as output C<b>. | ||
| 845 | Broadcasts over its inputs. | ||
| 846 | |||
| 847 | =for bad | ||
| 848 | |||
| 849 | This method can process ndarrays with bad values: those bad values | ||
| 850 | are propagated into the output ndarray. Any value that is not finite | ||
| 851 | is also set to bad in the output ndarray. If all values from the input | ||
| 852 | ndarray are finite, the output ndarray will B<not> have its | ||
| 853 | bad flag set. | ||
| 854 | |||
| 855 | =cut | ||
| 856 | |||
| 857 | |||
| 858 | |||
| 859 | |||
| 860 | *setnonfinitetobad = \&PDL::setnonfinitetobad; | ||
| 861 | |||
| 862 | |||
| 863 | |||
| 864 | |||
| 865 | |||
| 866 | |||
| 867 | =head2 setbadtonan | ||
| 868 | |||
| 869 | =for sig | ||
| 870 | |||
| 871 | Signature: (a(); [o] b()) | ||
| 872 | Types: (float ldouble cfloat cdouble cldouble double) | ||
| 873 | |||
| 874 | =for usage | ||
| 875 | |||
| 876 | $b = setbadtonan($a); | ||
| 877 | setbadtonan($a, $b); # all arguments given | ||
| 878 | $b = $a->setbadtonan; # method call | ||
| 879 | $a->setbadtonan($b); | ||
| 880 | $a->inplace->setbadtonan; # can be used inplace | ||
| 881 | setbadtonan($a->inplace); | ||
| 882 | |||
| 883 | =for ref | ||
| 884 | |||
| 885 | Sets Bad values to NaN | ||
| 886 | |||
| 887 | This is only relevant for floating-point ndarrays. The input ndarray can be | ||
| 888 | of any type, but if done inplace, the input must be floating point. | ||
| 889 | |||
| 890 | =pod | ||
| 891 | |||
| 892 | Can operate inplace with C<a> as output C<b>. | ||
| 893 | Broadcasts over its inputs. | ||
| 894 | |||
| 895 | =for bad | ||
| 896 | |||
| 897 | This method processes input ndarrays with bad values. The output ndarrays will | ||
| 898 | not contain bad values (insofar as NaN is not Bad as far as PDL is concerned) | ||
| 899 | and the output ndarray does not have its bad flag set. As an inplace | ||
| 900 | operation, it clears the bad flag. | ||
| 901 | |||
| 902 | =cut | ||
| 903 | |||
| 904 | |||
| 905 | |||
| 906 | |||
| 907 | *setbadtonan = \&PDL::setbadtonan; | ||
| 908 | |||
| 909 | |||
| 910 | |||
| 911 | |||
| 912 | |||
| 913 | |||
| 914 | =head2 setbadtoval | ||
| 915 | |||
| 916 | =for sig | ||
| 917 | |||
| 918 | Signature: (a(); [o]b(); double newval) | ||
| 919 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 920 | float double ldouble cfloat cdouble cldouble) | ||
| 921 | |||
| 922 | =for usage | ||
| 923 | |||
| 924 | $b = setbadtoval($a, $newval); | ||
| 925 | setbadtoval($a, $b, $newval); # all arguments given | ||
| 926 | $b = $a->setbadtoval($newval); # method call | ||
| 927 | $a->setbadtoval($b, $newval); | ||
| 928 | $a->inplace->setbadtoval($newval); # can be used inplace | ||
| 929 | setbadtoval($a->inplace, $newval); | ||
| 930 | |||
| 931 | =for ref | ||
| 932 | |||
| 933 | Replace any bad values by a (non-bad) value. | ||
| 934 | |||
| 935 | Also see L</badmask>. | ||
| 936 | |||
| 937 | =for example | ||
| 938 | |||
| 939 | $x->inplace->setbadtoval(23); | ||
| 940 | print "a badflag: ", $x->badflag, "\n"; | ||
| 941 | a badflag: 0 | ||
| 942 | |||
| 943 | =pod | ||
| 944 | |||
| 945 | Can operate inplace with C<a> as output C<b>. | ||
| 946 | Broadcasts over its inputs. | ||
| 947 | |||
| 948 | =for bad | ||
| 949 | |||
| 950 | The output always has its bad flag cleared. | ||
| 951 | If the input ndarray does not have its bad flag set, then | ||
| 952 | values are copied with no replacement. | ||
| 953 | |||
| 954 | =cut | ||
| 955 | |||
| 956 | |||
| 957 | |||
| 958 | |||
| 959 | *setbadtoval = \&PDL::setbadtoval; | ||
| 960 | |||
| 961 | |||
| 962 | |||
| 963 | |||
| 964 | |||
| 965 | |||
| 966 | =head2 badmask | ||
| 967 | |||
| 968 | =for sig | ||
| 969 | |||
| 970 | Signature: (a(); b(); [o]c()) | ||
| 971 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 972 | float double ldouble) | ||
| 973 | |||
| 974 | =for usage | ||
| 975 | |||
| 976 | $c = badmask($a, $b); | ||
| 977 | badmask($a, $b, $c); # all arguments given | ||
| 978 | $c = $a->badmask($b); # method call | ||
| 979 | $a->badmask($b, $c); | ||
| 980 | $a->inplace->badmask($b); # can be used inplace | ||
| 981 | badmask($a->inplace, $b); | ||
| 982 | |||
| 983 | =for ref | ||
| 984 | |||
| 985 | Clears all C<infs> and C<nans> in C<$a> to the corresponding value in C<$b>. | ||
| 986 | |||
| 987 | =pod | ||
| 988 | |||
| 989 | Can operate inplace with C<a> as output C<c>. | ||
| 990 | Broadcasts over its inputs. | ||
| 991 | |||
| 992 | =for bad | ||
| 993 | |||
| 994 | If bad values are present, these are also cleared. | ||
| 995 | |||
| 996 | =cut | ||
| 997 | |||
| 998 | |||
| 999 | |||
| 1000 | |||
| 1001 | *badmask = \&PDL::badmask; | ||
| 1002 | |||
| 1003 | |||
| 1004 | |||
| 1005 | |||
| 1006 | |||
| 1007 | |||
| 1008 | =head2 copybad | ||
| 1009 | |||
| 1010 | =for sig | ||
| 1011 | |||
| 1012 | Signature: (a(); mask(); [o]b()) | ||
| 1013 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 1014 | float double ldouble cfloat cdouble cldouble) | ||
| 1015 | |||
| 1016 | =for usage | ||
| 1017 | |||
| 1018 | $b = copybad($a, $mask); | ||
| 1019 | copybad($a, $mask, $b); # all arguments given | ||
| 1020 | $b = $a->copybad($mask); # method call | ||
| 1021 | $a->copybad($mask, $b); | ||
| 1022 | $a->inplace->copybad($mask); # can be used inplace | ||
| 1023 | copybad($a->inplace, $mask); | ||
| 1024 | |||
| 1025 | =for ref | ||
| 1026 | |||
| 1027 | Copies values from one ndarray to another, setting them | ||
| 1028 | bad if they are bad in the supplied mask. | ||
| 1029 | |||
| 1030 | =for example | ||
| 1031 | |||
| 1032 | $x = byte( [0,1,3] ); | ||
| 1033 | $mask = byte( [0,0,0] ); | ||
| 1034 | $mask->badflag(1); | ||
| 1035 | set($mask,1,$mask->badvalue); | ||
| 1036 | $x->inplace->copybad( $mask ); | ||
| 1037 | p $x; | ||
| 1038 | [0 BAD 3] | ||
| 1039 | |||
| 1040 | It is equivalent to: | ||
| 1041 | |||
| 1042 | $c = $x + $mask * 0 | ||
| 1043 | |||
| 1044 | =pod | ||
| 1045 | |||
| 1046 | Can operate inplace with C<a> as output C<b>. | ||
| 1047 | Broadcasts over its inputs. | ||
| 1048 | |||
| 1049 | =for bad | ||
| 1050 | |||
| 1051 | This handles input ndarrays that are bad. If either C<$x> | ||
| 1052 | or C<$mask> have bad values, those values will be marked | ||
| 1053 | as bad in the output ndarray and the output ndarray will have | ||
| 1054 | its bad value flag set to true. | ||
| 1055 | |||
| 1056 | =cut | ||
| 1057 | |||
| 1058 | |||
| 1059 | |||
| 1060 | |||
| 1061 | *copybad = \&PDL::copybad; | ||
| 1062 | |||
| 1063 | |||
| 1064 | |||
| 1065 | |||
| 1066 | |||
| 1067 | |||
| 1068 | =head2 locf | ||
| 1069 | |||
| 1070 | =for sig | ||
| 1071 | |||
| 1072 | Signature: (a(n); [o]b(n)) | ||
| 1073 | Types: (sbyte byte short ushort long ulong indx ulonglong longlong | ||
| 1074 | float double ldouble cfloat cdouble cldouble) | ||
| 1075 | |||
| 1076 | =for usage | ||
| 1077 | |||
| 1078 | $b = locf($a); | ||
| 1079 | locf($a, $b); # all arguments given | ||
| 1080 | $b = $a->locf; # method call | ||
| 1081 | $a->locf($b); | ||
| 1082 | |||
| 1083 | =for ref | ||
| 1084 | |||
| 1085 | Last Observation Carried Forward - replace | ||
| 1086 | every BAD value with the most recent non-BAD value prior to it. | ||
| 1087 | Any leading BADs will be set to 0. | ||
| 1088 | |||
| 1089 | =pod | ||
| 1090 | |||
| 1091 | Broadcasts over its inputs. | ||
| 1092 | |||
| 1093 | =for bad | ||
| 1094 | |||
| 1095 | C<locf> processes bad values. | ||
| 1096 | It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. | ||
| 1097 | |||
| 1098 | =cut | ||
| 1099 | |||
| 1100 | |||
| 1101 | |||
| 1102 | |||
| 1103 | *locf = \&PDL::locf; | ||
| 1104 | |||
| 1105 | |||
| 1106 | |||
| 1107 | |||
| 1108 | |||
| 1109 | |||
| 1110 | |||
| 1111 | #line 929 "lib/PDL/Bad.pd" | ||
| 1112 | |||
| 1113 | =head1 AUTHOR | ||
| 1114 | |||
| 1115 | Doug Burke (djburke@cpan.org), 2000, 2001, 2003, 2006. | ||
| 1116 | |||
| 1117 | The per-ndarray bad value support is by Heiko Klein (2006). | ||
| 1118 | |||
| 1119 | CPAN documentation fixes by David Mertens (2010, 2013). | ||
| 1120 | |||
| 1121 | All rights reserved. There is no warranty. You are allowed to | ||
| 1122 | redistribute this software / documentation under certain conditions. For | ||
| 1123 | details, see the file COPYING in the PDL distribution. If this file is | ||
| 1124 | separated from the PDL distribution, the copyright notice should be | ||
| 1125 | included in the file. | ||
| 1126 | |||
| 1127 | =cut | ||
| 1128 | #line 1129 "lib/PDL/Bad.pm" | ||
| 1129 | |||
| 1130 | # Exit with OK status | ||
| 1131 | |||
| 1132 | 1; | ||