"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "GENERATED/PDL/Primitive.pm" between
PDL-2.076.tar.gz and PDL-2.077.tar.gz

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

Primitive.pm  (PDL-2.076):Primitive.pm  (PDL-2.077)
# #
# GENERATED WITH PDL::PP! Don't modify! # GENERATED WITH PDL::PP! Don't modify!
# #
package PDL::Primitive; package PDL::Primitive;
our @EXPORT_OK = qw(inner outer matmult innerwt inner2 inner2d inner2t crossp no rm indadd conv1d in uniq uniqind uniqvec hclip lclip clip clip wtstat statsover stats histogram whistogram histogram2d whistogram2d fibonacci append axisvalues srand random randsym grandom vsearch vsearch_sample vsearch_insert_leftmost vsea rch_insert_rightmost vsearch_match vsearch_bin_inclusive vsearch_bin_exclusive i nterpolate interpol interpND one2nd which which_both where whereND whichND setop s intersect ); our @EXPORT_OK = qw(inner outer matmult innerwt inner2 inner2d inner2t crossp no rm indadd conv1d in uniq uniqind uniqvec hclip lclip clip clip wtstat statsover stats histogram whistogram histogram2d whistogram2d fibonacci append axisvalues srand random randsym grandom vsearch vsearch_sample vsearch_insert_leftmost vsea rch_insert_rightmost vsearch_match vsearch_bin_inclusive vsearch_bin_exclusive i nterpolate interpol interpND one2nd which which_both where where_both whereND wh ichND setops intersect );
our %EXPORT_TAGS = (Func=>\@EXPORT_OK); our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
use PDL::Core; use PDL::Core;
use PDL::Exporter; use PDL::Exporter;
use DynaLoader; use DynaLoader;
our @ISA = ( 'PDL::Exporter','DynaLoader' ); our @ISA = ( 'PDL::Exporter','DynaLoader' );
push @PDL::Core::PP, __PACKAGE__; push @PDL::Core::PP, __PACKAGE__;
bootstrap PDL::Primitive ; bootstrap PDL::Primitive ;
skipping to change at line 566 skipping to change at line 566
conv1d ignores the bad-value flag of the input ndarrays. conv1d ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 689 "Primitive.pm" #line 689 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub PDL::conv1d { sub PDL::conv1d {
my $opt = pop @_ if ref($_[$#_]) eq 'HASH'; my $opt = pop @_ if ref($_[-1]) eq 'HASH';
die 'Usage: conv1d( a(m), kern(p), [o]b(m), {Options} )' die 'Usage: conv1d( a(m), kern(p), [o]b(m), {Options} )'
if $#_<1 || $#_>2; if @_<2 || @_>3;
my($x,$kern) = @_; my($x,$kern) = @_;
my $c = $#_ == 2 ? $_[2] : PDL->null; my $c = @_ == 3 ? $_[2] : PDL->null;
PDL::_conv1d_int($x,$kern,$c, PDL::_conv1d_int($x,$kern,$c,
!(defined $opt && exists $$opt{Boundary}) ? 0 : !(defined $opt && exists $$opt{Boundary}) ? 0 :
lc $$opt{Boundary} eq "reflect"); lc $$opt{Boundary} eq "reflect");
return $c; return $c;
} }
#line 708 "Primitive.pm" #line 708 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*conv1d = \&PDL::conv1d; *conv1d = \&PDL::conv1d;
skipping to change at line 623 skipping to change at line 623
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 758 "Primitive.pm" #line 758 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*in = \&PDL::in; *in = \&PDL::in;
#line 765 "Primitive.pm" #line 765 "Primitive.pm"
#line 770 "primitive.pd" #line 762 "primitive.pd"
=head2 uniq =head2 uniq
=for ref =for ref
return all unique elements of an ndarray return all unique elements of an ndarray
The unique elements are returned in ascending order. The unique elements are returned in ascending order.
=for example =for example
skipping to change at line 683 skipping to change at line 683
my $answ = $nans; # NaN values always uniq my $answ = $nans; # NaN values always uniq
if ( $uniq->nelem > 0 ) { if ( $uniq->nelem > 0 ) {
$answ = $uniq->append($answ); $answ = $uniq->append($answ);
} else { } else {
$answ = ( ($srt->nelem == 0) ? $srt : PDL::pdl( ref($srt), [$srt->index(0 )] ) )->append($answ); $answ = ( ($srt->nelem == 0) ? $srt : PDL::pdl( ref($srt), [$srt->index(0 )] ) )->append($answ);
} }
return $answ; return $answ;
} }
#line 827 "Primitive.pm" #line 827 "Primitive.pm"
#line 830 "primitive.pd" #line 822 "primitive.pd"
=head2 uniqind =head2 uniqind
=for ref =for ref
Return the indices of all unique elements of an ndarray Return the indices of all unique elements of an ndarray
The order is in the order of the values to be consistent The order is in the order of the values to be consistent
with uniq. C<NaN> values never compare equal with any with uniq. C<NaN> values never compare equal with any
other value and so are always unique. This follows the other value and so are always unique. This follows the
Matlab usage. Matlab usage.
skipping to change at line 747 skipping to change at line 747
my $ansind = $nanind; my $ansind = $nanind;
if ( $uniqind->nelem > 0 ) { if ( $uniqind->nelem > 0 ) {
$ansind = ($good->index($i_srt->index($uniqind)))->append($ansind); $ansind = ($good->index($i_srt->index($uniqind)))->append($ansind);
} else { } else {
$ansind = $uniqind->append($ansind); $ansind = $uniqind->append($ansind);
} }
return $ansind; return $ansind;
} }
#line 894 "Primitive.pm" #line 894 "Primitive.pm"
#line 896 "primitive.pd" #line 888 "primitive.pd"
=head2 uniqvec =head2 uniqvec
=for ref =for ref
Return all unique vectors out of a collection Return all unique vectors out of a collection
NOTE: If any vectors in the input ndarray have NaN values NOTE: If any vectors in the input ndarray have NaN values
they are returned at the end of the non-NaN ones. This is they are returned at the end of the non-NaN ones. This is
because, by definition, NaN values never compare equal with because, by definition, NaN values never compare equal with
skipping to change at line 799 skipping to change at line 799
my $pdl2d = $pdl->clump(1..$pdl->ndims-1); my $pdl2d = $pdl->clump(1..$pdl->ndims-1);
my $ngood = $pdl2d->ngoodover; my $ngood = $pdl2d->ngoodover;
$pdl2d = $pdl2d->mv(0,-1)->dice($ngood->which)->mv(-1,0); # remov e all-BAD vectors $pdl2d = $pdl2d->mv(0,-1)->dice($ngood->which)->mv(-1,0); # remov e all-BAD vectors
my $numnan = ($pdl2d!=$pdl2d)->sumover; # wo rks since no all-BADs to confuse my $numnan = ($pdl2d!=$pdl2d)->sumover; # wo rks since no all-BADs to confuse
my $presrt = $pdl2d->mv(0,-1)->dice($numnan->not->which)->mv(0,-1); # re move vectors with any NaN values my $presrt = $pdl2d->mv(0,-1)->dice($numnan->not->which)->mv(0,-1); # re move vectors with any NaN values
my $nanvec = $pdl2d->mv(0,-1)->dice($numnan->which)->mv(0,-1); # th e vectors with any NaN values my $nanvec = $pdl2d->mv(0,-1)->dice($numnan->which)->mv(0,-1); # th e vectors with any NaN values
# use dice instead of slice since qsortvec might be packing
# the badvals to the front of the array instead of the end like
# the docs say. If that is the case and it gets fixed, it won't
# bust uniqvec. DAL 14-March 2006
my $srt = $presrt->qsortvec->mv(0,-1); # BA Ds are sorted by qsortvec my $srt = $presrt->qsortvec->mv(0,-1); # BA Ds are sorted by qsortvec
my $srtdice = $srt; my $srtdice = $srt;
my $somebad = null; my $somebad = null;
if ($srt->badflag) { if ($srt->badflag) {
$srtdice = $srt->dice($srt->mv(0,-1)->nbadover->not->which); $srtdice = $srt->dice($srt->mv(0,-1)->nbadover->not->which);
$somebad = $srt->dice($srt->mv(0,-1)->nbadover->which); $somebad = $srt->dice($srt->mv(0,-1)->nbadover->which);
} }
my $uniq = $srtdice->nelem > 0 my $uniq = $srtdice->nelem > 0
? ($srtdice != $srtdice->rotate(-1))->mv(0,-1)->orover->which ? ($srtdice != $srtdice->rotate(-1))->mv(0,-1)->orover->which
: $srtdice->orover->which; : $srtdice->orover->which;
my $ans = $uniq->nelem > 0 ? $srtdice->dice($uniq) : my $ans = $uniq->nelem > 0 ? $srtdice->dice($uniq) :
($srtdice->nelem > 0) ? $srtdice->slice("0,:") : ($srtdice->nelem > 0) ? $srtdice->slice("0,:") :
$srtdice; $srtdice;
return $ans->append($somebad)->append($nanvec->mv(0,-1))->mv(0,-1); return $ans->append($somebad)->append($nanvec->mv(0,-1))->mv(0,-1);
} }
#line 972 "Primitive.pm" #line 967 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 hclip =head2 hclip
=for sig =for sig
Signature: (a(); b(); [o] c()) Signature: (a(); b(); [o] c())
=for ref =for ref
clip (threshold) C<$a> by C<$b> (C<$b> is upper bound) clip (threshold) C<$a> by C<$b> (C<$b> is upper bound)
=for bad =for bad
hclip processes bad values. hclip processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 997 "Primitive.pm" #line 992 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub PDL::hclip { sub PDL::hclip {
my ($x,$y) = @_; my ($x,$y) = @_;
my $c; my $c;
if ($x->is_inplace) { if ($x->is_inplace) {
$x->set_inplace(0); $c = $x; $x->set_inplace(0); $c = $x;
} elsif ($#_ > 1) {$c=$_[2]} else {$c=PDL->nullcreate($x)} } elsif (@_ > 2) {$c=$_[2]} else {$c=PDL->nullcreate($x)}
PDL::_hclip_int($x,$y,$c); PDL::_hclip_int($x,$y,$c);
return $c; return $c;
} }
#line 1012 "Primitive.pm" #line 1007 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*hclip = \&PDL::hclip; *hclip = \&PDL::hclip;
#line 1019 "Primitive.pm" #line 1014 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 lclip =head2 lclip
=for sig =for sig
Signature: (a(); b(); [o] c()) Signature: (a(); b(); [o] c())
=for ref =for ref
clip (threshold) C<$a> by C<$b> (C<$b> is lower bound) clip (threshold) C<$a> by C<$b> (C<$b> is lower bound)
=for bad =for bad
lclip processes bad values. lclip processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1044 "Primitive.pm" #line 1039 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub PDL::lclip { sub PDL::lclip {
my ($x,$y) = @_; my ($x,$y) = @_;
my $c; my $c;
if ($x->is_inplace) { if ($x->is_inplace) {
$x->set_inplace(0); $c = $x; $x->set_inplace(0); $c = $x;
} elsif ($#_ > 1) {$c=$_[2]} else {$c=PDL->nullcreate($x)} } elsif (@_ > 2) {$c=$_[2]} else {$c=PDL->nullcreate($x)}
PDL::_lclip_int($x,$y,$c); PDL::_lclip_int($x,$y,$c);
return $c; return $c;
} }
#line 1059 "Primitive.pm" #line 1054 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*lclip = \&PDL::lclip; *lclip = \&PDL::lclip;
#line 1066 "Primitive.pm" #line 1061 "Primitive.pm"
#line 1013 "primitive.pd" #line 999 "primitive.pd"
=head2 clip =head2 clip
=for ref =for ref
Clip (threshold) an ndarray by (optional) upper or lower bounds. Clip (threshold) an ndarray by (optional) upper or lower bounds.
=for usage =for usage
$y = $x->clip(0,3); $y = $x->clip(0,3);
$c = $x->clip(undef, $x); $c = $x->clip(undef, $x);
=for bad =for bad
clip handles bad values since it is just a clip handles bad values since it is just a
wrapper around L</hclip> and wrapper around L</hclip> and
L</lclip>. L</lclip>.
=cut =cut
#line 1090 "Primitive.pm" #line 1085 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 clip =head2 clip
=for sig =for sig
Signature: (a(); l(); h(); [o] c()) Signature: (a(); l(); h(); [o] c())
=for ref =for ref
info not available info not available
=for bad =for bad
clip processes bad values. clip processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1117 "Primitive.pm" #line 1112 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
*clip = \&PDL::clip; *clip = \&PDL::clip;
sub PDL::clip { sub PDL::clip {
my($x, $l, $h) = @_; my($x, $l, $h) = @_;
my $d; my $d;
unless(defined($l) || defined($h)) { unless(defined($l) || defined($h)) {
# Deal with pathological case # Deal with pathological case
if($x->is_inplace) { if($x->is_inplace) {
$x->set_inplace(0); $x->set_inplace(0);
return $x; return $x;
} else { } else {
return $x->copy; return $x->copy;
} }
} }
if($x->is_inplace) { if($x->is_inplace) {
$x->set_inplace(0); $d = $x $x->set_inplace(0); $d = $x
} elsif ($#_ > 2) { } elsif (@_ > 3) {
$d=$_[3] $d=$_[3]
} else { } else {
$d = PDL->nullcreate($x); $d = PDL->nullcreate($x);
} }
if(defined($l) && defined($h)) { if(defined($l) && defined($h)) {
PDL::_clip_int($x,$l,$h,$d); PDL::_clip_int($x,$l,$h,$d);
} elsif( defined($l) ) { } elsif( defined($l) ) {
PDL::_lclip_int($x,$l,$d); PDL::_lclip_int($x,$l,$d);
} elsif( defined($h) ) { } elsif( defined($h) ) {
PDL::_hclip_int($x,$h,$d); PDL::_hclip_int($x,$h,$d);
} else { } else {
die "This can't happen (clip contingency) - file a bug"; die "This can't happen (clip contingency) - file a bug";
} }
return $d; return $d;
} }
#line 1156 "Primitive.pm" #line 1151 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*clip = \&PDL::clip; *clip = \&PDL::clip;
#line 1163 "Primitive.pm" #line 1158 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 wtstat =head2 wtstat
=for sig =for sig
Signature: (a(n); wt(n); avg(); [o]b(); int deg) Signature: (a(n); wt(n); avg(); [o]b(); int deg)
=for ref =for ref
skipping to change at line 1008 skipping to change at line 1003
b() = (sum_i wt_i * (a_i ** degree - avg)) / (sum_i wt_i) b() = (sum_i wt_i * (a_i ** degree - avg)) / (sum_i wt_i)
=for bad =for bad
=for bad =for bad
Bad values are ignored in any calculation; C<$b> will only Bad values are ignored in any calculation; C<$b> will only
have its bad flag set if the output contains any bad data. have its bad flag set if the output contains any bad data.
=cut =cut
#line 1197 "Primitive.pm" #line 1192 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*wtstat = \&PDL::wtstat; *wtstat = \&PDL::wtstat;
#line 1204 "Primitive.pm" #line 1199 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 statsover =head2 statsover
=for sig =for sig
Signature: (a(n); w(n); float+ [o]avg(); float+ [o]prms(); int+ [o]median(); i nt+ [o]min(); int+ [o]max(); float+ [o]adev(); float+ [o]rms()) Signature: (a(n); w(n); float+ [o]avg(); float+ [o]prms(); int+ [o]median(); i nt+ [o]min(); int+ [o]max(); float+ [o]adev(); float+ [o]rms())
=for ref =for ref
skipping to change at line 1085 skipping to change at line 1080
use C<clump(-1)> directly on the ndarray or call C<stats>. use C<clump(-1)> directly on the ndarray or call C<stats>.
=for bad =for bad
=for bad =for bad
Bad values are simply ignored in the calculation, effectively reducing Bad values are simply ignored in the calculation, effectively reducing
the sample size. If all data are bad then the output data are marked bad. the sample size. If all data are bad then the output data are marked bad.
=cut =cut
#line 1286 "Primitive.pm" #line 1281 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub PDL::statsover { sub PDL::statsover {
barf('Usage: ($mean,[$prms, $median, $min, $max, $adev, $rms]) = statsover($d ata,[$weights])') if $#_>1; barf('Usage: ($mean,[$prms, $median, $min, $max, $adev, $rms]) = statsover($d ata,[$weights])') if @_>2;
my ($data, $weights) = @_; my ($data, $weights) = @_;
$weights = $data->ones() if !defined($weights); $weights = $data->ones() if !defined($weights);
my $median = $data->medover(); my $median = $data->medover();
my $mean = PDL->nullcreate($data); my $mean = PDL->nullcreate($data);
my $rms = PDL->nullcreate($data); my $rms = PDL->nullcreate($data);
my $min = PDL->nullcreate($data); my $min = PDL->nullcreate($data);
my $max = PDL->nullcreate($data); my $max = PDL->nullcreate($data);
my $adev = PDL->nullcreate($data); my $adev = PDL->nullcreate($data);
my $prms = PDL->nullcreate($data); my $prms = PDL->nullcreate($data);
PDL::_statsover_int($data, $weights, $mean, $prms, $median, $min, $max, $adev , $rms); PDL::_statsover_int($data, $weights, $mean, $prms, $median, $min, $max, $adev , $rms);
return $mean unless wantarray; return $mean unless wantarray;
return ($mean, $prms, $median, $min, $max, $adev, $rms); return ($mean, $prms, $median, $min, $max, $adev, $rms);
} }
#line 1311 "Primitive.pm" #line 1306 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*statsover = \&PDL::statsover; *statsover = \&PDL::statsover;
#line 1318 "Primitive.pm" #line 1313 "Primitive.pm"
#line 1321 "primitive.pd" #line 1307 "primitive.pd"
=head2 stats =head2 stats
=for ref =for ref
Calculates useful statistics on an ndarray Calculates useful statistics on an ndarray
=for usage =for usage
($mean,$prms,$median,$min,$max,$adev,$rms) = stats($ndarray,[$weights]); ($mean,$prms,$median,$min,$max,$adev,$rms) = stats($ndarray,[$weights]);
skipping to change at line 1140 skipping to change at line 1135
=for bad =for bad
Bad values are handled; if all input values are bad, then all of the output Bad values are handled; if all input values are bad, then all of the output
values are flagged bad. values are flagged bad.
=cut =cut
*stats = \&PDL::stats; *stats = \&PDL::stats;
sub PDL::stats { sub PDL::stats {
barf('Usage: ($mean,[$rms]) = stats($data,[$weights])') if $#_>1; barf('Usage: ($mean,[$rms]) = stats($data,[$weights])') if @_>2;
my ($data,$weights) = @_; my ($data,$weights) = @_;
# Ensure that $weights is properly broadcasted over; this could be # Ensure that $weights is properly broadcasted over; this could be
# done rather more efficiently... # done rather more efficiently...
if(defined $weights) { if(defined $weights) {
$weights = pdl($weights) unless UNIVERSAL::isa($weights,'PDL'); $weights = pdl($weights) unless UNIVERSAL::isa($weights,'PDL');
if( ($weights->ndims != $data->ndims) or if( ($weights->ndims != $data->ndims) or
(pdl($weights->dims) != pdl($data->dims))->or (pdl($weights->dims) != pdl($data->dims))->or
) { ) {
$weights = $weights + zeroes($data) $weights = $weights + zeroes($data)
} }
$weights = $weights->flat; $weights = $weights->flat;
} }
return PDL::statsover($data->flat,$weights); return PDL::statsover($data->flat,$weights);
} }
#line 1366 "Primitive.pm" #line 1361 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 histogram =head2 histogram
=for sig =for sig
Signature: (in(n); int+[o] hist(m); double step; double min; int msize => m) Signature: (in(n); int+[o] hist(m); double step; double min; int msize => m)
=for ref =for ref
skipping to change at line 1201 skipping to change at line 1196
pdl> p histogram(pdl(1,1,2),1,0,3) pdl> p histogram(pdl(1,1,2),1,0,3)
[0 2 1] [0 2 1]
=for bad =for bad
histogram processes bad values. histogram processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1418 "Primitive.pm" #line 1413 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*histogram = \&PDL::histogram; *histogram = \&PDL::histogram;
#line 1425 "Primitive.pm" #line 1420 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 whistogram =head2 whistogram
=for sig =for sig
Signature: (in(n); float+ wt(n);float+[o] hist(m); double step; double min; in t msize => m) Signature: (in(n); float+ wt(n);float+[o] hist(m); double step; double min; in t msize => m)
=for ref =for ref
skipping to change at line 1248 skipping to change at line 1243
pdl> p whistogram(pdl(1,1,2), pdl(0.1,0.1,0.5), 1, 0, 4) pdl> p whistogram(pdl(1,1,2), pdl(0.1,0.1,0.5), 1, 0, 4)
[0 0.2 0.5 0] [0 0.2 0.5 0]
=for bad =for bad
whistogram processes bad values. whistogram processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1474 "Primitive.pm" #line 1469 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*whistogram = \&PDL::whistogram; *whistogram = \&PDL::whistogram;
#line 1481 "Primitive.pm" #line 1476 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 histogram2d =head2 histogram2d
=for sig =for sig
Signature: (ina(n); inb(n); int+[o] hist(ma,mb); double stepa; double mina; in t masize => ma; Signature: (ina(n); inb(n); int+[o] hist(ma,mb); double stepa; double mina; in t masize => ma;
double stepb; double minb; int mbsize => mb;) double stepb; double minb; int mbsize => mb;)
skipping to change at line 1300 skipping to change at line 1295
[0 2 2] [0 2 2]
[0 1 0] [0 1 0]
] ]
=for bad =for bad
histogram2d processes bad values. histogram2d processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1535 "Primitive.pm" #line 1530 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*histogram2d = \&PDL::histogram2d; *histogram2d = \&PDL::histogram2d;
#line 1542 "Primitive.pm" #line 1537 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 whistogram2d =head2 whistogram2d
=for sig =for sig
Signature: (ina(n); inb(n); float+ wt(n);float+[o] hist(ma,mb); double stepa; double mina; int masize => ma; Signature: (ina(n); inb(n); float+ wt(n);float+[o] hist(ma,mb); double stepa; double mina; int masize => ma;
double stepb; double minb; int mbsize => mb;) double stepb; double minb; int mbsize => mb;)
skipping to change at line 1352 skipping to change at line 1347
[ 0 0.5 0.9] [ 0 0.5 0.9]
[ 0 0.1 0] [ 0 0.1 0]
] ]
=for bad =for bad
whistogram2d processes bad values. whistogram2d processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1596 "Primitive.pm" #line 1591 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*whistogram2d = \&PDL::whistogram2d; *whistogram2d = \&PDL::whistogram2d;
#line 1603 "Primitive.pm" #line 1598 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 fibonacci =head2 fibonacci
=for sig =for sig
Signature: (i(n); indx [o]x(n)) Signature: (i(n); indx [o]x(n))
=for ref =for ref
Constructor - a vector with Fibonacci's sequence Constructor - a vector with Fibonacci's sequence
=for bad =for bad
fibonacci does not process bad values. fibonacci does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1628 "Primitive.pm" #line 1623 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub fibonacci { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->fibonacci : PDL ->fibonacci(@_) } sub fibonacci { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->fibonacci : PDL ->fibonacci(@_) }
sub PDL::fibonacci{ sub PDL::fibonacci{
my $x = &PDL::Core::_construct; my $x = &PDL::Core::_construct;
my $is_inplace = $x->is_inplace; my $is_inplace = $x->is_inplace;
my ($in, $out) = $x->clump(-1); my ($in, $out) = $x->clump(-1);
$out = $is_inplace ? $in->inplace : PDL->null; $out = $is_inplace ? $in->inplace : PDL->null;
PDL::_fibonacci_int($in, $out); PDL::_fibonacci_int($in, $out);
$out; $out;
} }
#line 1643 "Primitive.pm" #line 1638 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
#line 1648 "Primitive.pm" #line 1643 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 append =head2 append
=for sig =for sig
Signature: (a(n); b(m); [o] c(mn)) Signature: (a(n); b(m); [o] c(mn))
=for ref =for ref
skipping to change at line 1429 skipping to change at line 1424
than two ndarrays along an arbitrary dimension, and than two ndarrays along an arbitrary dimension, and
L<cat|PDL::Core/cat>, which can append more than two ndarrays that all L<cat|PDL::Core/cat>, which can append more than two ndarrays that all
have the same sized dimensions. have the same sized dimensions.
=for bad =for bad
append does not process bad values. append does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1691 "Primitive.pm" #line 1686 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
#line 1632 "primitive.pd" #line 1618 "primitive.pd"
sub PDL::append { sub PDL::append {
my ($i1, $i2, $o) = map PDL->topdl($_), @_; my ($i1, $i2, $o) = map PDL->topdl($_), @_;
if (grep $_->isempty, $i1, $i2) { if (grep $_->isempty, $i1, $i2) {
if (!defined $o) { if (!defined $o) {
return $i2->isnull ? PDL->zeroes(0) : $i2->copy if $i1->isempty; return $i2->isnull ? PDL->zeroes(0) : $i2->copy if $i1->isempty;
return $i1->isnull ? PDL->zeroes(0) : $i1->copy; return $i1->isnull ? PDL->zeroes(0) : $i1->copy;
} else { } else {
$o .= $i2->isnull ? PDL->zeroes(0) : $i2, return $o if $i1->isempty; $o .= $i2->isnull ? PDL->zeroes(0) : $i2, return $o if $i1->isempty;
$o .= $i1->isnull ? PDL->zeroes(0) : $i1, return $o; $o .= $i1->isnull ? PDL->zeroes(0) : $i1, return $o;
} }
} }
$o //= PDL->null; $o //= PDL->null;
PDL::_append_int($i1, $i2->convert($i1->type), $o); PDL::_append_int($i1, $i2->convert($i1->type), $o);
$o; $o;
} }
#line 1079 "../../blib/lib/PDL/PP.pm" #line 1079 "../../blib/lib/PDL/PP.pm"
#line 1717 "Primitive.pm" #line 1712 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*append = \&PDL::append; *append = \&PDL::append;
#line 1724 "Primitive.pm" #line 1719 "Primitive.pm"
#line 1679 "primitive.pd" #line 1665 "primitive.pd"
=head2 glue =head2 glue
=for usage =for usage
$c = $x->glue(<dim>,$y,...) $c = $x->glue(<dim>,$y,...)
=for ref =for ref
Glue two or more PDLs together along an arbitrary dimension Glue two or more PDLs together along an arbitrary dimension
skipping to change at line 1536 skipping to change at line 1531
next unless(defined $y && $y->nelem); next unless(defined $y && $y->nelem);
while($dim >= $y->ndims) { while($dim >= $y->ndims) {
$y = $y->dummy(-1,1); $y = $y->dummy(-1,1);
} }
$y = $y->xchg(0,$dim); $y = $y->xchg(0,$dim);
$x = $x->append($y); $x = $x->append($y);
} }
$x->xchg(0,$dim); $x->xchg(0,$dim);
} }
#line 1805 "Primitive.pm" #line 1800 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*axisvalues = \&PDL::axisvalues; *axisvalues = \&PDL::axisvalues;
#line 1812 "Primitive.pm" #line 1807 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 srand =head2 srand
=for sig =for sig
Signature: (a()) Signature: (a())
=for ref =for ref
skipping to change at line 1568 skipping to change at line 1563
srand(); # uses current time srand(); # uses current time
srand(5); # fixed number e.g. for testing srand(5); # fixed number e.g. for testing
=for bad =for bad
srand does not process bad values. srand does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1846 "Primitive.pm" #line 1841 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
*srand = \&PDL::srand; *srand = \&PDL::srand;
sub PDL::srand { PDL::_srand_int($_[0] // PDL::Core::seed()) } sub PDL::srand { PDL::_srand_int($_[0] // PDL::Core::seed()) }
#line 1854 "Primitive.pm" #line 1849 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*srand = \&PDL::srand; *srand = \&PDL::srand;
#line 1861 "Primitive.pm" #line 1856 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 random =head2 random
=for sig =for sig
Signature: (a()) Signature: (a())
=for ref =for ref
skipping to change at line 1614 skipping to change at line 1609
You can use the PDL function L</srand> to seed the random generator. You can use the PDL function L</srand> to seed the random generator.
If it has not been called yet, it will be with the current time. If it has not been called yet, it will be with the current time.
=for bad =for bad
random does not process bad values. random does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1902 "Primitive.pm" #line 1897 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub random { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->random : PDL->rand om(@_) } sub random { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->random : PDL->rand om(@_) }
sub PDL::random { sub PDL::random {
my $class = shift; my $class = shift;
my $x = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inpla ce; my $x = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inpla ce;
PDL::_random_int($x); PDL::_random_int($x);
return $x; return $x;
} }
#line 1915 "Primitive.pm" #line 1910 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
#line 1920 "Primitive.pm" #line 1915 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 randsym =head2 randsym
=for sig =for sig
Signature: (a()) Signature: (a())
=for ref =for ref
skipping to change at line 1662 skipping to change at line 1657
You can use the PDL function L</srand> to seed the random generator. You can use the PDL function L</srand> to seed the random generator.
If it has not been called yet, it will be with the current time. If it has not been called yet, it will be with the current time.
=for bad =for bad
randsym does not process bad values. randsym does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1960 "Primitive.pm" #line 1955 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub randsym { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->randsym : PDL->ra ndsym(@_) } sub randsym { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->randsym : PDL->ra ndsym(@_) }
sub PDL::randsym { sub PDL::randsym {
my $class = shift; my $class = shift;
my $x = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inpla ce; my $x = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inpla ce;
PDL::_randsym_int($x); PDL::_randsym_int($x);
return $x; return $x;
} }
#line 1973 "Primitive.pm" #line 1968 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
#line 1978 "Primitive.pm" #line 1973 "Primitive.pm"
#line 1903 "primitive.pd" #line 1890 "primitive.pd"
=head2 grandom =head2 grandom
=for ref =for ref
Constructor which returns ndarray of Gaussian random numbers Constructor which returns ndarray of Gaussian random numbers
=for usage =for usage
$x = grandom([type], $nx, $ny, $nz,...); $x = grandom([type], $nx, $ny, $nz,...);
skipping to change at line 1710 skipping to change at line 1705
=cut =cut
sub grandom { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->grandom : PDL->gr andom(@_) } sub grandom { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->grandom : PDL->gr andom(@_) }
sub PDL::grandom { sub PDL::grandom {
my $class = shift; my $class = shift;
my $x = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inpla ce; my $x = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inpla ce;
use PDL::Math 'ndtri'; use PDL::Math 'ndtri';
$x .= ndtri(randsym($x)); $x .= ndtri(randsym($x));
return $x; return $x;
} }
#line 2014 "Primitive.pm" #line 2009 "Primitive.pm"
#line 1947 "primitive.pd" #line 1930 "primitive.pd"
=head2 vsearch =head2 vsearch
=for sig =for sig
Signature: ( vals(); xs(n); [o] indx(); [\%options] ) Signature: ( vals(); xs(n); [o] indx(); [\%options] )
=for ref =for ref
Efficiently search for values in a sorted ndarray, returning indices. Efficiently search for values in a sorted ndarray, returning indices.
skipping to change at line 1858 skipping to change at line 1853
$mode eq 'sample' ? \&vsearch_sample $mode eq 'sample' ? \&vsearch_sample
: $mode eq 'insert_leftmost' ? \&vsearch_insert_leftmost : $mode eq 'insert_leftmost' ? \&vsearch_insert_leftmost
: $mode eq 'insert_rightmost' ? \&vsearch_insert_rightmost : $mode eq 'insert_rightmost' ? \&vsearch_insert_rightmost
: $mode eq 'match' ? \&vsearch_match : $mode eq 'match' ? \&vsearch_match
: $mode eq 'bin_inclusive' ? \&vsearch_bin_inclusive : $mode eq 'bin_inclusive' ? \&vsearch_bin_inclusive
: $mode eq 'bin_exclusive' ? \&vsearch_bin_exclusive : $mode eq 'bin_exclusive' ? \&vsearch_bin_exclusive
: croak( "unknown vsearch mode: $mode\n" ); : croak( "unknown vsearch mode: $mode\n" );
} }
*PDL::vsearch = \&vsearch; *PDL::vsearch = \&vsearch;
#line 2165 "Primitive.pm" #line 2160 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 vsearch_sample =head2 vsearch_sample
=for sig =for sig
Signature: (vals(); x(n); indx [o]idx()) Signature: (vals(); x(n); indx [o]idx())
=for ref =for ref
skipping to change at line 1926 skipping to change at line 1921
$c = vsearch_sample($y, $x); # Now, $c will have the appropriate distr. $c = vsearch_sample($y, $x); # Now, $c will have the appropriate distr.
It is possible to use the L<cumusumover|PDL::Ufunc/cumusumover> It is possible to use the L<cumusumover|PDL::Ufunc/cumusumover>
function to obtain cumulative probabilities from absolute probabilities. function to obtain cumulative probabilities from absolute probabilities.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2259 "Primitive.pm" #line 2254 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*vsearch_sample = \&PDL::vsearch_sample; *vsearch_sample = \&PDL::vsearch_sample;
#line 2266 "Primitive.pm" #line 2261 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 vsearch_insert_leftmost =head2 vsearch_insert_leftmost
=for sig =for sig
Signature: (vals(); x(n); indx [o]idx()) Signature: (vals(); x(n); indx [o]idx())
=for ref =for ref
skipping to change at line 1995 skipping to change at line 1990
i = 0 i = 0
If C<$x> contains duplicated elements, I<I> is the index of the If C<$x> contains duplicated elements, I<I> is the index of the
leftmost (by index in array) duplicate if I<V> matches. leftmost (by index in array) duplicate if I<V> matches.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2356 "Primitive.pm" #line 2351 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*vsearch_insert_leftmost = \&PDL::vsearch_insert_leftmost; *vsearch_insert_leftmost = \&PDL::vsearch_insert_leftmost;
#line 2363 "Primitive.pm" #line 2358 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 vsearch_insert_rightmost =head2 vsearch_insert_rightmost
=for sig =for sig
Signature: (vals(); x(n); indx [o]idx()) Signature: (vals(); x(n); indx [o]idx())
=for ref =for ref
skipping to change at line 2064 skipping to change at line 2059
i = $x->nelem - 1 i = $x->nelem - 1
If C<$x> contains duplicated elements, I<I> is the index of the If C<$x> contains duplicated elements, I<I> is the index of the
leftmost (by index in array) duplicate if I<V> matches. leftmost (by index in array) duplicate if I<V> matches.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2453 "Primitive.pm" #line 2448 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*vsearch_insert_rightmost = \&PDL::vsearch_insert_rightmost; *vsearch_insert_rightmost = \&PDL::vsearch_insert_rightmost;
#line 2460 "Primitive.pm" #line 2455 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 vsearch_match =head2 vsearch_match
=for sig =for sig
Signature: (vals(); x(n); indx [o]idx()) Signature: (vals(); x(n); indx [o]idx())
=for ref =for ref
skipping to change at line 2102 skipping to change at line 2097
index of that element, otherwise it is I<-( insertion_point + 1 )>, index of that element, otherwise it is I<-( insertion_point + 1 )>,
where I<insertion_point> is an index in C<$x> where I<V> may be where I<insertion_point> is an index in C<$x> where I<V> may be
inserted while maintaining the order in C<$x>. If C<$x> has inserted while maintaining the order in C<$x>. If C<$x> has
duplicated values, I<I> may refer to any of them. duplicated values, I<I> may refer to any of them.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2508 "Primitive.pm" #line 2503 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*vsearch_match = \&PDL::vsearch_match; *vsearch_match = \&PDL::vsearch_match;
#line 2515 "Primitive.pm" #line 2510 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 vsearch_bin_inclusive =head2 vsearch_bin_inclusive
=for sig =for sig
Signature: (vals(); x(n); indx [o]idx()) Signature: (vals(); x(n); indx [o]idx())
=for ref =for ref
skipping to change at line 2169 skipping to change at line 2164
i = $x->nelem - 1 i = $x->nelem - 1
If C<$x> contains duplicated elements, I<I> is the index of the If C<$x> contains duplicated elements, I<I> is the index of the
righmost (by index in array) duplicate if I<V> matches. righmost (by index in array) duplicate if I<V> matches.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2603 "Primitive.pm" #line 2598 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*vsearch_bin_inclusive = \&PDL::vsearch_bin_inclusive; *vsearch_bin_inclusive = \&PDL::vsearch_bin_inclusive;
#line 2610 "Primitive.pm" #line 2605 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 vsearch_bin_exclusive =head2 vsearch_bin_exclusive
=for sig =for sig
Signature: (vals(); x(n); indx [o]idx()) Signature: (vals(); x(n); indx [o]idx())
=for ref =for ref
skipping to change at line 2236 skipping to change at line 2231
i = $x->nelem - 1 i = $x->nelem - 1
If C<$x> contains duplicated elements, I<I> is the index of the If C<$x> contains duplicated elements, I<I> is the index of the
righmost (by index in array) duplicate if I<V> matches. righmost (by index in array) duplicate if I<V> matches.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2698 "Primitive.pm" #line 2693 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*vsearch_bin_exclusive = \&PDL::vsearch_bin_exclusive; *vsearch_bin_exclusive = \&PDL::vsearch_bin_exclusive;
#line 2705 "Primitive.pm" #line 2700 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 interpolate =head2 interpolate
=for sig =for sig
Signature: (xi(); x(n); y(n); [o] yi(); int [o] err()) Signature: (xi(); x(n); y(n); [o] yi(); int [o] err())
=for ref =for ref
skipping to change at line 2282 skipping to change at line 2277
See also L</interpol>, which uses the same routine, See also L</interpol>, which uses the same routine,
differing only in the handling of extrapolation - an error message differing only in the handling of extrapolation - an error message
is printed rather than returning an error ndarray. is printed rather than returning an error ndarray.
=for bad =for bad
needs major (?) work to handles bad values needs major (?) work to handles bad values
=cut =cut
#line 2753 "Primitive.pm" #line 2748 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*interpolate = \&PDL::interpolate; *interpolate = \&PDL::interpolate;
#line 2760 "Primitive.pm" #line 2755 "Primitive.pm"
#line 2623 "primitive.pd" #line 2606 "primitive.pd"
=head2 interpol =head2 interpol
=for sig =for sig
Signature: (xi(); x(n); y(n); [o] yi()) Signature: (xi(); x(n); y(n); [o] yi())
=for ref =for ref
routine for 1D linear interpolation routine for 1D linear interpolation
skipping to change at line 2317 skipping to change at line 2312
The difference occurs in the handling of out-of-bounds values; here The difference occurs in the handling of out-of-bounds values; here
an error message is printed. an error message is printed.
=cut =cut
# kept in for backwards compatability # kept in for backwards compatability
sub interpol ($$$;$) { sub interpol ($$$;$) {
my $xi = shift; my $xi = shift;
my $x = shift; my $x = shift;
my $y = shift; my $y = shift;
my $yi = @_ == 1 ? $_[0] : PDL->null;
my $yi;
if ( $#_ == 0 ) { $yi = $_[0]; }
else { $yi = PDL->null; }
interpolate( $xi, $x, $y, $yi, my $err = PDL->null ); interpolate( $xi, $x, $y, $yi, my $err = PDL->null );
print "some values had to be extrapolated\n" print "some values had to be extrapolated\n"
if any $err; if any $err;
return $yi if @_ == 0;
return $yi if $#_ == -1;
} # sub: interpol() } # sub: interpol()
*PDL::interpol = \&interpol; *PDL::interpol = \&interpol;
#line 2805 "Primitive.pm" #line 2794 "Primitive.pm"
#line 2667 "primitive.pd" #line 2644 "primitive.pd"
=head2 interpND =head2 interpND
=for ref =for ref
Interpolate values from an N-D ndarray, with switchable method Interpolate values from an N-D ndarray, with switchable method
=for example =for example
$source = 10*xvals(10,10) + yvals(10,10); $source = 10*xvals(10,10) + yvals(10,10);
skipping to change at line 2574 skipping to change at line 2563
$mag = $mag->dummy(-1,$index->dim($i)); $mag = $mag->dummy(-1,$index->dim($i));
} }
my $out = cos($phase + $phref ) * $mag; my $out = cos($phase + $phref ) * $mag;
$out = $out->clump($source->ndims)->sumover; $out = $out->clump($source->ndims)->sumover;
return $out; return $out;
} else { } else {
barf("interpND: unknown method '$method'; valid ones are 'linear' and 'samp le'.\n"); barf("interpND: unknown method '$method'; valid ones are 'linear' and 'samp le'.\n");
} }
} }
#line 3052 "Primitive.pm" #line 3041 "Primitive.pm"
#line 2917 "primitive.pd" #line 2894 "primitive.pd"
=head2 one2nd =head2 one2nd
=for ref =for ref
Converts a one dimensional index ndarray to a set of ND coordinates Converts a one dimensional index ndarray to a set of ND coordinates
=for usage =for usage
@coords=one2nd($x, $indices) @coords=one2nd($x, $indices)
skipping to change at line 2612 skipping to change at line 2601
6 6
pdl> print one2nd($x, maximum_ind($c)) pdl> print one2nd($x, maximum_ind($c))
0 1 1 0 1 1
pdl> p $x->at(0,1,1) pdl> p $x->at(0,1,1)
3 3
=cut =cut
*one2nd = \&PDL::one2nd; *one2nd = \&PDL::one2nd;
sub PDL::one2nd { sub PDL::one2nd {
barf "Usage: one2nd \$array \$indices\n" if $#_ != 1; barf "Usage: one2nd \$array \$indices\n" if @_ != 2;
my ($x, $ind)=@_; my ($x, $ind)=@_;
my @dimension=$x->dims; my @dimension=$x->dims;
$ind = indx($ind); $ind = indx($ind);
my(@index); my(@index);
my $count=0; my $count=0;
foreach (@dimension) { foreach (@dimension) {
$index[$count++]=$ind % $_; $index[$count++]=$ind % $_;
$ind /= $_; $ind /= $_;
} }
return @index; return @index;
} }
#line 3104 "Primitive.pm" #line 3093 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 which =head2 which
=for sig =for sig
Signature: (mask(n); indx [o] inds(m)) Signature: (mask(n); indx [o] inds(m))
=for ref =for ref
skipping to change at line 2658 skipping to change at line 2647
with output from C<which>, remember to flatten it before calling index: with output from C<which>, remember to flatten it before calling index:
$data = random 5, 5; $data = random 5, 5;
$idx = which $data > 0.5; # $idx is now 1D $idx = which $data > 0.5; # $idx is now 1D
$bigsum = $data->flat->index($idx)->sum; # flatten before indexing $bigsum = $data->flat->index($idx)->sum; # flatten before indexing
Compare also L</where> for similar functionality. Compare also L</where> for similar functionality.
SEE ALSO: SEE ALSO:
L</which_both> returns separately the indices of both L</which_both> returns separately the indices of both nonzero and zero
zero and nonzero values in the mask. values in the mask.
L</where_both> returns separately slices of both nonzero and zero
values in the mask.
L</where> returns associated values from a data PDL, rather than L</where> returns associated values from a data PDL, rather than
indices into the mask PDL. indices into the mask PDL.
L</whichND> returns N-D indices into a multidimensional PDL. L</whichND> returns N-D indices into a multidimensional PDL.
=for example =for example
pdl> $x = sequence(10); p $x pdl> $x = sequence(10); p $x
[0 1 2 3 4 5 6 7 8 9] [0 1 2 3 4 5 6 7 8 9]
pdl> $indx = which($x>6); p $indx pdl> $indx = which($x>6); p $indx
[7 8 9] [7 8 9]
=for bad =for bad
which processes bad values. which processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 3167 "Primitive.pm" #line 3159 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub which { my ($this,$out) = @_; sub which { my ($this,$out) = @_;
$this = $this->flat; $this = $this->flat;
$out = $this->nullcreate unless defined $out; $out //= $this->nullcreate;
PDL::_which_int($this,$out); PDL::_which_int($this,$out);
return $out; return $out;
} }
*PDL::which = \&which; *PDL::which = \&which;
#line 3180 "Primitive.pm" #line 3172 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*which = \&PDL::which; *which = \&PDL::which;
#line 3187 "Primitive.pm" #line 3179 "Primitive.pm"
#line 1058 "../../blib/lib/PDL/PP.pm" #line 1058 "../../blib/lib/PDL/PP.pm"
=head2 which_both =head2 which_both
=for sig =for sig
Signature: (mask(n); indx [o] inds(m); indx [o]notinds(q)) Signature: (mask(n); indx [o] inds(m); indx [o]notinds(q))
=for ref =for ref
Returns indices of zero and nonzero values in a mask PDL Returns indices of nonzero and zero values in a mask PDL
=for usage =for usage
($i, $c_i) = which_both($mask); ($i, $c_i) = which_both($mask);
This works just as L</which>, but the complement of C<$i> will be in This works just as L</which>, but the complement of C<$i> will be in
C<$c_i>. C<$c_i>.
=for example =for example
pdl> $x = sequence(10); p $x pdl> p $x = sequence(10)
[0 1 2 3 4 5 6 7 8 9] [0 1 2 3 4 5 6 7 8 9]
pdl> ($small, $big) = which_both ($x >= 5); p "$small\n $big" pdl> ($big, $small) = which_both($x >= 5); p "$big\n$small"
[5 6 7 8 9] [5 6 7 8 9]
[0 1 2 3 4] [0 1 2 3 4]
=for bad =for bad
which_both processes bad values. which_both processes bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 3230 "Primitive.pm" #line 3222 "Primitive.pm"
#line 1059 "../../blib/lib/PDL/PP.pm" #line 1059 "../../blib/lib/PDL/PP.pm"
sub which_both { my ($this,$outi,$outni) = @_; sub which_both { my ($this,$outi,$outni) = @_;
$this = $this->flat; $this = $this->flat;
$outi = $this->nullcreate unless defined $outi; $outi //= $this->nullcreate;
$outni = $this->nullcreate unless defined $outni; $outni //= $this->nullcreate;
PDL::_which_both_int($this,$outi,$outni); PDL::_which_both_int($this,$outi,$outni);
return wantarray ? ($outi,$outni) : $outi; return wantarray ? ($outi,$outni) : $outi;
} }
*PDL::which_both = \&which_both; *PDL::which_both = \&which_both;
#line 3244 "Primitive.pm" #line 3236 "Primitive.pm"
#line 1060 "../../blib/lib/PDL/PP.pm" #line 1060 "../../blib/lib/PDL/PP.pm"
*which_both = \&PDL::which_both; *which_both = \&PDL::which_both;
#line 3251 "Primitive.pm" #line 3243 "Primitive.pm"
#line 3120 "primitive.pd" #line 3101 "primitive.pd"
=head2 where =head2 where
=for ref =for ref
Use a mask to select values from one or more data PDLs Use a mask to select values from one or more data PDLs
C<where> accepts one or more data ndarrays and a mask ndarray. It C<where> accepts one or more data ndarrays and a mask ndarray. It
returns a list of output ndarrays, corresponding to the input data returns a list of output ndarrays, corresponding to the input data
ndarrays. Each output ndarray is a 1-dimensional list of values in its ndarrays. Each output ndarray is a 1-dimensional list of values in its
skipping to change at line 2797 skipping to change at line 2789
Note: C<$i> is always 1-D, even if C<$x> is E<gt>1-D. Note: C<$i> is always 1-D, even if C<$x> is E<gt>1-D.
WARNING: The first argument WARNING: The first argument
(the values) and the second argument (the mask) currently have to have (the values) and the second argument (the mask) currently have to have
the exact same dimensions (or horrible things happen). You *cannot* the exact same dimensions (or horrible things happen). You *cannot*
broadcast over a smaller mask, for example. broadcast over a smaller mask, for example.
=cut =cut
sub PDL::where { sub PDL::where {
barf "Usage: where( \$pdl1, ..., \$pdlN, \$mask )\n" if $#_ == 0; barf "Usage: where( \$pdl1, ..., \$pdlN, \$mask )\n" if @_ == 1;
if(@_ == 2) {
if($#_ == 1) {
my($data,$mask) = @_; my($data,$mask) = @_;
$data = $_[0]->clump(-1) if $_[0]->getndims>1; $data = $_[0]->clump(-1) if $_[0]->getndims>1;
$mask = $_[1]->clump(-1) if $_[0]->getndims>1; $mask = $_[1]->clump(-1) if $_[0]->getndims>1;
return $data->index($mask->which()); return $data->index($mask->which());
} else { } else {
if($_[-1]->getndims > 1) { if($_[-1]->getndims > 1) {
my $mask = $_[-1]->clump(-1)->which; my $mask = $_[-1]->clump(-1)->which;
return map {$_->clump(-1)->index($mask)} @_[0..$#_-1]; return map {$_->clump(-1)->index($mask)} @_[0..$#_-1];
} else { } else {
my $mask = $_[-1]->which; my $mask = $_[-1]->which;
return map {$_->index($mask)} @_[0..$#_-1]; return map {$_->index($mask)} @_[0..$#_-1];
} }
} }
} }
*where = \&PDL::where; *where = \&PDL::where;
#line 3321 "Primitive.pm" #line 3312 "Primitive.pm"
#line 3169 "primitive.pd"
#line 3190 "primitive.pd" =head2 where_both
=for ref
Returns slices (non-zero in mask, zero) of an ndarray according to a mask
=for usage
($match_vals, $non_match_vals) = where_both($pdl, $mask);
This works like L</which_both>, but (flattened) data-flowing slices
rather than index-sets are returned.
=for example
pdl> p $x = sequence(10) + 2
[2 3 4 5 6 7 8 9 10 11]
pdl> ($big, $small) = where_both($x, $x > 5); p "$big\n$small"
[6 7 8 9 10 11]
[2 3 4 5]
pdl> p $big += 2, $small -= 1
[8 9 10 11 12 13] [1 2 3 4]
pdl> p $x
[1 2 3 4 8 9 10 11 12 13]
=cut
sub PDL::where_both {
barf "Usage: where_both(\$pdl, \$mask)\n" if @_ != 2;
my ($arr, $mask) = @_; # $mask has 0==false, 1==true
my $arr_flat = $arr->clump(-1);
map $arr_flat->index1d($_), PDL::which_both($mask);
}
*where_both = \&PDL::where_both;
#line 3352 "Primitive.pm"
#line 3207 "primitive.pd"
=head2 whereND =head2 whereND
=for ref =for ref
C<where> with support for ND masks and broadcasting C<where> with support for ND masks and broadcasting
C<whereND> accepts one or more data ndarrays and a C<whereND> accepts one or more data ndarrays and a
mask ndarray. It returns a list of output ndarrays, mask ndarray. It returns a list of output ndarrays,
corresponding to the input data ndarrays. The values corresponding to the input data ndarrays. The values
skipping to change at line 2874 skipping to change at line 2903
# Used in lvalue context: # Used in lvalue context:
$data->whereND($mask4) .= 0; $data->whereND($mask4) .= 0;
SEE ALSO: SEE ALSO:
L</whichND> returns N-D indices into a multidimensional PDL, from a mask. L</whichND> returns N-D indices into a multidimensional PDL, from a mask.
=cut =cut
sub PDL::whereND :lvalue { sub PDL::whereND :lvalue {
barf "Usage: whereND( \$pdl1, ..., \$pdlN, \$mask )\n" if $#_ == 0; barf "Usage: whereND( \$pdl1, ..., \$pdlN, \$mask )\n" if @_ == 1;
my $mask = pop @_; # $mask has 0==false, 1==true my $mask = pop @_; # $mask has 0==false, 1==true
my @to_return; my @to_return;
my $n = PDL::sum($mask); my $n = PDL::sum($mask);
foreach my $arr (@_) { foreach my $arr (@_) {
my $sub_i = $mask * ones($arr); my $sub_i = $mask * ones($arr);
my $where_sub_i = PDL::where($arr, $sub_i); my $where_sub_i = PDL::where($arr, $sub_i);
# count the number of dims in $mask and $arr # count the number of dims in $mask and $arr
# $mask = a b c d e f..... # $mask = a b c d e f.....
my @idims = dims($arr); my @idims = dims($arr);
# ...and pop off the number of dims in $mask # ...and pop off the number of dims in $mask
foreach ( dims($mask) ) { shift(@idims) }; foreach ( dims($mask) ) { shift(@idims) };
my $ndim = 0; my $ndim = 0;
foreach my $id ($n, @idims[0..($#idims-1)]) { foreach my $id ($n, @idims[0..($#idims-1)]) {
$where_sub_i = $where_sub_i->splitdim($ndim++,$id) if $n>0; $where_sub_i = $where_sub_i->splitdim($ndim++,$id) if $n>0;
} }
push @to_return, $where_sub_i; push @to_return, $where_sub_i;
} }
return (@to_return == 1) ? $to_return[0] : @to_return; return (@to_return == 1) ? $to_return[0] : @to_return;
} }
*whereND = \&PDL::whereND; *whereND = \&PDL::whereND;
#line 3412 "Primitive.pm" #line 3434 "Primitive.pm"
#line 3281 "primitive.pd" #line 3288 "primitive.pd"
=head2 whichND =head2 whichND
=for ref =for ref
Return the coordinates of non-zero values in a mask. Return the coordinates of non-zero values in a mask.
=for usage =for usage
WhichND returns the N-dimensional coordinates of each nonzero value in WhichND returns the N-dimensional coordinates of each nonzero value in
skipping to change at line 3009 skipping to change at line 3029
} }
for my $i (0..$#mdims) { for my $i (0..$#mdims) {
my($s) = $ind->index($i); my($s) = $ind->index($i);
$s /= $mult->index($i); $s /= $mult->index($i);
$s %= $mdims[$i]; $s %= $mdims[$i];
} }
return $ind; return $ind;
} }
#line 3520 "Primitive.pm" #line 3541 "Primitive.pm"
#line 3394 "primitive.pd" #line 3397 "primitive.pd"
=head2 setops =head2 setops
=for ref =for ref
Implements simple set operations like union and intersection Implements simple set operations like union and intersection
=for usage =for usage
Usage: $set = setops($x, <OPERATOR>, $y); Usage: $set = setops($x, <OPERATOR>, $y);
skipping to change at line 3191 skipping to change at line 3211
# Make ordered list of set union. # Make ordered list of set union.
my $union = append($x, $y)->qsort; my $union = append($x, $y)->qsort;
return $union->where($union == rotate($union, -1)); return $union->where($union == rotate($union, -1));
} else { } else {
print "The operation $op is not known!"; print "The operation $op is not known!";
return -1; return -1;
} }
} }
#line 3705 "Primitive.pm" #line 3726 "Primitive.pm"
#line 3578 "primitive.pd" #line 3580 "primitive.pd"
=head2 intersect =head2 intersect
=for ref =for ref
Calculate the intersection of two ndarrays Calculate the intersection of two ndarrays
=for usage =for usage
Usage: $set = intersect($x, $y); Usage: $set = intersect($x, $y);
skipping to change at line 3228 skipping to change at line 3248
=cut =cut
*intersect = \&PDL::intersect; *intersect = \&PDL::intersect;
sub PDL::intersect { sub PDL::intersect {
return setops($_[0], 'AND', $_[1]); return setops($_[0], 'AND', $_[1]);
} }
#line 3744 "Primitive.pm" #line 3765 "Primitive.pm"
#line 3617 "primitive.pd" #line 3616 "primitive.pd"
=head1 AUTHOR =head1 AUTHOR
Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu). Contributions Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu). Contributions
by Christian Soeller (c.soeller@auckland.ac.nz), Karl Glazebrook by Christian Soeller (c.soeller@auckland.ac.nz), Karl Glazebrook
(kgb@aaoepp.aao.gov.au), Craig DeForest (deforest@boulder.swri.edu) (kgb@aaoepp.aao.gov.au), Craig DeForest (deforest@boulder.swri.edu)
and Jarle Brinchmann (jarle@astro.up.pt) and Jarle Brinchmann (jarle@astro.up.pt)
All rights reserved. There is no warranty. You are allowed All rights reserved. There is no warranty. You are allowed
to redistribute this software / documentation under certain to redistribute this software / documentation under certain
conditions. For details, see the file COPYING in the PDL conditions. For details, see the file COPYING in the PDL
distribution. If this file is separated from the PDL distribution, distribution. If this file is separated from the PDL distribution,
the copyright notice should be included in the file. the copyright notice should be included in the file.
Updated for CPAN viewing compatibility by David Mertens. Updated for CPAN viewing compatibility by David Mertens.
=cut =cut
#line 3768 "Primitive.pm" #line 3789 "Primitive.pm"
# Exit with OK status # Exit with OK status
1; 1;
 End of changes. 120 change blocks. 
135 lines changed or deleted 155 lines changed or added

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