Primitive.pm (PDL-2.081) | : | Primitive.pm (PDL-2.082) | ||
---|---|---|---|---|
skipping to change at line 60 | skipping to change at line 60 | |||
# Only pull in PDL::Primitive: | # Only pull in PDL::Primitive: | |||
use PDL::Primitive; | use PDL::Primitive; | |||
=cut | =cut | |||
#line 62 "Primitive.pm" | #line 62 "Primitive.pm" | |||
=head1 FUNCTIONS | =head1 FUNCTIONS | |||
=cut | =cut | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 inner | =head2 inner | |||
=for sig | =for sig | |||
Signature: (a(n); b(n); [o]c()) | Signature: (a(n); b(n); [o]c()) | |||
=for ref | =for ref | |||
Inner product over one dimension | Inner product over one dimension | |||
skipping to change at line 85 | skipping to change at line 85 | |||
=for bad | =for bad | |||
If C<a() * b()> contains only bad data, | If C<a() * b()> contains only bad data, | |||
C<c()> is set bad. Otherwise C<c()> will have its bad flag cleared, | C<c()> is set bad. Otherwise C<c()> will have its bad flag cleared, | |||
as it will not contain any bad values. | as it will not contain any bad values. | |||
=cut | =cut | |||
#line 104 "Primitive.pm" | #line 104 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*inner = \&PDL::inner; | *inner = \&PDL::inner; | |||
#line 111 "Primitive.pm" | #line 111 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 outer | =head2 outer | |||
=for sig | =for sig | |||
Signature: (a(n); b(m); [o]c(n,m)) | Signature: (a(n); b(m); [o]c(n,m)) | |||
=for ref | =for ref | |||
outer product over one dimension | outer product over one dimension | |||
skipping to change at line 114 | skipping to change at line 114 | |||
operator but this function is provided for convenience. | operator but this function is provided for convenience. | |||
=for bad | =for bad | |||
outer processes bad values. | outer 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 142 "Primitive.pm" | #line 142 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*outer = \&PDL::outer; | *outer = \&PDL::outer; | |||
#line 149 "Primitive.pm" | #line 149 "Primitive.pm" | |||
#line 105 "primitive.pd" | #line 105 "primitive.pd" | |||
=head2 x | =head2 x | |||
=for sig | =for sig | |||
skipping to change at line 212 | skipping to change at line 212 | |||
] | ] | |||
INTERNALS | INTERNALS | |||
The mechanics of the multiplication are carried out by the | The mechanics of the multiplication are carried out by the | |||
L</matmult> method. | L</matmult> method. | |||
=cut | =cut | |||
#line 244 "Primitive.pm" | #line 244 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 matmult | =head2 matmult | |||
=for sig | =for sig | |||
Signature: (a(t,h); b(w,t); [o]c(w,h)) | Signature: (a(t,h); b(w,t); [o]c(w,h)) | |||
=for ref | =for ref | |||
Matrix multiplication | Matrix multiplication | |||
skipping to change at line 243 | skipping to change at line 243 | |||
For usage, see L</x>, a description of the overloaded 'x' operator | For usage, see L</x>, a description of the overloaded 'x' operator | |||
=for bad | =for bad | |||
matmult ignores the bad-value flag of the input ndarrays. | matmult 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 282 "Primitive.pm" | #line 282 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::matmult { | sub PDL::matmult { | |||
my ($x,$y,$c) = @_; | my ($x,$y,$c) = @_; | |||
$y = PDL->topdl($y); | $y = PDL->topdl($y); | |||
$c = PDL->null unless do { local $@; eval { $c->isa('PDL') } }; | $c = PDL->null unless do { local $@; eval { $c->isa('PDL') } }; | |||
while($x->getndims < 2) {$x = $x->dummy(-1)} | while($x->getndims < 2) {$x = $x->dummy(-1)} | |||
while($y->getndims < 2) {$y = $y->dummy(-1)} | while($y->getndims < 2) {$y = $y->dummy(-1)} | |||
return ($c .= $x * $y) if( ($x->dim(0)==1 && $x->dim(1)==1) || | return ($c .= $x * $y) if( ($x->dim(0)==1 && $x->dim(1)==1) || | |||
($y->dim(0)==1 && $y->dim(1)==1) ); | ($y->dim(0)==1 && $y->dim(1)==1) ); | |||
barf sprintf 'Dim mismatch in matmult of [%1$dx%2$d] x [%3$dx%4$d]: %1$d != %4$d',$x->dim(0),$x->dim(1),$y->dim(0),$y->dim(1) | barf sprintf 'Dim mismatch in matmult of [%1$dx%2$d] x [%3$dx%4$d]: %1$d != %4$d',$x->dim(0),$x->dim(1),$y->dim(0),$y->dim(1) | |||
if $y->dim(1) != $x->dim(0); | if $y->dim(1) != $x->dim(0); | |||
PDL::_matmult_int($x,$y,$c); | PDL::_matmult_int($x,$y,$c); | |||
$c; | $c; | |||
} | } | |||
#line 301 "Primitive.pm" | #line 301 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*matmult = \&PDL::matmult; | *matmult = \&PDL::matmult; | |||
#line 308 "Primitive.pm" | #line 308 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 innerwt | =head2 innerwt | |||
=for sig | =for sig | |||
Signature: (a(n); b(n); c(n); [o]d()) | Signature: (a(n); b(n); c(n); [o]d()) | |||
=for ref | =for ref | |||
Weighted (i.e. triple) inner product | Weighted (i.e. triple) inner product | |||
skipping to change at line 287 | skipping to change at line 287 | |||
d = sum_i a(i) b(i) c(i) | d = sum_i a(i) b(i) c(i) | |||
=for bad | =for bad | |||
innerwt processes bad values. | innerwt 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 339 "Primitive.pm" | #line 339 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*innerwt = \&PDL::innerwt; | *innerwt = \&PDL::innerwt; | |||
#line 346 "Primitive.pm" | #line 346 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 inner2 | =head2 inner2 | |||
=for sig | =for sig | |||
Signature: (a(n); b(n,m); c(m); [o]d()) | Signature: (a(n); b(n,m); c(m); [o]d()) | |||
=for ref | =for ref | |||
Inner product of two vectors and a matrix | Inner product of two vectors and a matrix | |||
skipping to change at line 317 | skipping to change at line 317 | |||
very wasteful. Instead, you should use a temporary for C<b*c>. | very wasteful. Instead, you should use a temporary for C<b*c>. | |||
=for bad | =for bad | |||
inner2 processes bad values. | inner2 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 378 "Primitive.pm" | #line 378 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*inner2 = \&PDL::inner2; | *inner2 = \&PDL::inner2; | |||
#line 385 "Primitive.pm" | #line 385 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 inner2d | =head2 inner2d | |||
=for sig | =for sig | |||
Signature: (a(n,m); b(n,m); [o]c()) | Signature: (a(n,m); b(n,m); [o]c()) | |||
=for ref | =for ref | |||
Inner product over 2 dimensions. | Inner product over 2 dimensions. | |||
skipping to change at line 346 | skipping to change at line 346 | |||
$c = inner($x->clump(2), $y->clump(2)) | $c = inner($x->clump(2), $y->clump(2)) | |||
=for bad | =for bad | |||
inner2d processes bad values. | inner2d 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 418 "Primitive.pm" | #line 418 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*inner2d = \&PDL::inner2d; | *inner2d = \&PDL::inner2d; | |||
#line 425 "Primitive.pm" | #line 425 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 inner2t | =head2 inner2t | |||
=for sig | =for sig | |||
Signature: (a(j,n); b(n,m); c(m,k); [t]tmp(n,k); [o]d(j,k))) | Signature: (a(j,n); b(n,m); c(m,k); [t]tmp(n,k); [o]d(j,k))) | |||
=for ref | =for ref | |||
Efficient Triple matrix product C<a*b*c> | Efficient Triple matrix product C<a*b*c> | |||
skipping to change at line 383 | skipping to change at line 383 | |||
closures at some point. | closures at some point. | |||
=for bad | =for bad | |||
inner2t processes bad values. | inner2t 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 465 "Primitive.pm" | #line 465 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*inner2t = \&PDL::inner2t; | *inner2t = \&PDL::inner2t; | |||
#line 472 "Primitive.pm" | #line 472 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 crossp | =head2 crossp | |||
=for sig | =for sig | |||
Signature: (a(tri=3); b(tri); [o] c(tri)) | Signature: (a(tri=3); b(tri); [o] c(tri)) | |||
=for ref | =for ref | |||
Cross product of two 3D vectors | Cross product of two 3D vectors | |||
skipping to change at line 417 | skipping to change at line 417 | |||
orthogonal to C<$x> and C<$y> | orthogonal to C<$x> and C<$y> | |||
=for bad | =for bad | |||
crossp does not process bad values. | crossp 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 509 "Primitive.pm" | #line 509 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*crossp = \&PDL::crossp; | *crossp = \&PDL::crossp; | |||
#line 516 "Primitive.pm" | #line 516 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 norm | =head2 norm | |||
=for sig | =for sig | |||
Signature: (vec(n); [o] norm(n)) | Signature: (vec(n); [o] norm(n)) | |||
=for ref | =for ref | |||
Normalises a vector to unit Euclidean length | Normalises a vector to unit Euclidean length | |||
=for bad | =for bad | |||
norm processes bad values. | norm 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 541 "Primitive.pm" | #line 541 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*norm = \&PDL::norm; | *norm = \&PDL::norm; | |||
#line 548 "Primitive.pm" | #line 548 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 indadd | =head2 indadd | |||
=for sig | =for sig | |||
Signature: (input(n); indx ind(n); [io] sum(m)) | Signature: (input(n); indx ind(n); [io] sum(m)) | |||
=for ref | =for ref | |||
Broadcasting index add: add C<input> to the C<ind> element of C<sum>, i.e: | Broadcasting index add: add C<input> to the C<ind> element of C<sum>, i.e: | |||
skipping to change at line 492 | skipping to change at line 492 | |||
=for bad | =for bad | |||
=for bad | =for bad | |||
The routine barfs on bad indices, and bad inputs set target outputs bad. | The routine barfs on bad indices, and bad inputs set target outputs bad. | |||
=cut | =cut | |||
#line 602 "Primitive.pm" | #line 602 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*indadd = \&PDL::indadd; | *indadd = \&PDL::indadd; | |||
#line 609 "Primitive.pm" | #line 609 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 conv1d | =head2 conv1d | |||
=for sig | =for sig | |||
Signature: (a(m); kern(p); [o]b(m); int reflect) | Signature: (a(m); kern(p); [o]b(m); int reflect) | |||
=for ref | =for ref | |||
1D convolution along first dimension | 1D convolution along first dimension | |||
skipping to change at line 563 | skipping to change at line 563 | |||
unless special care is taken. | unless special care is taken. | |||
=for bad | =for bad | |||
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 684 "Primitive.pm" | #line 684 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::conv1d { | sub PDL::conv1d { | |||
my $opt = pop @_ if ref($_[-1]) 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 @_<2 || @_>3; | if @_<2 || @_>3; | |||
my($x,$kern) = @_; | my($x,$kern) = @_; | |||
my $c = @_ == 3 ? $_[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 703 "Primitive.pm" | #line 703 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*conv1d = \&PDL::conv1d; | *conv1d = \&PDL::conv1d; | |||
#line 710 "Primitive.pm" | #line 710 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 in | =head2 in | |||
=for sig | =for sig | |||
Signature: (a(); b(n); [o] c()) | Signature: (a(); b(n); [o] c()) | |||
=for ref | =for ref | |||
test if a is in the set of values b | test if a is in the set of values b | |||
skipping to change at line 618 | skipping to change at line 618 | |||
and is generally faster. | and is generally faster. | |||
=for bad | =for bad | |||
in does not process bad values. | in 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 753 "Primitive.pm" | #line 753 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*in = \&PDL::in; | *in = \&PDL::in; | |||
#line 760 "Primitive.pm" | #line 760 "Primitive.pm" | |||
#line 698 "primitive.pd" | #line 698 "primitive.pd" | |||
=head2 uniq | =head2 uniq | |||
=for ref | =for ref | |||
skipping to change at line 666 | skipping to change at line 666 | |||
print $x->uniq; | print $x->uniq; | |||
[0 3 6 9] | [0 3 6 9] | |||
=cut | =cut | |||
*uniq = \&PDL::uniq; | *uniq = \&PDL::uniq; | |||
# return unique elements of array | # return unique elements of array | |||
# find as jumps in the sorted array | # find as jumps in the sorted array | |||
# flattens in the process | # flattens in the process | |||
sub PDL::uniq { | sub PDL::uniq { | |||
use PDL::Core 'barf'; | ||||
my ($arr) = @_; | my ($arr) = @_; | |||
return $arr if($arr->nelem == 0); # The null list is unique (CED) | return $arr if($arr->nelem == 0); # The null list is unique (CED) | |||
my $srt = $arr->clump(-1)->where($arr==$arr)->qsort; # no NaNs or BADs for | return $arr->flat if($arr->nelem == 1); # singleton list is unique | |||
qsort | my $aflat = $arr->flat; | |||
my $nans = $arr->clump(-1)->where($arr!=$arr); | my $srt = $aflat->where($aflat==$aflat)->qsort; # no NaNs or BADs for qsort | |||
my $uniq = ($srt->nelem > 0) ? $srt->where($srt != $srt->rotate(-1)) : $srt; | my $nans = $aflat->where($aflat!=$aflat); | |||
my $uniq = ($srt->nelem > 1) ? $srt->where($srt != $srt->rotate(-1)) : $srt; | ||||
# make sure we return something if there is only one value | # make sure we return something if there is only one value | |||
my $answ = $nans; # NaN values always uniq | ( | |||
if ( $uniq->nelem > 0 ) { | $uniq->nelem > 0 ? $uniq : | |||
$answ = $uniq->append($answ); | $srt->nelem == 0 ? $srt : | |||
} else { | PDL::pdl( ref($srt), [$srt->index(0)] ) | |||
$answ = ( ($srt->nelem == 0) ? $srt : PDL::pdl( ref($srt), [$srt->index(0 | )->append($nans); | |||
)] ) )->append($answ); | ||||
} | ||||
return $answ; | ||||
} | } | |||
#line 822 "Primitive.pm" | #line 821 "Primitive.pm" | |||
#line 758 "primitive.pd" | #line 757 "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 745 | skipping to change at line 744 | |||
} | } | |||
# Now map back to the original space | # Now map back to the original space | |||
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 889 "Primitive.pm" | #line 888 "Primitive.pm" | |||
#line 824 "primitive.pd" | #line 823 "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 816 | skipping to change at line 815 | |||
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 962 "Primitive.pm" | #line 961 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 987 "Primitive.pm" | #line 986 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 (@_ > 2) {$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 1002 "Primitive.pm" | #line 1001 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*hclip = \&PDL::hclip; | *hclip = \&PDL::hclip; | |||
#line 1009 "Primitive.pm" | #line 1008 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 1034 "Primitive.pm" | #line 1033 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 (@_ > 2) {$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 1049 "Primitive.pm" | #line 1048 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*lclip = \&PDL::lclip; | *lclip = \&PDL::lclip; | |||
#line 1056 "Primitive.pm" | #line 1055 "Primitive.pm" | |||
#line 934 "primitive.pd" | #line 933 "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 1080 "Primitive.pm" | #line 1079 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 1107 "Primitive.pm" | #line 1106 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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; | |||
skipping to change at line 971 | skipping to change at line 970 | |||
} 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 1146 "Primitive.pm" | #line 1145 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*clip = \&PDL::clip; | *clip = \&PDL::clip; | |||
#line 1153 "Primitive.pm" | #line 1152 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Weighted statistical moment of given degree | Weighted statistical moment of given degree | |||
skipping to change at line 1003 | skipping to change at line 1002 | |||
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 1187 "Primitive.pm" | #line 1186 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*wtstat = \&PDL::wtstat; | *wtstat = \&PDL::wtstat; | |||
#line 1194 "Primitive.pm" | #line 1193 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Calculate useful statistics over a dimension of an ndarray | Calculate useful statistics over a dimension of an ndarray | |||
skipping to change at line 1080 | skipping to change at line 1079 | |||
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 1275 "Primitive.pm" | #line 1274 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 @_>2; | barf('Usage: ($mean,[$prms, $median, $min, $max, $adev, $rms]) = statsover($d ata,[$weights])') if @_>2; | |||
my ($data, $weights) = @_; | my ($data, $weights) = @_; | |||
$weights //= $data->ones(); | $weights //= $data->ones(); | |||
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); | |||
wantarray ? ($mean, $prms, $median, $min, $max, $adev, $rms) : $mean; | wantarray ? ($mean, $prms, $median, $min, $max, $adev, $rms) : $mean; | |||
} | } | |||
#line 1296 "Primitive.pm" | #line 1295 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*statsover = \&PDL::statsover; | *statsover = \&PDL::statsover; | |||
#line 1303 "Primitive.pm" | #line 1302 "Primitive.pm" | |||
#line 1185 "primitive.pd" | #line 1184 "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 1149 | skipping to change at line 1148 | |||
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 1351 "Primitive.pm" | #line 1350 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Calculates a histogram for given stepsize and minimum. | Calculates a histogram for given stepsize and minimum. | |||
skipping to change at line 1193 | skipping to change at line 1192 | |||
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 1403 "Primitive.pm" | #line 1402 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*histogram = \&PDL::histogram; | *histogram = \&PDL::histogram; | |||
#line 1410 "Primitive.pm" | #line 1409 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Calculates a histogram from weighted data for given stepsize and minimum. | Calculates a histogram from weighted data for given stepsize and minimum. | |||
skipping to change at line 1240 | skipping to change at line 1239 | |||
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 1459 "Primitive.pm" | #line 1458 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*whistogram = \&PDL::whistogram; | *whistogram = \&PDL::whistogram; | |||
#line 1466 "Primitive.pm" | #line 1465 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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;) | |||
=for ref | =for ref | |||
skipping to change at line 1292 | skipping to change at line 1291 | |||
[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 1520 "Primitive.pm" | #line 1519 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*histogram2d = \&PDL::histogram2d; | *histogram2d = \&PDL::histogram2d; | |||
#line 1527 "Primitive.pm" | #line 1526 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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;) | |||
=for ref | =for ref | |||
skipping to change at line 1344 | skipping to change at line 1343 | |||
[ 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 1581 "Primitive.pm" | #line 1580 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*whistogram2d = \&PDL::whistogram2d; | *whistogram2d = \&PDL::whistogram2d; | |||
#line 1588 "Primitive.pm" | #line 1587 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 1613 "Primitive.pm" | #line 1612 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 1628 "Primitive.pm" | #line 1627 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
#line 1633 "Primitive.pm" | #line 1632 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
append two ndarrays by concatenating along their first dimensions | append two ndarrays by concatenating along their first dimensions | |||
skipping to change at line 1421 | skipping to change at line 1420 | |||
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 1676 "Primitive.pm" | #line 1675 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
#line 1497 "primitive.pd" | #line 1496 "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 970 "../../blib/lib/PDL/PP.pm" | #line 1700 "Primitive.pm" | |||
#line 1702 "Primitive.pm" | #line 1701 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*append = \&PDL::append; | *append = \&PDL::append; | |||
#line 1709 "Primitive.pm" | #line 1708 "Primitive.pm" | |||
#line 1544 "primitive.pd" | #line 1543 "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 1525 | skipping to change at line 1524 | |||
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 1787 "Primitive.pm" | #line 1786 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*axisvalues = \&PDL::axisvalues; | *axisvalues = \&PDL::axisvalues; | |||
#line 1794 "Primitive.pm" | #line 1793 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 cmpvec | =head2 cmpvec | |||
=for sig | =for sig | |||
Signature: (a(n); b(n); sbyte [o]c()) | Signature: (a(n); b(n); sbyte [o]c()) | |||
=for ref | =for ref | |||
Compare two vectors lexicographically. | Compare two vectors lexicographically. | |||
Returns -1 if a is less, 1 if greater, 0 if equal. | Returns -1 if a is less, 1 if greater, 0 if equal. | |||
=for bad | =for bad | |||
The output is bad if any input values up to the point of inequality are | The output is bad if any input values up to the point of inequality are | |||
bad - any after are ignored. | bad - any after are ignored. | |||
=cut | =cut | |||
#line 1823 "Primitive.pm" | #line 1822 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*cmpvec = \&PDL::cmpvec; | *cmpvec = \&PDL::cmpvec; | |||
#line 1830 "Primitive.pm" | #line 1829 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 eqvec | =head2 eqvec | |||
=for sig | =for sig | |||
Signature: (a(n); b(n); sbyte [o]c()) | Signature: (a(n); b(n); sbyte [o]c()) | |||
=for ref | =for ref | |||
Compare two vectors, returning 1 if equal, 0 if not equal. | Compare two vectors, returning 1 if equal, 0 if not equal. | |||
=for bad | =for bad | |||
The output is bad if any input values are bad. | The output is bad if any input values are bad. | |||
=cut | =cut | |||
#line 1855 "Primitive.pm" | #line 1854 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*eqvec = \&PDL::eqvec; | *eqvec = \&PDL::eqvec; | |||
#line 1862 "Primitive.pm" | #line 1861 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 enumvec | =head2 enumvec | |||
=for sig | =for sig | |||
Signature: (v(M,N); indx [o]k(N)) | Signature: (v(M,N); indx [o]k(N)) | |||
=for ref | =for ref | |||
Enumerate a list of vectors with locally unique keys. | Enumerate a list of vectors with locally unique keys. | |||
skipping to change at line 1610 | skipping to change at line 1609 | |||
If you need global keys, see enumvecg(). | If you need global keys, see enumvecg(). | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
enumvec does not process bad values. | enumvec 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 1897 "Primitive.pm" | #line 1896 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*enumvec = \&PDL::enumvec; | *enumvec = \&PDL::enumvec; | |||
#line 1904 "Primitive.pm" | #line 1903 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 enumvecg | =head2 enumvecg | |||
=for sig | =for sig | |||
Signature: (v(M,N); indx [o]k(N)) | Signature: (v(M,N); indx [o]k(N)) | |||
=for ref | =for ref | |||
Enumerate a list of vectors with globally unique keys. | Enumerate a list of vectors with globally unique keys. | |||
skipping to change at line 1645 | skipping to change at line 1644 | |||
... but somewhat more efficiently. | ... but somewhat more efficiently. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
enumvecg does not process bad values. | enumvecg 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 1940 "Primitive.pm" | #line 1939 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*enumvecg = \&PDL::enumvecg; | *enumvecg = \&PDL::enumvecg; | |||
#line 1947 "Primitive.pm" | #line 1946 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 vsearchvec | =head2 vsearchvec | |||
=for sig | =for sig | |||
Signature: (find(M); which(M,N); indx [o]found()) | Signature: (find(M); which(M,N); indx [o]found()) | |||
=for ref | =for ref | |||
Routine for searching N-dimensional values - akin to vsearch() for vectors. | Routine for searching N-dimensional values - akin to vsearch() for vectors. | |||
skipping to change at line 1686 | skipping to change at line 1685 | |||
See also: L</vsearch>. | See also: L</vsearch>. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
vsearchvec does not process bad values. | vsearchvec 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 1989 "Primitive.pm" | #line 1988 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearchvec = \&PDL::vsearchvec; | *vsearchvec = \&PDL::vsearchvec; | |||
#line 1996 "Primitive.pm" | #line 1995 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 unionvec | =head2 unionvec | |||
=for sig | =for sig | |||
Signature: (a(M,NA); b(M,NB); [o]c(M,NC); indx [o]nc()) | Signature: (a(M,NA); b(M,NB); [o]c(M,NC); indx [o]nc()) | |||
=for ref | =for ref | |||
Union of two vector-valued PDLs. | Union of two vector-valued PDLs. | |||
skipping to change at line 1719 | skipping to change at line 1718 | |||
and returns the sliced PDL. | and returns the sliced PDL. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
unionvec does not process bad values. | unionvec 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 2030 "Primitive.pm" | #line 2029 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::unionvec { | sub PDL::unionvec { | |||
my ($a,$b,$c,$nc) = @_; | my ($a,$b,$c,$nc) = @_; | |||
$c = PDL->null if (!defined($nc)); | $c = PDL->null if (!defined($nc)); | |||
$nc = PDL->null if (!defined($nc)); | $nc = PDL->null if (!defined($nc)); | |||
PDL::_unionvec_int($a,$b,$c,$nc); | PDL::_unionvec_int($a,$b,$c,$nc); | |||
return ($c,$nc) if (wantarray); | return ($c,$nc) if (wantarray); | |||
return $c->slice(",0:".($nc->max-1)); | return $c->slice(",0:".($nc->max-1)); | |||
} | } | |||
#line 2045 "Primitive.pm" | #line 2044 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*unionvec = \&PDL::unionvec; | *unionvec = \&PDL::unionvec; | |||
#line 2052 "Primitive.pm" | #line 2051 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 intersectvec | =head2 intersectvec | |||
=for sig | =for sig | |||
Signature: (a(M,NA); b(M,NB); [o]c(M,NC); indx [o]nc()) | Signature: (a(M,NA); b(M,NB); [o]c(M,NC); indx [o]nc()) | |||
=for ref | =for ref | |||
Intersection of two vector-valued PDLs. | Intersection of two vector-valued PDLs. | |||
skipping to change at line 1763 | skipping to change at line 1762 | |||
and returns the sliced PDL. | and returns the sliced PDL. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
intersectvec does not process bad values. | intersectvec 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 2085 "Primitive.pm" | #line 2084 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::intersectvec { | sub PDL::intersectvec { | |||
my ($a,$b,$c,$nc) = @_; | my ($a,$b,$c,$nc) = @_; | |||
$c = PDL->null if (!defined($c)); | $c = PDL->null if (!defined($c)); | |||
$nc = PDL->null if (!defined($nc)); | $nc = PDL->null if (!defined($nc)); | |||
PDL::_intersectvec_int($a,$b,$c,$nc); | PDL::_intersectvec_int($a,$b,$c,$nc); | |||
return ($c,$nc) if (wantarray); | return ($c,$nc) if (wantarray); | |||
my $nc_max = $nc->max; | my $nc_max = $nc->max; | |||
return ($nc_max > 0 | return ($nc_max > 0 | |||
? $c->slice(",0:".($nc_max-1)) | ? $c->slice(",0:".($nc_max-1)) | |||
: $c->reshape($c->dim(0), 0, ($c->dims)[2..($c->ndims-1)])); | : $c->reshape($c->dim(0), 0, ($c->dims)[2..($c->ndims-1)])); | |||
} | } | |||
#line 2103 "Primitive.pm" | #line 2102 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*intersectvec = \&PDL::intersectvec; | *intersectvec = \&PDL::intersectvec; | |||
#line 2110 "Primitive.pm" | #line 2109 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 setdiffvec | =head2 setdiffvec | |||
=for sig | =for sig | |||
Signature: (a(M,NA); b(M,NB); [o]c(M,NC); indx [o]nc()) | Signature: (a(M,NA); b(M,NB); [o]c(M,NC); indx [o]nc()) | |||
=for ref | =for ref | |||
Set-difference ($a() \ $b()) of two vector-valued PDLs. | Set-difference ($a() \ $b()) of two vector-valued PDLs. | |||
skipping to change at line 1811 | skipping to change at line 1810 | |||
and returns the sliced PDL. | and returns the sliced PDL. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
setdiffvec does not process bad values. | setdiffvec 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 2144 "Primitive.pm" | #line 2143 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::setdiffvec { | sub PDL::setdiffvec { | |||
my ($a,$b,$c,$nc) = @_; | my ($a,$b,$c,$nc) = @_; | |||
$c = PDL->null if (!defined($c)); | $c = PDL->null if (!defined($c)); | |||
$nc = PDL->null if (!defined($nc)); | $nc = PDL->null if (!defined($nc)); | |||
PDL::_setdiffvec_int($a,$b,$c,$nc); | PDL::_setdiffvec_int($a,$b,$c,$nc); | |||
return ($c,$nc) if (wantarray); | return ($c,$nc) if (wantarray); | |||
my $nc_max = $nc->max; | my $nc_max = $nc->max; | |||
return ($nc_max > 0 | return ($nc_max > 0 | |||
? $c->slice(",0:".($nc_max-1)) | ? $c->slice(",0:".($nc_max-1)) | |||
: $c->reshape($c->dim(0), 0, ($c->dims)[2..($c->ndims-1)])); | : $c->reshape($c->dim(0), 0, ($c->dims)[2..($c->ndims-1)])); | |||
} | } | |||
#line 2162 "Primitive.pm" | #line 2161 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*setdiffvec = \&PDL::setdiffvec; | *setdiffvec = \&PDL::setdiffvec; | |||
#line 2169 "Primitive.pm" | #line 2168 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 union_sorted | =head2 union_sorted | |||
=for sig | =for sig | |||
Signature: (a(NA); b(NB); [o]c(NC); indx [o]nc()) | Signature: (a(NA); b(NB); [o]c(NC); indx [o]nc()) | |||
=for ref | =for ref | |||
Union of two flat sorted unique-valued PDLs. | Union of two flat sorted unique-valued PDLs. | |||
skipping to change at line 1857 | skipping to change at line 1856 | |||
In scalar context, reshapes $c() to the actual number of elements in the union a nd returns it. | In scalar context, reshapes $c() to the actual number of elements in the union a nd returns it. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
union_sorted does not process bad values. | union_sorted 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 2201 "Primitive.pm" | #line 2200 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::union_sorted { | sub PDL::union_sorted { | |||
my ($a,$b,$c,$nc) = @_; | my ($a,$b,$c,$nc) = @_; | |||
$c = PDL->null if (!defined($c)); | $c = PDL->null if (!defined($c)); | |||
$nc = PDL->null if (!defined($nc)); | $nc = PDL->null if (!defined($nc)); | |||
PDL::_union_sorted_int($a,$b,$c,$nc); | PDL::_union_sorted_int($a,$b,$c,$nc); | |||
return ($c,$nc) if (wantarray); | return ($c,$nc) if (wantarray); | |||
return $c->slice("0:".($nc->max-1)); | return $c->slice("0:".($nc->max-1)); | |||
} | } | |||
#line 2216 "Primitive.pm" | #line 2215 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*union_sorted = \&PDL::union_sorted; | *union_sorted = \&PDL::union_sorted; | |||
#line 2223 "Primitive.pm" | #line 2222 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 intersect_sorted | =head2 intersect_sorted | |||
=for sig | =for sig | |||
Signature: (a(NA); b(NB); [o]c(NC); indx [o]nc()) | Signature: (a(NA); b(NB); [o]c(NC); indx [o]nc()) | |||
=for ref | =for ref | |||
Intersection of two flat sorted unique-valued PDLs. | Intersection of two flat sorted unique-valued PDLs. | |||
skipping to change at line 1900 | skipping to change at line 1899 | |||
In scalar context, reshapes $c() to the actual number of elements in the interse ction and returns it. | In scalar context, reshapes $c() to the actual number of elements in the interse ction and returns it. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
intersect_sorted does not process bad values. | intersect_sorted 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 2255 "Primitive.pm" | #line 2254 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::intersect_sorted { | sub PDL::intersect_sorted { | |||
my ($a,$b,$c,$nc) = @_; | my ($a,$b,$c,$nc) = @_; | |||
$c = PDL->null if (!defined($c)); | $c = PDL->null if (!defined($c)); | |||
$nc = PDL->null if (!defined($nc)); | $nc = PDL->null if (!defined($nc)); | |||
PDL::_intersect_sorted_int($a,$b,$c,$nc); | PDL::_intersect_sorted_int($a,$b,$c,$nc); | |||
return ($c,$nc) if (wantarray); | return ($c,$nc) if (wantarray); | |||
my $nc_max = $nc->max; | my $nc_max = $nc->max; | |||
return ($nc_max > 0 | return ($nc_max > 0 | |||
? $c->slice("0:".($nc_max-1)) | ? $c->slice("0:".($nc_max-1)) | |||
: $c->reshape(0, ($c->dims)[1..($c->ndims-1)])); | : $c->reshape(0, ($c->dims)[1..($c->ndims-1)])); | |||
} | } | |||
#line 2273 "Primitive.pm" | #line 2272 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*intersect_sorted = \&PDL::intersect_sorted; | *intersect_sorted = \&PDL::intersect_sorted; | |||
#line 2280 "Primitive.pm" | #line 2279 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 setdiff_sorted | =head2 setdiff_sorted | |||
=for sig | =for sig | |||
Signature: (a(NA); b(NB); [o]c(NC); indx [o]nc()) | Signature: (a(NA); b(NB); [o]c(NC); indx [o]nc()) | |||
=for ref | =for ref | |||
Set-difference ($a() \ $b()) of two flat sorted unique-valued PDLs. | Set-difference ($a() \ $b()) of two flat sorted unique-valued PDLs. | |||
skipping to change at line 1947 | skipping to change at line 1946 | |||
In scalar context, reshapes $c() to the actual number of elements in the differe nce set and returns it. | In scalar context, reshapes $c() to the actual number of elements in the differe nce set and returns it. | |||
Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||
=for bad | =for bad | |||
setdiff_sorted does not process bad values. | setdiff_sorted 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 2313 "Primitive.pm" | #line 2312 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::setdiff_sorted { | sub PDL::setdiff_sorted { | |||
my ($a,$b,$c,$nc) = @_; | my ($a,$b,$c,$nc) = @_; | |||
$c = PDL->null if (!defined($c)); | $c = PDL->null if (!defined($c)); | |||
$nc = PDL->null if (!defined($nc)); | $nc = PDL->null if (!defined($nc)); | |||
PDL::_setdiff_sorted_int($a,$b,$c,$nc); | PDL::_setdiff_sorted_int($a,$b,$c,$nc); | |||
return ($c,$nc) if (wantarray); | return ($c,$nc) if (wantarray); | |||
my $nc_max = $nc->max; | my $nc_max = $nc->max; | |||
return ($nc_max > 0 | return ($nc_max > 0 | |||
? $c->slice("0:".($nc_max-1)) | ? $c->slice("0:".($nc_max-1)) | |||
: $c->reshape(0, ($c->dims)[1..($c->ndims-1)])); | : $c->reshape(0, ($c->dims)[1..($c->ndims-1)])); | |||
} | } | |||
#line 2331 "Primitive.pm" | #line 2330 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*setdiff_sorted = \&PDL::setdiff_sorted; | *setdiff_sorted = \&PDL::setdiff_sorted; | |||
#line 2338 "Primitive.pm" | #line 2337 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 srand | =head2 srand | |||
=for sig | =for sig | |||
Signature: (a()) | Signature: (a()) | |||
=for ref | =for ref | |||
Seed random-number generator with a 64-bit int. Will generate seed data | Seed random-number generator with a 64-bit int. Will generate seed data | |||
skipping to change at line 1994 | skipping to change at line 1993 | |||
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 2372 "Primitive.pm" | #line 2371 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 2380 "Primitive.pm" | #line 2379 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*srand = \&PDL::srand; | *srand = \&PDL::srand; | |||
#line 2387 "Primitive.pm" | #line 2386 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 random | =head2 random | |||
=for sig | =for sig | |||
Signature: (a()) | Signature: (a()) | |||
=for ref | =for ref | |||
Constructor which returns ndarray of random numbers | Constructor which returns ndarray of random numbers | |||
skipping to change at line 2040 | skipping to change at line 2039 | |||
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 2428 "Primitive.pm" | #line 2427 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 2441 "Primitive.pm" | #line 2440 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
#line 2446 "Primitive.pm" | #line 2445 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 randsym | =head2 randsym | |||
=for sig | =for sig | |||
Signature: (a()) | Signature: (a()) | |||
=for ref | =for ref | |||
Constructor which returns ndarray of random numbers | Constructor which returns ndarray of random numbers | |||
skipping to change at line 2088 | skipping to change at line 2087 | |||
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 2486 "Primitive.pm" | #line 2485 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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 2499 "Primitive.pm" | #line 2498 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
#line 2504 "Primitive.pm" | #line 2503 "Primitive.pm" | |||
#line 2319 "primitive.pd" | #line 2318 "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 2136 | skipping to change at line 2135 | |||
=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 2540 "Primitive.pm" | #line 2539 "Primitive.pm" | |||
#line 2359 "primitive.pd" | #line 2358 "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 2284 | skipping to change at line 2283 | |||
$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 2691 "Primitive.pm" | #line 2690 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Search for values in a sorted array, return index appropriate for sampling from a distribution | Search for values in a sorted array, return index appropriate for sampling from a distribution | |||
skipping to change at line 2352 | skipping to change at line 2351 | |||
$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 2785 "Primitive.pm" | #line 2784 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearch_sample = \&PDL::vsearch_sample; | *vsearch_sample = \&PDL::vsearch_sample; | |||
#line 2792 "Primitive.pm" | #line 2791 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Determine the insertion point for values in a sorted array, inserting before dup licates. | Determine the insertion point for values in a sorted array, inserting before dup licates. | |||
skipping to change at line 2421 | skipping to change at line 2420 | |||
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 2882 "Primitive.pm" | #line 2881 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearch_insert_leftmost = \&PDL::vsearch_insert_leftmost; | *vsearch_insert_leftmost = \&PDL::vsearch_insert_leftmost; | |||
#line 2889 "Primitive.pm" | #line 2888 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Determine the insertion point for values in a sorted array, inserting after dupl icates. | Determine the insertion point for values in a sorted array, inserting after dupl icates. | |||
skipping to change at line 2490 | skipping to change at line 2489 | |||
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 2979 "Primitive.pm" | #line 2978 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearch_insert_rightmost = \&PDL::vsearch_insert_rightmost; | *vsearch_insert_rightmost = \&PDL::vsearch_insert_rightmost; | |||
#line 2986 "Primitive.pm" | #line 2985 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Match values against a sorted array. | Match values against a sorted array. | |||
skipping to change at line 2528 | skipping to change at line 2527 | |||
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 3034 "Primitive.pm" | #line 3033 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearch_match = \&PDL::vsearch_match; | *vsearch_match = \&PDL::vsearch_match; | |||
#line 3041 "Primitive.pm" | #line 3040 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Determine the index for values in a sorted array of bins, lower bound inclusive. | Determine the index for values in a sorted array of bins, lower bound inclusive. | |||
skipping to change at line 2595 | skipping to change at line 2594 | |||
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 3129 "Primitive.pm" | #line 3128 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearch_bin_inclusive = \&PDL::vsearch_bin_inclusive; | *vsearch_bin_inclusive = \&PDL::vsearch_bin_inclusive; | |||
#line 3136 "Primitive.pm" | #line 3135 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../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 | |||
Determine the index for values in a sorted array of bins, lower bound exclusive. | Determine the index for values in a sorted array of bins, lower bound exclusive. | |||
skipping to change at line 2662 | skipping to change at line 2661 | |||
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 3224 "Primitive.pm" | #line 3223 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*vsearch_bin_exclusive = \&PDL::vsearch_bin_exclusive; | *vsearch_bin_exclusive = \&PDL::vsearch_bin_exclusive; | |||
#line 3231 "Primitive.pm" | #line 3230 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 interpolate | =head2 interpolate | |||
=for sig | =for sig | |||
Signature: (real xi(); real x(n); y(n); [o] yi(); int [o] err()) | Signature: (real xi(); real x(n); y(n); [o] yi(); int [o] err()) | |||
=for ref | =for ref | |||
routine for 1D linear interpolation | routine for 1D linear interpolation | |||
skipping to change at line 2711 | skipping to change at line 2710 | |||
is printed rather than returning an error ndarray. | is printed rather than returning an error ndarray. | |||
Note that C<interpolate> can use complex values for C<$y> and C<$yi> but | Note that C<interpolate> can use complex values for C<$y> and C<$yi> but | |||
C<$x> and C<$xi> must be real. | C<$x> and C<$xi> must be real. | |||
=for bad | =for bad | |||
needs major (?) work to handles bad values | needs major (?) work to handles bad values | |||
=cut | =cut | |||
#line 3282 "Primitive.pm" | #line 3281 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::interpolate { | sub PDL::interpolate { | |||
my ($xi, $x, $y, $yi, $err) = @_; | my ($xi, $x, $y, $yi, $err) = @_; | |||
croak "x must be real" if (ref($x) && ! $x->type->real); | croak "x must be real" if (ref($x) && ! $x->type->real); | |||
croak "xi must be real" if (ref($xi) && ! $xi->type->real ); | croak "xi must be real" if (ref($xi) && ! $xi->type->real ); | |||
$yi //= PDL->null; | $yi //= PDL->null; | |||
$err //= PDL->null; | $err //= PDL->null; | |||
PDL::_interpolate_int($xi, $x, $y, $yi, $err); | PDL::_interpolate_int($xi, $x, $y, $yi, $err); | |||
($yi, $err); | ($yi, $err); | |||
} | } | |||
#line 3297 "Primitive.pm" | #line 3296 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*interpolate = \&PDL::interpolate; | *interpolate = \&PDL::interpolate; | |||
#line 3304 "Primitive.pm" | #line 3303 "Primitive.pm" | |||
#line 3047 "primitive.pd" | #line 3046 "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 2766 | skipping to change at line 2765 | |||
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 = @_ == 1 ? $_[0] : 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 @_ == 0; | |||
} # sub: interpol() | } # sub: interpol() | |||
*PDL::interpol = \&interpol; | *PDL::interpol = \&interpol; | |||
#line 3343 "Primitive.pm" | #line 3342 "Primitive.pm" | |||
#line 3085 "primitive.pd" | #line 3084 "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 3010 | skipping to change at line 3009 | |||
$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 3590 "Primitive.pm" | #line 3589 "Primitive.pm" | |||
#line 3335 "primitive.pd" | #line 3334 "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 3060 | skipping to change at line 3059 | |||
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 3642 "Primitive.pm" | #line 3641 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 which | =head2 which | |||
=for sig | =for sig | |||
Signature: (mask(n); indx [o] inds(n); indx [o]lastout()) | Signature: (mask(n); indx [o] inds(n); indx [o]lastout()) | |||
=for ref | =for ref | |||
Returns indices of non-zero values from a 1-D PDL | Returns indices of non-zero values from a 1-D PDL | |||
skipping to change at line 3118 | skipping to change at line 3117 | |||
[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 3708 "Primitive.pm" | #line 3707 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../blib/lib/PDL/PP.pm" | |||
sub which { my ($this,$out) = @_; | sub which { my ($this,$out) = @_; | |||
$this = $this->flat; | $this = $this->flat; | |||
$out //= $this->nullcreate; | $out //= $this->nullcreate; | |||
PDL::_which_int($this,$out,my $lastout = $this->nullcreate); | PDL::_which_int($this,$out,my $lastout = $this->nullcreate); | |||
my $lastoutmax = $lastout->max->sclr; | my $lastoutmax = $lastout->max->sclr; | |||
$lastoutmax ? $out->slice('0:'.($lastoutmax-1))->sever : empty(in dx); | $lastoutmax ? $out->slice('0:'.($lastoutmax-1))->sever : empty(in dx); | |||
} | } | |||
*PDL::which = \&which; | *PDL::which = \&which; | |||
#line 3722 "Primitive.pm" | #line 3721 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*which = \&PDL::which; | *which = \&PDL::which; | |||
#line 3729 "Primitive.pm" | #line 3728 "Primitive.pm" | |||
#line 949 "../../blib/lib/PDL/PP.pm" | #line 958 "../../blib/lib/PDL/PP.pm" | |||
=head2 which_both | =head2 which_both | |||
=for sig | =for sig | |||
Signature: (mask(n); indx [o] inds(n); indx [o]notinds(n); indx [o]lastout(); indx [o]lastoutn()) | Signature: (mask(n); indx [o] inds(n); indx [o]notinds(n); indx [o]lastout(); indx [o]lastoutn()) | |||
=for ref | =for ref | |||
Returns indices of nonzero and zero values in a mask PDL | Returns indices of nonzero and zero values in a mask PDL | |||
skipping to change at line 3170 | skipping to change at line 3169 | |||
pdl> ($big, $small) = which_both($x >= 5); p "$big\n$small" | 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 3772 "Primitive.pm" | #line 3771 "Primitive.pm" | |||
#line 950 "../../blib/lib/PDL/PP.pm" | #line 959 "../../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; | $outi //= $this->nullcreate; | |||
$outni //= $this->nullcreate; | $outni //= $this->nullcreate; | |||
PDL::_which_both_int($this,$outi,$outni,my $lastout = $this->null create,my $lastoutn = $this->nullcreate); | PDL::_which_both_int($this,$outi,$outni,my $lastout = $this->null create,my $lastoutn = $this->nullcreate); | |||
my $lastoutmax = $lastout->max->sclr; | my $lastoutmax = $lastout->max->sclr; | |||
$outi = $lastoutmax ? $outi->slice('0:'.($lastoutmax-1))->sever : empty(indx); | $outi = $lastoutmax ? $outi->slice('0:'.($lastoutmax-1))->sever : empty(indx); | |||
return $outi if !wantarray; | return $outi if !wantarray; | |||
my $lastoutnmax = $lastoutn->max->sclr; | my $lastoutnmax = $lastoutn->max->sclr; | |||
($outi, $lastoutnmax ? $outni->slice('0:'.($lastoutnmax-1))->seve r : empty(indx)); | ($outi, $lastoutnmax ? $outni->slice('0:'.($lastoutnmax-1))->seve r : empty(indx)); | |||
} | } | |||
*PDL::which_both = \&which_both; | *PDL::which_both = \&which_both; | |||
#line 3790 "Primitive.pm" | #line 3789 "Primitive.pm" | |||
#line 951 "../../blib/lib/PDL/PP.pm" | #line 960 "../../blib/lib/PDL/PP.pm" | |||
*which_both = \&PDL::which_both; | *which_both = \&PDL::which_both; | |||
#line 3797 "Primitive.pm" | #line 3796 "Primitive.pm" | |||
#line 3516 "primitive.pd" | #line 3515 "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 3258 | skipping to change at line 3257 | |||
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 3866 "Primitive.pm" | #line 3865 "Primitive.pm" | |||
#line 3584 "primitive.pd" | #line 3583 "primitive.pd" | |||
=head2 where_both | =head2 where_both | |||
=for ref | =for ref | |||
Returns slices (non-zero in mask, zero) of an ndarray according to a mask | Returns slices (non-zero in mask, zero) of an ndarray according to a mask | |||
=for usage | =for usage | |||
($match_vals, $non_match_vals) = where_both($pdl, $mask); | ($match_vals, $non_match_vals) = where_both($pdl, $mask); | |||
skipping to change at line 3296 | skipping to change at line 3295 | |||
=cut | =cut | |||
sub PDL::where_both { | sub PDL::where_both { | |||
barf "Usage: where_both(\$pdl, \$mask)\n" if @_ != 2; | barf "Usage: where_both(\$pdl, \$mask)\n" if @_ != 2; | |||
my ($arr, $mask) = @_; # $mask has 0==false, 1==true | my ($arr, $mask) = @_; # $mask has 0==false, 1==true | |||
my $arr_flat = $arr->clump(-1); | my $arr_flat = $arr->clump(-1); | |||
map $arr_flat->index1d($_), PDL::which_both($mask); | map $arr_flat->index1d($_), PDL::which_both($mask); | |||
} | } | |||
*where_both = \&PDL::where_both; | *where_both = \&PDL::where_both; | |||
#line 3906 "Primitive.pm" | #line 3905 "Primitive.pm" | |||
#line 3622 "primitive.pd" | #line 3621 "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 3376 | skipping to change at line 3375 | |||
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 3988 "Primitive.pm" | #line 3987 "Primitive.pm" | |||
#line 3703 "primitive.pd" | #line 3702 "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 3481 | skipping to change at line 3480 | |||
} | } | |||
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 4095 "Primitive.pm" | #line 4094 "Primitive.pm" | |||
#line 3812 "primitive.pd" | #line 3811 "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 3652 | skipping to change at line 3651 | |||
my $inds=which($s1 == $s2); | my $inds=which($s1 == $s2); | |||
if ($inds->nelem() > 0) { | if ($inds->nelem() > 0) { | |||
return $union->index($inds); | return $union->index($inds); | |||
} else { | } else { | |||
return $inds; | return $inds; | |||
} | } | |||
} elsif ($op eq 'AND') { | } elsif ($op eq 'AND') { | |||
# The intersection of the arrays. | # The intersection of the arrays. | |||
return $x if $x->isempty; | ||||
return $y if $y->isempty; | ||||
# 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))->uniq; | ||||
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 4280 "Primitive.pm" | #line 4279 "Primitive.pm" | |||
#line 3995 "primitive.pd" | #line 3994 "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 3700 | skipping to change at line 3699 | |||
=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 4319 "Primitive.pm" | #line 4318 "Primitive.pm" | |||
#line 4031 "primitive.pd" | #line 4030 "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 4343 "Primitive.pm" | #line 4342 "Primitive.pm" | |||
# Exit with OK status | # Exit with OK status | |||
1; | 1; | |||
End of changes. 238 change blocks. | ||||
253 lines changed or deleted | 250 lines changed or added |