Slices.pm (PDL-2.082) | : | Slices.pm (PDL-2.083) | ||
---|---|---|---|---|

skipping to change at line 81 | skipping to change at line 81 | |||

then the variables C<$y> and C<$c> point to the same object but with | then the variables C<$y> and C<$c> point to the same object but with | |||

C<-E<gt>copy> they would not. | C<-E<gt>copy> they would not. | |||

=cut | =cut | |||

use strict; | use strict; | |||

use warnings; | use warnings; | |||

use PDL::Core ':Internal'; | use PDL::Core ':Internal'; | |||

use Scalar::Util 'blessed'; | use Scalar::Util 'blessed'; | |||

#line 91 "Slices.pm" | #line 90 "Slices.pm" | |||

=head1 FUNCTIONS | =head1 FUNCTIONS | |||

=cut | =cut | |||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 index | =head2 index | |||

=for sig | =for sig | |||

Signature: (a(n); indx ind(); [oca] c()) | Signature: (a(n); indx ind(); [oca] c()) | |||

=for ref | =for ref | |||

C<index>, C<index1d>, and C<index2d> provide rudimentary index indirection. | C<index>, C<index1d>, and C<index2d> provide rudimentary index indirection. | |||

skipping to change at line 162 | skipping to change at line 160 | |||

puts a single column from C<$x> into C<$y>, and puts a single element | puts a single column from C<$x> into C<$y>, and puts a single element | |||

from each column of C<$x> into C<$c>. If you want to extract multiple | from each column of C<$x> into C<$c>. If you want to extract multiple | |||

columns from an array in one operation, see L</dice> or | columns from an array in one operation, see L</dice> or | |||

L</indexND>. | L</indexND>. | |||

=for bad | =for bad | |||

index barfs if any of the index values are bad. | index barfs if any of the index values are bad. | |||

=cut | =cut | |||

#line 184 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*index = \&PDL::index; | *index = \&PDL::index; | |||

#line 191 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 index1d | =head2 index1d | |||

=for sig | =for sig | |||

Signature: (a(n); indx ind(m); [oca] c(m)) | Signature: (a(n); indx ind(m); [oca] c(m)) | |||

=for ref | =for ref | |||

C<index>, C<index1d>, and C<index2d> provide rudimentary index indirection. | C<index>, C<index1d>, and C<index2d> provide rudimentary index indirection. | |||

skipping to change at line 244 | skipping to change at line 236 | |||

puts a single column from C<$x> into C<$y>, and puts a single element | puts a single column from C<$x> into C<$y>, and puts a single element | |||

from each column of C<$x> into C<$c>. If you want to extract multiple | from each column of C<$x> into C<$c>. If you want to extract multiple | |||

columns from an array in one operation, see L</dice> or | columns from an array in one operation, see L</dice> or | |||

L</indexND>. | L</indexND>. | |||

=for bad | =for bad | |||

index1d propagates BAD index elements to the output variable. | index1d propagates BAD index elements to the output variable. | |||

=cut | =cut | |||

#line 274 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*index1d = \&PDL::index1d; | *index1d = \&PDL::index1d; | |||

#line 281 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 index2d | =head2 index2d | |||

=for sig | =for sig | |||

Signature: (a(na,nb); indx inda(); indx indb(); [oca] c()) | Signature: (a(na,nb); indx inda(); indx indb(); [oca] c()) | |||

=for ref | =for ref | |||

C<index>, C<index1d>, and C<index2d> provide rudimentary index indirection. | C<index>, C<index1d>, and C<index2d> provide rudimentary index indirection. | |||

skipping to change at line 326 | skipping to change at line 312 | |||

puts a single column from C<$x> into C<$y>, and puts a single element | puts a single column from C<$x> into C<$y>, and puts a single element | |||

from each column of C<$x> into C<$c>. If you want to extract multiple | from each column of C<$x> into C<$c>. If you want to extract multiple | |||

columns from an array in one operation, see L</dice> or | columns from an array in one operation, see L</dice> or | |||

L</indexND>. | L</indexND>. | |||

=for bad | =for bad | |||

index2d barfs if either of the index values are bad. | index2d barfs if either of the index values are bad. | |||

=cut | =cut | |||

#line 364 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*index2d = \&PDL::index2d; | *index2d = \&PDL::index2d; | |||

#line 371 "Slices.pm" | ||||

#line 241 "slices.pd" | #line 241 "slices.pd" | |||

=head2 indexNDb | =head2 indexNDb | |||

=for ref | =for ref | |||

Backwards-compatibility alias for indexND | Backwards-compatibility alias for indexND | |||

=head2 indexND | =head2 indexND | |||

skipping to change at line 383 | skipping to change at line 365 | |||

PDL, suitable for feeding to this. | PDL, suitable for feeding to this. | |||

=cut | =cut | |||

sub PDL::indexND { | sub PDL::indexND { | |||

my($source,$index, $boundary) = @_; | my($source,$index, $boundary) = @_; | |||

return PDL::range($source,$index,undef,$boundary); | return PDL::range($source,$index,undef,$boundary); | |||

} | } | |||

*PDL::indexNDb = \&PDL::indexND; | *PDL::indexNDb = \&PDL::indexND; | |||

#line 425 "Slices.pm" | ||||

#line 293 "slices.pd" | #line 293 "slices.pd" | |||

sub PDL::range { | sub PDL::range { | |||

my($source,$ind,$sz,$bound) = @_; | my($source,$ind,$sz,$bound) = @_; | |||

# Convert to indx type up front (also handled in rangeb if necessary) | # Convert to indx type up front (also handled in rangeb if necessary) | |||

my $index = (ref $ind && UNIVERSAL::isa($ind,'PDL') && $ind->type eq 'indx') ? $ind : indx($ind); | my $index = (ref $ind && UNIVERSAL::isa($ind,'PDL') && $ind->type eq 'indx') ? $ind : indx($ind); | |||

my $size = defined($sz) ? PDL->pdl($sz) : undef; | my $size = defined($sz) ? PDL->pdl($sz) : undef; | |||

# Handle empty PDL case: return a properly constructed Empty. | # Handle empty PDL case: return a properly constructed Empty. | |||

if($index->isempty) { | if($index->isempty) { | |||

my @sdims= $source->dims; | my @sdims= $source->dims; | |||

skipping to change at line 423 | skipping to change at line 403 | |||

$bound = $s; | $bound = $s; | |||

} | } | |||

elsif($bound !~ m/^[0123ftepx]+$/ && $bound =~ m/^([0123ftepx])/i ) { | elsif($bound !~ m/^[0123ftepx]+$/ && $bound =~ m/^([0123ftepx])/i ) { | |||

$bound = $1; | $bound = $1; | |||

} | } | |||

} | } | |||

no warnings; # shut up about passing undef into rangeb | no warnings; # shut up about passing undef into rangeb | |||

$source->rangeb($index,$size,$bound); | $source->rangeb($index,$size,$bound); | |||

} | } | |||

#line 471 "Slices.pm" | #line 440 "Slices.pm" | |||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rangeb | =head2 rangeb | |||

=for sig | =for sig | |||

Signature: (P(); C(); pdl *ind_pdl; SV *size; SV *boundary_sv) | Signature: (P(); C(); pdl *ind_pdl; SV *size_sv; SV *boundary_sv) | |||

=for ref | =for ref | |||

Engine for L</range> | Engine for L</range> | |||

=for example | =for example | |||

Same calling convention as L</range>, but you must supply all | Same calling convention as L</range>, but you must supply all | |||

parameters. C<rangeb> is marginally faster as it makes a direct PP call, | parameters. C<rangeb> is marginally faster as it makes a direct PP call, | |||

avoiding the perl argument-parsing step. | avoiding the perl argument-parsing step. | |||

skipping to change at line 636 | skipping to change at line 614 | |||

[0 0 0 0 0] | [0 0 0 0 0] | |||

[0 0 1 1 0] | [0 0 1 1 0] | |||

] | ] | |||

B<CAVEAT>: It's quite possible to select multiple ranges that | B<CAVEAT>: It's quite possible to select multiple ranges that | |||

intersect. In that case, modifying the ranges doesn't have a | intersect. In that case, modifying the ranges doesn't have a | |||

guaranteed result in the original PDL -- the result is an arbitrary | guaranteed result in the original PDL -- the result is an arbitrary | |||

choice among the valid values. For some things that's OK; but for | choice among the valid values. For some things that's OK; but for | |||

others it's not. In particular, this doesn't work: | others it's not. In particular, this doesn't work: | |||

pdl> $photon_list = new PDL::RandVar->sample(500)->reshape(2,250)*10 | pdl> $photon_list = PDL::RandVar->new->sample(500)->reshape(2,250)*10 | |||

pdl> $histogram = zeroes(10,10) | pdl> $histogram = zeroes(10,10) | |||

pdl> $histogram->range($photon_list,1)++; #not what you wanted | pdl> $histogram->range($photon_list,1)++; #not what you wanted | |||

The reason is that if two photons land in the same bin, then that bin | The reason is that if two photons land in the same bin, then that bin | |||

doesn't get incremented twice. (That may get fixed in a later version...) | doesn't get incremented twice. (That may get fixed in a later version...) | |||

B<PERMISSIVE RANGING>: If C<$index> has too many dimensions compared | B<PERMISSIVE RANGING>: If C<$index> has too many dimensions compared | |||

to C<$source>, then $source is treated as though it had dummy | to C<$source>, then $source is treated as though it had dummy | |||

dimensions of size 1, up to the required number of dimensions. These | dimensions of size 1, up to the required number of dimensions. These | |||

virtual dummy dimensions have the usual boundary conditions applied to | virtual dummy dimensions have the usual boundary conditions applied to | |||

skipping to change at line 697 | skipping to change at line 675 | |||

* index broadcast dimensions are effectively clumped internally. This | * index broadcast dimensions are effectively clumped internally. This | |||

makes it easier to loop over the index array but a little more brain-bending | makes it easier to loop over the index array but a little more brain-bending | |||

to tease out the algorithm. | to tease out the algorithm. | |||

=for bad | =for bad | |||

rangeb processes bad values. | rangeb 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 752 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rangeb = \&PDL::rangeb; | *rangeb = \&PDL::rangeb; | |||

#line 759 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rld | =head2 rld | |||

=for sig | =for sig | |||

Signature: (indx a(n); b(n); [o]c(m)) | Signature: (indx a(n); b(n); [o]c(m)) | |||

=for ref | =for ref | |||

Run-length decode a vector | Run-length decode a vector | |||

skipping to change at line 729 | skipping to change at line 701 | |||

=for example | =for example | |||

rld($x,$y,$c=null); | rld($x,$y,$c=null); | |||

=for bad | =for bad | |||

rld does not process bad values. | rld 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. | ||||

=cut | =cut | |||

#line 793 "Slices.pm" | ||||

#line 959 "../../blib/lib/PDL/PP.pm" | ||||

#line 1045 "slices.pd" | ||||

sub PDL::rld { | sub PDL::rld { | |||

my ($x,$y) = @_; | my ($x,$y) = @_; | |||

my ($c); | my ($c); | |||

if ($#_ == 2) { | if ($#_ == 2) { | |||

$c = $_[2]; | $c = $_[2]; | |||

} else { | } else { | |||

# XXX Need to improve emulation of broadcasting in auto-generating c | # XXX Need to improve emulation of broadcasting in auto-generating c | |||

my ($size) = $x->sumover->max->sclr; | my ($size) = $x->sumover->max->sclr; | |||

my (@dims) = $x->dims; | my (@dims) = $x->dims; | |||

shift @dims; | shift @dims; | |||

$c = $y->zeroes($size,@dims); | $c = $y->zeroes($size,@dims); | |||

} | } | |||

&PDL::_rld_int($x,$y,$c); | &PDL::_rld_int($x,$y,$c); | |||

$c; | $c; | |||

} | } | |||

#line 814 "Slices.pm" | #line 767 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rld = \&PDL::rld; | *rld = \&PDL::rld; | |||

#line 821 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rle | =head2 rle | |||

=for sig | =for sig | |||

Signature: (c(n); indx [o]a(m); [o]b(m)) | Signature: (c(n); indx [o]a(m); [o]b(m)) | |||

=for ref | =for ref | |||

Run-length encode a vector | Run-length encode a vector | |||

skipping to change at line 806 | skipping to change at line 771 | |||

$y = $x->cumusumover; | $y = $x->cumusumover; | |||

$yprob1x = $y->slice('-1:0')->double / $y->slice('(-1)'); | $yprob1x = $y->slice('-1:0')->double / $y->slice('(-1)'); | |||

$z = cat($x1, 1 / $yprob1x**$nrolls)->transpose; | $z = cat($x1, 1 / $yprob1x**$nrolls)->transpose; | |||

=for bad | =for bad | |||

rle does not process bad values. | rle does not process bad values. | |||

=cut | =cut | |||

#line 881 "Slices.pm" | ||||

#line 959 "../../blib/lib/PDL/PP.pm" | ||||

#line 1096 "slices.pd" | ||||

sub PDL::rle { | sub PDL::rle { | |||

my $c = shift; | my $c = shift; | |||

my ($x,$y) = @_==2 ? @_ : (null,null); | my ($x,$y) = @_==2 ? @_ : (null,null); | |||

PDL::_rle_int($c,$x,$y); | PDL::_rle_int($c,$x,$y); | |||

my $max_ind = ($c->ndims<2) ? ($x!=0)->sumover-1 : | my $max_ind = ($c->ndims<2) ? ($x!=0)->sumover-1 : | |||

($x!=0)->clump(1..$x->ndims-1)->sumover->max->sc lr-1; | ($x!=0)->clump(1..$x->ndims-1)->sumover->max->sc lr-1; | |||

return ($x->slice("0:$max_ind"),$y->slice("0:$max_ind")); | return ($x->slice("0:$max_ind"),$y->slice("0:$max_ind")); | |||

} | } | |||

#line 895 "Slices.pm" | #line 839 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rle = \&PDL::rle; | *rle = \&PDL::rle; | |||

#line 902 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rlevec | =head2 rlevec | |||

=for sig | =for sig | |||

Signature: (c(M,N); indx [o]a(N); [o]b(M,N)) | Signature: (c(M,N); indx [o]a(N); [o]b(M,N)) | |||

=for ref | =for ref | |||

Run-length encode a set of vectors. | Run-length encode a set of vectors. | |||

skipping to change at line 857 | skipping to change at line 815 | |||

See also: L</rle>, L<PDL::Ufunc/qsortvec>, L<PDL::Primitive/uniqvec> | See also: L</rle>, L<PDL::Ufunc/qsortvec>, L<PDL::Primitive/uniqvec> | |||

Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||

=for bad | =for bad | |||

rlevec does not process bad values. | rlevec does not process bad values. | |||

=cut | =cut | |||

#line 943 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rlevec = \&PDL::rlevec; | *rlevec = \&PDL::rlevec; | |||

#line 950 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rldvec | =head2 rldvec | |||

=for sig | =for sig | |||

Signature: (indx a(N); b(M,N); [o]c(M,N)) | Signature: (indx a(N); b(M,N); [o]c(M,N)) | |||

=for ref | =for ref | |||

Run-length decode a set of vectors, akin to a higher-order rld(). | Run-length decode a set of vectors, akin to a higher-order rld(). | |||

skipping to change at line 890 | skipping to change at line 842 | |||

See also: L</rld>. | See also: L</rld>. | |||

Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||

=for bad | =for bad | |||

rldvec does not process bad values. | rldvec does not process bad values. | |||

=cut | =cut | |||

#line 984 "Slices.pm" | ||||

#line 959 "../../blib/lib/PDL/PP.pm" | ||||

#line 1221 "slices.pd" | ||||

sub PDL::rldvec { | sub PDL::rldvec { | |||

my ($a,$b,$c) = @_; | my ($a,$b,$c) = @_; | |||

if (!defined($c)) { | if (!defined($c)) { | |||

# XXX Need to improve emulation of threading in auto-generating c | # XXX Need to improve emulation of threading in auto-generating c | |||

my ($rowlen) = $b->dim(0); | my ($rowlen) = $b->dim(0); | |||

my ($size) = $a->sumover->max; | my ($size) = $a->sumover->max; | |||

my (@dims) = $a->dims; | my (@dims) = $a->dims; | |||

shift(@dims); | shift(@dims); | |||

$c = $b->zeroes($b->type,$rowlen,$size,@dims); | $c = $b->zeroes($b->type,$rowlen,$size,@dims); | |||

} | } | |||

&PDL::_rldvec_int($a,$b,$c); | &PDL::_rldvec_int($a,$b,$c); | |||

return $c; | return $c; | |||

} | } | |||

#line 1003 "Slices.pm" | #line 932 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rldvec = \&PDL::rldvec; | *rldvec = \&PDL::rldvec; | |||

#line 1010 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rleseq | =head2 rleseq | |||

=for sig | =for sig | |||

Signature: (c(N); indx [o]a(N); [o]b(N)) | Signature: (c(N); indx [o]a(N); [o]b(N)) | |||

=for ref | =for ref | |||

Run-length encode a vector of subsequences. | Run-length encode a vector of subsequences. | |||

skipping to change at line 940 | skipping to change at line 885 | |||

See also L</rle>. | See also L</rle>. | |||

Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||

=for bad | =for bad | |||

rleseq does not process bad values. | rleseq does not process bad values. | |||

=cut | =cut | |||

#line 1044 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rleseq = \&PDL::rleseq; | *rleseq = \&PDL::rleseq; | |||

#line 1051 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rldseq | =head2 rldseq | |||

=for sig | =for sig | |||

Signature: (indx a(N); b(N); [o]c(M)) | Signature: (indx a(N); b(N); [o]c(M)) | |||

=for ref | =for ref | |||

Run-length decode a subsequence vector. | Run-length decode a subsequence vector. | |||

skipping to change at line 976 | skipping to change at line 915 | |||

See also: L</rld>. | See also: L</rld>. | |||

Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||

=for bad | =for bad | |||

rldseq does not process bad values. | rldseq does not process bad values. | |||

=cut | =cut | |||

#line 1088 "Slices.pm" | ||||

#line 959 "../../blib/lib/PDL/PP.pm" | ||||

#line 1300 "slices.pd" | ||||

sub PDL::rldseq { | sub PDL::rldseq { | |||

my ($a,$b,$c) = @_; | my ($a,$b,$c) = @_; | |||

if (!defined($c)) { | if (!defined($c)) { | |||

my $size = $a->sumover->max; | my $size = $a->sumover->max; | |||

my (@dims) = $a->dims; | my (@dims) = $a->dims; | |||

shift(@dims); | shift(@dims); | |||

$c = $b->zeroes($b->type,$size,@dims); | $c = $b->zeroes($b->type,$size,@dims); | |||

} | } | |||

&PDL::_rldseq_int($a,$b,$c); | &PDL::_rldseq_int($a,$b,$c); | |||

return $c; | return $c; | |||

} | } | |||

#line 1105 "Slices.pm" | #line 1020 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rldseq = \&PDL::rldseq; | *rldseq = \&PDL::rldseq; | |||

#line 1112 "Slices.pm" | ||||

#line 1346 "slices.pd" | #line 1340 "slices.pd" | |||

=head2 rleND | =head2 rleND | |||

=for sig | =for sig | |||

Signature: (data(@vdims,N); int [o]counts(N); [o]elts(@vdims,N)) | Signature: (data(@vdims,N); int [o]counts(N); [o]elts(@vdims,N)) | |||

=for ref | =for ref | |||

Run-length encode a set of (sorted) n-dimensional values. | Run-length encode a set of (sorted) n-dimensional values. | |||

skipping to change at line 1077 | skipping to change at line 1011 | |||

my @countdims = $counts->dims; | my @countdims = $counts->dims; | |||

shift(@countdims); | shift(@countdims); | |||

$data = zeroes($elts->type, @vdimsN, @countdims); | $data = zeroes($elts->type, @vdimsN, @countdims); | |||

} | } | |||

##-- guts: call rldvec() | ##-- guts: call rldvec() | |||

rldvec($counts, $elts->clump($#vdimsN), $data->clump($#vdimsN)); | rldvec($counts, $elts->clump($#vdimsN), $data->clump($#vdimsN)); | |||

return $data; | return $data; | |||

} | } | |||

#line 1195 "Slices.pm" | #line 1107 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*_clump_int = \&PDL::_clump_int; | *_clump_int = \&PDL::_clump_int; | |||

#line 1202 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 xchg | =head2 xchg | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx n1; PDL_Indx n2) | Signature: (P(); C(); PDL_Indx n1; PDL_Indx n2) | |||

=for ref | =for ref | |||

exchange two dimensions | exchange two dimensions | |||

skipping to change at line 1115 | skipping to change at line 1044 | |||

are exchanged with each other i.e. | are exchanged with each other i.e. | |||

$y->at(5,3,2,8) == $x->at(5,3,8,2) | $y->at(5,3,2,8) == $x->at(5,3,8,2) | |||

=for bad | =for bad | |||

xchg does not process bad values. | xchg does not process bad values. | |||

=cut | =cut | |||

#line 1242 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*xchg = \&PDL::xchg; | *xchg = \&PDL::xchg; | |||

#line 1249 "Slices.pm" | ||||

#line 1502 "slices.pd" | #line 1499 "slices.pd" | |||

=head2 reorder | =head2 reorder | |||

=for ref | =for ref | |||

Re-orders the dimensions of a PDL based on the supplied list. | Re-orders the dimensions of a PDL based on the supplied list. | |||

Similar to the L</xchg> method, this method re-orders the dimensions | Similar to the L</xchg> method, this method re-orders the dimensions | |||

of a PDL. While the L</xchg> method swaps the position of two dimensions, | of a PDL. While the L</xchg> method swaps the position of two dimensions, | |||

the reorder method can change the positions of many dimensions at | the reorder method can change the positions of many dimensions at | |||

skipping to change at line 1242 | skipping to change at line 1167 | |||

my $errString = "PDL::reorder: Dim index $newDimOrder[$i] out of r ange in position $i\n(range is 0-$#newDimOrder)"; | my $errString = "PDL::reorder: Dim index $newDimOrder[$i] out of r ange in position $i\n(range is 0-$#newDimOrder)"; | |||

barf($errString); | barf($errString); | |||

} | } | |||

} | } | |||

# Checking that they are all present and also not duplicated is done by broadcast() [I think] | # Checking that they are all present and also not duplicated is done by broadcast() [I think] | |||

# a quicker way to do the reorder | # a quicker way to do the reorder | |||

return $pdl->broadcast(@newDimOrder)->unbroadcast(0); | return $pdl->broadcast(@newDimOrder)->unbroadcast(0); | |||

} | } | |||

#line 1374 "Slices.pm" | #line 1275 "Slices.pm" | |||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 mv | =head2 mv | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx n1; PDL_Indx n2) | Signature: (P(); C(); PDL_Indx n1; PDL_Indx n2) | |||

=for ref | =for ref | |||

move a dimension to another position | move a dimension to another position | |||

skipping to change at line 1276 | skipping to change at line 1199 | |||

The other dimensions are moved accordingly. | The other dimensions are moved accordingly. | |||

Negative dimension indices count from the end. | Negative dimension indices count from the end. | |||

=for bad | =for bad | |||

mv does not process bad values. | mv does not process bad values. | |||

=cut | =cut | |||

#line 1414 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*mv = \&PDL::mv; | *mv = \&PDL::mv; | |||

#line 1421 "Slices.pm" | ||||

#line 1675 "slices.pd" | #line 1676 "slices.pd" | |||

=head2 using | =head2 using | |||

=for ref | =for ref | |||

Returns array of column numbers requested | Returns array of column numbers requested | |||

=for usage | =for usage | |||

line $pdl->using(1,2); | line $pdl->using(1,2); | |||

skipping to change at line 1313 | skipping to change at line 1232 | |||

*using = \&PDL::using; | *using = \&PDL::using; | |||

sub PDL::using { | sub PDL::using { | |||

my ($x,@ind)=@_; | my ($x,@ind)=@_; | |||

@ind = list $ind[0] if (blessed($ind[0]) && $ind[0]->isa('PDL')); | @ind = list $ind[0] if (blessed($ind[0]) && $ind[0]->isa('PDL')); | |||

foreach (@ind) { | foreach (@ind) { | |||

$_ = $x->slice("($_)"); | $_ = $x->slice("($_)"); | |||

} | } | |||

@ind; | @ind; | |||

} | } | |||

#line 1456 "Slices.pm" | #line 1347 "Slices.pm" | |||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 diagonal | =head2 diagonal | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx whichdims[]) | Signature: (P(); C(); PDL_Indx whichdims[]) | |||

=for ref | =for ref | |||

Returns the multidimensional diagonal over the specified dimensions. | Returns the multidimensional diagonal over the specified dimensions. | |||

skipping to change at line 1373 | skipping to change at line 1290 | |||

[0 0 1] | [0 0 1] | |||

] | ] | |||

] | ] | |||

=for bad | =for bad | |||

diagonal does not process bad values. | diagonal does not process bad values. | |||

=cut | =cut | |||

#line 1522 "Slices.pm" | ||||

#line 959 "../../blib/lib/PDL/PP.pm" | ||||

#line 1770 "slices.pd" | ||||

sub PDL::diagonal { shift->_diagonal_int(my $o=PDL->null, \@_); $o } | sub PDL::diagonal { shift->_diagonal_int(my $o=PDL->null, \@_); $o } | |||

#line 1529 "Slices.pm" | #line 1412 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*diagonal = \&PDL::diagonal; | *diagonal = \&PDL::diagonal; | |||

#line 1536 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 lags | =head2 lags | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx nthdim;PDL_Indx step;PDL_Indx n) | Signature: (P(); C(); PDL_Indx nthdim;PDL_Indx step;PDL_Indx n) | |||

=for ref | =for ref | |||

Returns an ndarray of lags to parent. | Returns an ndarray of lags to parent. | |||

skipping to change at line 1431 | skipping to change at line 1341 | |||

C<$step> and C<$nlags> must be positive. C<$nthdim> can be | C<$step> and C<$nlags> must be positive. C<$nthdim> can be | |||

negative and will then be counted from the last dim backwards | negative and will then be counted from the last dim backwards | |||

in the usual way (-1 = last dim). | in the usual way (-1 = last dim). | |||

=for bad | =for bad | |||

lags does not process bad values. | lags does not process bad values. | |||

=cut | =cut | |||

#line 1590 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*lags = \&PDL::lags; | *lags = \&PDL::lags; | |||

#line 1597 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 splitdim | =head2 splitdim | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx nthdim;PDL_Indx nsp) | Signature: (P(); C(); PDL_Indx nthdim;PDL_Indx nsp) | |||

=for ref | =for ref | |||

Splits a dimension in the parent ndarray (opposite of L<clump|PDL::Core/clump>). | Splits a dimension in the parent ndarray (opposite of L<clump|PDL::Core/clump>). | |||

skipping to change at line 1470 | skipping to change at line 1374 | |||

$y->at(6,4,m,n,3,6) == $x->at(6,4,m+3*n) | $y->at(6,4,m,n,3,6) == $x->at(6,4,m+3*n) | |||

is always true (C<m> has to be less than 3). | is always true (C<m> has to be less than 3). | |||

=for bad | =for bad | |||

splitdim does not process bad values. | splitdim does not process bad values. | |||

=cut | =cut | |||

#line 1637 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*splitdim = \&PDL::splitdim; | *splitdim = \&PDL::splitdim; | |||

#line 1644 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 rotate | =head2 rotate | |||

=for sig | =for sig | |||

Signature: (x(n); indx shift(); [oca]y(n)) | Signature: (x(n); indx shift(); [oca]y(n)) | |||

=for ref | =for ref | |||

Shift vector elements along with wrap. Flows data back&forth. | Shift vector elements along with wrap. Flows data back&forth. | |||

=for bad | =for bad | |||

rotate does not process bad values. | rotate does not process bad values. | |||

=cut | =cut | |||

#line 1670 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*rotate = \&PDL::rotate; | *rotate = \&PDL::rotate; | |||

#line 1677 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 broadcastI | =head2 broadcastI | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx id; PDL_Indx whichdims[]) | Signature: (P(); C(); PDL_Indx id; PDL_Indx whichdims[]) | |||

=for ref | =for ref | |||

internal | internal | |||

skipping to change at line 1526 | skipping to change at line 1418 | |||

=for example | =for example | |||

$y = $x->broadcastI(0,1,5); # broadcast over dims 1,5 in id 1 | $y = $x->broadcastI(0,1,5); # broadcast over dims 1,5 in id 1 | |||

=for bad | =for bad | |||

broadcastI does not process bad values. | broadcastI does not process bad values. | |||

=cut | =cut | |||

#line 1710 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*broadcastI = \&PDL::broadcastI; | *broadcastI = \&PDL::broadcastI; | |||

#line 1717 "Slices.pm" | ||||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 unbroadcast | =head2 unbroadcast | |||

=for sig | =for sig | |||

Signature: (P(); C(); PDL_Indx atind) | Signature: (P(); C(); PDL_Indx atind) | |||

=for ref | =for ref | |||

All broadcasted dimensions are made real again. | All broadcasted dimensions are made real again. | |||

See [TBD Doc] for details and examples. | See [TBD Doc] for details and examples. | |||

=for bad | =for bad | |||

unbroadcast does not process bad values. | unbroadcast does not process bad values. | |||

=cut | =cut | |||

#line 1745 "Slices.pm" | ||||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*unbroadcast = \&PDL::unbroadcast; | *unbroadcast = \&PDL::unbroadcast; | |||

#line 1752 "Slices.pm" | ||||

#line 2110 "slices.pd" | #line 2111 "slices.pd" | |||

=head2 dice | =head2 dice | |||

=for ref | =for ref | |||

Dice rows/columns/planes out of a PDL using indexes for | Dice rows/columns/planes out of a PDL using indexes for | |||

each dimension. | each dimension. | |||

This function can be used to extract irregular subsets | This function can be used to extract irregular subsets | |||

along many dimension of a PDL, e.g. only certain rows in an image, | along many dimension of a PDL, e.g. only certain rows in an image, | |||

skipping to change at line 1710 | skipping to change at line 1592 | |||

=cut | =cut | |||

sub PDL::dice_axis { | sub PDL::dice_axis { | |||

my($self,$axis,$idx) = @_; | my($self,$axis,$idx) = @_; | |||

my $ix = PDL->topdl($idx); | my $ix = PDL->topdl($idx); | |||

barf("dice_axis: index must be <=1D") if $ix->getndims > 1; | barf("dice_axis: index must be <=1D") if $ix->getndims > 1; | |||

return $self->mv($axis,0)->index1d($ix)->mv(0,$axis); | return $self->mv($axis,0)->index1d($ix)->mv(0,$axis); | |||

} | } | |||

*dice_axis = \&PDL::dice_axis; | *dice_axis = \&PDL::dice_axis; | |||

#line 1907 "Slices.pm" | #line 1755 "Slices.pm" | |||

#line 958 "../../blib/lib/PDL/PP.pm" | ||||

=head2 slice | =head2 slice | |||

=for sig | =for sig | |||

Signature: (P(); C(); pdl_slice_args *arglist) | Signature: (P(); C(); pdl_slice_args *arglist) | |||

=for usage | =for usage | |||

$slice = $data->slice([2,3],'x',[2,2,0],"-1:1:-1", "*3"); | $slice = $data->slice([2,3],'x',[2,2,0],"-1:1:-1", "*3"); | |||

skipping to change at line 1881 | skipping to change at line 1761 | |||

$x->slice([1,3]); # Same as above three calls, but using array ref syntax | $x->slice([1,3]); # Same as above three calls, but using array ref syntax | |||

$x->slice([3,1]); | $x->slice([3,1]); | |||

$x->slice([-2,1]); | $x->slice([-2,1]); | |||

=for bad | =for bad | |||

slice does not process bad values. | slice does not process bad values. | |||

=cut | =cut | |||

#line 2085 "Slices.pm" | ||||

#line 959 "../../blib/lib/PDL/PP.pm" | ||||

#line 2430 "slices.pd" | ||||

sub PDL::slice { | sub PDL::slice { | |||

my ($source, @others) = @_; | my ($source, @others) = @_; | |||

for my $i(0..$#others) { | for my $i(0..$#others) { | |||

my $idx = $others[$i]; | my $idx = $others[$i]; | |||

if (ref $idx eq 'ARRAY') { | if (ref $idx eq 'ARRAY') { | |||

my @arr = map UNIVERSAL::isa($_, 'PDL') ? $_->flat->at(0) : $_, @{$other s[$i]}; | my @arr = map UNIVERSAL::isa($_, 'PDL') ? $_->flat->at(0) : $_, @{$other s[$i]}; | |||

$others[$i] = \@arr; | $others[$i] = \@arr; | |||

next; | next; | |||

} | } | |||

next if !( blessed($idx) && $idx->isa('PDL') ); | next if !( blessed($idx) && $idx->isa('PDL') ); | |||

skipping to change at line 1921 | skipping to change at line 1799 | |||

$others[$i] = $idx->flat->at(0); | $others[$i] = $idx->flat->at(0); | |||

} | } | |||

else { | else { | |||

#### Zero elements -- force an extended empty. | #### Zero elements -- force an extended empty. | |||

$others[$i] = "1:0:1"; | $others[$i] = "1:0:1"; | |||

} | } | |||

} | } | |||

PDL::_slice_int($source,my $o=$source->initialize,\@others); | PDL::_slice_int($source,my $o=$source->initialize,\@others); | |||

$o; | $o; | |||

} | } | |||

#line 2127 "Slices.pm" | #line 1966 "Slices.pm" | |||

#line 960 "../../blib/lib/PDL/PP.pm" | ||||

*slice = \&PDL::slice; | *slice = \&PDL::slice; | |||

#line 2134 "Slices.pm" | ||||

#line 2599 "slices.pd" | #line 2598 "slices.pd" | |||

=head1 BUGS | =head1 BUGS | |||

For the moment, you can't slice one of the zero-length dims of an | For the moment, you can't slice one of the zero-length dims of an | |||

empty ndarray. It is not clear how to implement this in a way that makes | empty ndarray. It is not clear how to implement this in a way that makes | |||

sense. | sense. | |||

Many types of index errors are reported far from the indexing | Many types of index errors are reported far from the indexing | |||

operation that caused them. This is caused by the underlying architecture: | operation that caused them. This is caused by the underlying architecture: | |||

slice() sets up a mapping between variables, but that mapping isn't | slice() sets up a mapping between variables, but that mapping isn't | |||

skipping to change at line 1953 | skipping to change at line 1828 | |||

Copyright (C) 1997 Tuomas J. Lukka. Contributions by | Copyright (C) 1997 Tuomas J. Lukka. Contributions by | |||

Craig DeForest, deforest@boulder.swri.edu. | Craig DeForest, deforest@boulder.swri.edu. | |||

Documentation contributions by David Mertens. | Documentation contributions by David Mertens. | |||

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. | |||

=cut | =cut | |||

#line 2166 "Slices.pm" | #line 2001 "Slices.pm" | |||

# Exit with OK status | # Exit with OK status | |||

1; | 1; | |||

End of changes. 68 change blocks. | ||||

151 lines changed or deleted | | 26 lines changed or added |