Skip to content

Commit

Permalink
Merge branch 'master' into 64bit-index-support
Browse files Browse the repository at this point in the history
  • Loading branch information
devel-chm committed Jan 22, 2013
2 parents da6d5d6 + ce06b35 commit 9ee953d
Show file tree
Hide file tree
Showing 88 changed files with 1,200 additions and 2,563 deletions.
102 changes: 55 additions & 47 deletions Basic/Bad/bad.pd
Expand Up @@ -717,36 +717,25 @@ Also see L<isfinite|PDL::Math/isfinite>.
);


# perhaps these should have pm code which returns the
# answer if the bad flag is not set
pp_def('nbadover' . <<'=cut',

=head2 nbadover

=cut
=for sig

# perhaps these should have pm code which returns the
# answer if the bad flag is not set
pp_def(
'nbadover',
HandleBad => 1,
Pars => 'a(n); int+ [o]b();',
Code =>
'$b() = 0;',
BadCode =>
'$GENERIC(b) cnt = 0;
loop(n) %{
if ( $ISBAD(a()) ) { cnt++; }
%}
$b() = cnt;',
Doc => <<'EOD',
Signature: (a(n); int+ [o] b())

=for ref

Find the number of bad elements along the 1st dimension.

This function reduces the dimensionality of a piddle
by one by finding the number of bad elements
along the 1st dimension.

By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
I<any> dimension.
This function reduces the dimensionality of a piddle by one by finding the
number of bad elements along the 1st dimension. In this sense it shares
much in common with the functions defined in L<PDL::Ufunc>. In particular,
by using L<xchg|PDL::Slices/xchg> and similar dimension rearranging methods,
it is possible to perform this calculation over I<any> dimension.

=for usage

Expand All @@ -756,10 +745,23 @@ I<any> dimension.

$spectrum = nbadover $image->xchg(0,1)

=for bad

nbadover processes input values that are bad. The ouput piddle will not have
any bad values and will not have its bad flag set.

=cut

EOD
);
HandleBad => 1,
Code => '$b() = 0;',
BadCode => q{
$GENERIC(b) cnt = 0;
loop(n) %{
if ( $ISBAD(a()) ) { cnt++; }
%}
$b() = cnt;
},
);

=head2 ngoodover

Expand Down Expand Up @@ -1083,7 +1085,7 @@ if ( $usenan ) {
pp_add_exported( '', 'setnantobad setbadtonan' );
my $stuff_to_add_to_the_pm = <<'!NO!SUBS!';

=head3 setnantobad
=head2 setnantobad

=for ref

Expand Down Expand Up @@ -1122,7 +1124,7 @@ sub PDL::setnantobad{
return $b;
}

=head3 setbadtonan
=head2 setbadtonan

=for ref

Expand Down Expand Up @@ -1220,14 +1222,37 @@ Can be done inplace.
BadDoc => 'Supports bad values.',
); # pp_def: setnantobad


pp_def('setbadtonan' . <<'=cut',

=head2 setbadtonan

=cut
=for sig

pp_def(
'setbadtonan',
Signature: (a(); [o] b();)

=for ref

Sets Bad values to NaN

This is only relevant for floating-point piddles. The input piddle can be
of any type, but if done inplace, the input must be floating point.

=for usage

$b = $a->setbadtonan;
$a->inplace->setbadtonan;

=for bad

This method processes input piddles with bad values. The output piddles will
not contain bad values (insofar as NaN is not Bad as far as PDL is concerned)
and the output piddle does not have its bad flag set. As an inplace
operation, it clears the bad flag.

=cut

HandleBad => 1,
Pars => 'a(); [o]b();',
GenericTypes => [ 'F', 'D' ],
Inplace => 1,
CopyBadStatusCode =>
Expand All @@ -1239,23 +1264,6 @@ pp_def(
'if ( $ISBAD(a()) ) { $b() = $TFD(_nan_float,_nan_double); } /* _nan_xxx set up at top of file */
else { $b() = $a(); }
',
Doc =>
'
=for ref

Sets Bad values to NaN
(only relevant for floating-point piddles).
Can be done inplace and it clears the bad flag.

=for usage

$b = $a->setbadtonan;
$a->inplace->setbadtonan;

=cut

',
BadDoc => 'Supports bad values.',
); # pp_def: setbadtonan

} # if: $usenan
Expand Down
2 changes: 1 addition & 1 deletion Basic/Complex/complex.pd
Expand Up @@ -730,7 +730,7 @@ pp_def 'Cacosh',
Pars => 'a(m=2); [o]c(m=2)',
Inplace => 1,
GenericTypes => [F,D],
Doc => '',
Doc => 'Works inplace',
Code => q^
$GENERIC() ar = $a(m=>0), ai = $a(m=>1);

Expand Down
20 changes: 11 additions & 9 deletions Basic/Core/Basic.pm
Expand Up @@ -407,7 +407,8 @@ or
$hist = hist($data,$min,$max,$step);
($xvals,$hist) = hist($data,[$min,$max,$step]);
If C<hist> is run in list context, C<$xvals> gives the computed bin centres
If C<hist> is run in list context, C<$xvals> gives the
computed bin centres as double values.
A nice idiom (with
L<PDL::Graphics::PGPLOT|PDL::Graphics::PGPLOT>) is
Expand Down Expand Up @@ -455,8 +456,9 @@ Create a weighted histogram of a piddle
$hist = whist($data, $wt, [$min,$max,$step]);
($xvals,$hist) = whist($data, $wt, [$min,$max,$step]);
If requested, C<$xvals> gives the computed bin centres.
C<$data> and C<$wt> should have the same dimensionality and extents.
If requested, C<$xvals> gives the computed bin centres
as type double values. C<$data> and C<$wt> should have
the same dimensionality and extents.
A nice idiom (with
L<PDL::Graphics::PGPLOT|PDL::Graphics::PGPLOT>) is
Expand Down Expand Up @@ -496,16 +498,16 @@ sub _hist_bin_calc {
my $ntype = $pdl->get_datatype;
barf "empty piddle, no values to work with" if $pdl->nelem == 0;
unless (defined $step) {
my $defbins = 100 < $pdl->nelem ? 100 : $pdl->nelem;
my $defbins = sqrt($pdl->nelem);
$defbins = ($defbins>100) ? 100 : $defbins;
$step = ($max-$min)/$defbins;
$step = int($step) > 0 ? int($step) : 1 if $ntype < $PDL_F;
}
barf "step is zero (or all data equal to one value)" if $step == 0;
my $bins = int(($max-$min)/$step);
my $bins = int(($max-$min)/$step+0.5);
print "hist with step $step, min $min and $bins bins\n"
if $PDL::debug;
my $xvals = $min + $step/2 + sequence(PDL::Type->new($ntype),$bins)*
PDL::convert($step,$ntype) if $wantarray;
if $PDL::debug;
# Need to use double for $xvals here
my $xvals = $min + $step/2 + sequence(PDL::Core::double,$bins)*$step if $wantarray;

return ( $step, $min, $bins, $xvals );
}
Expand Down

0 comments on commit 9ee953d

Please sign in to comment.