Slices.pm (PDL-2.077) | : | Slices.pm (PDL-2.078) | ||
---|---|---|---|---|
skipping to change at line 333 | skipping to change at line 333 | |||
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 364 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*index2d = \&PDL::index2d; | *index2d = \&PDL::index2d; | |||
#line 371 "Slices.pm" | #line 371 "Slices.pm" | |||
#line 299 "slices.pd" | #line 245 "slices.pd" | |||
=head2 indexNDb | =head2 indexNDb | |||
=for ref | =for ref | |||
Backwards-compatibility alias for indexND | Backwards-compatibility alias for indexND | |||
=head2 indexND | =head2 indexND | |||
=for ref | =for ref | |||
skipping to change at line 383 | skipping to change at line 383 | |||
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 426 "Slices.pm" | #line 425 "Slices.pm" | |||
#line 352 "slices.pd" | #line 297 "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) { | |||
skipping to change at line 423 | skipping to change at line 423 | |||
$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 472 "Slices.pm" | #line 471 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 *boundary_sv) | |||
=for ref | =for ref | |||
skipping to change at line 637 | skipping to change at line 637 | |||
[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 = new PDL::RandVar->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 | |||
them. | them. | |||
skipping to change at line 679 | skipping to change at line 679 | |||
PDL with every atomic perl operation, even if you only touch a single element. | PDL with every atomic perl operation, even if you only touch a single element. | |||
One way to speed up such code is to sever your range, so that PDL | One way to speed up such code is to sever your range, so that PDL | |||
doesn't have to copy the data with each operation, then copy the | doesn't have to copy the data with each operation, then copy the | |||
elements explicitly at the end of your loop. Here's an example that | elements explicitly at the end of your loop. Here's an example that | |||
labels each region in a range sequentially, using many small | labels each region in a range sequentially, using many small | |||
operations rather than a single xvals assignment: | operations rather than a single xvals assignment: | |||
### How to make a collection of small ops run fast with range... | ### How to make a collection of small ops run fast with range... | |||
$x = $data->range($index, $sizes, $bound)->sever; | $x = $data->range($index, $sizes, $bound)->sever; | |||
$aa = $data->range($index, $sizes, $bound); | $aa = $data->range($index, $sizes, $bound); | |||
map { $x($_ - 1) .= $_; } (1..$x->nelem); # Lots of little ops | $x($_ - 1) .= $_ for 1..$x->nelem; # Lots of little ops | |||
$aa .= $x; | $aa .= $x; | |||
C<range> is a perl front-end to a PP function, C<rangeb>. Calling | C<range> is a perl front-end to a PP function, C<rangeb>. Calling | |||
C<rangeb> is marginally faster but requires that you include all arguments. | C<rangeb> is marginally faster but requires that you include all arguments. | |||
DEVEL NOTES | DEVEL NOTES | |||
* 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. | |||
=cut | =cut | |||
=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 756 "Slices.pm" | #line 754 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*rangeb = \&PDL::rangeb; | *rangeb = \&PDL::rangeb; | |||
#line 763 "Slices.pm" | #line 761 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 731 | skipping to change at line 731 | |||
=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. | 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 797 "Slices.pm" | #line 795 "Slices.pm" | |||
#line 1059 "../../blib/lib/PDL/PP.pm" | #line 1059 "../../blib/lib/PDL/PP.pm" | |||
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 818 "Slices.pm" | #line 816 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*rld = \&PDL::rld; | *rld = \&PDL::rld; | |||
#line 825 "Slices.pm" | #line 823 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 808 | skipping to change at line 808 | |||
$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. | |||
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 885 "Slices.pm" | #line 883 "Slices.pm" | |||
#line 1059 "../../blib/lib/PDL/PP.pm" | #line 1059 "../../blib/lib/PDL/PP.pm" | |||
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 899 "Slices.pm" | #line 897 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*rle = \&PDL::rle; | *rle = \&PDL::rle; | |||
#line 906 "Slices.pm" | #line 904 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*_clump_int = \&PDL::_clump_int; | *_clump_int = \&PDL::_clump_int; | |||
#line 913 "Slices.pm" | #line 911 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 863 | skipping to change at line 863 | |||
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. | |||
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 953 "Slices.pm" | #line 951 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*xchg = \&PDL::xchg; | *xchg = \&PDL::xchg; | |||
#line 960 "Slices.pm" | #line 958 "Slices.pm" | |||
#line 1327 "slices.pd" | #line 1269 "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 990 | skipping to change at line 990 | |||
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 1085 "Slices.pm" | #line 1083 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 1024 | skipping to change at line 1024 | |||
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. | |||
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 1125 "Slices.pm" | #line 1123 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*mv = \&PDL::mv; | *mv = \&PDL::mv; | |||
#line 1132 "Slices.pm" | #line 1130 "Slices.pm" | |||
#line 1503 "slices.pd" | #line 1445 "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 1061 | skipping to change at line 1061 | |||
*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 1167 "Slices.pm" | #line 1165 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 1121 | skipping to change at line 1121 | |||
[0 0 1] | [0 0 1] | |||
] | ] | |||
] | ] | |||
=for bad | =for bad | |||
diagonal does not process bad values. | diagonal 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 1233 "Slices.pm" | #line 1231 "Slices.pm" | |||
#line 1059 "../../blib/lib/PDL/PP.pm" | #line 1059 "../../blib/lib/PDL/PP.pm" | |||
sub PDL::diagonal { shift->_diagonal_int(my $o=PDL->null, \@_); $o } | sub PDL::diagonal { shift->_diagonal_int(my $o=PDL->null, \@_); $o } | |||
#line 1240 "Slices.pm" | #line 1238 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*diagonal = \&PDL::diagonal; | *diagonal = \&PDL::diagonal; | |||
#line 1247 "Slices.pm" | #line 1245 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 1179 | skipping to change at line 1179 | |||
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. | |||
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 1301 "Slices.pm" | #line 1299 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*lags = \&PDL::lags; | *lags = \&PDL::lags; | |||
#line 1308 "Slices.pm" | #line 1306 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 1218 | skipping to change at line 1218 | |||
$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. | |||
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 1348 "Slices.pm" | #line 1346 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*splitdim = \&PDL::splitdim; | *splitdim = \&PDL::splitdim; | |||
#line 1355 "Slices.pm" | #line 1353 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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. | |||
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 1381 "Slices.pm" | #line 1379 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*rotate = \&PDL::rotate; | *rotate = \&PDL::rotate; | |||
#line 1388 "Slices.pm" | #line 1386 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 1274 | skipping to change at line 1274 | |||
=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. | |||
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 1421 "Slices.pm" | #line 1419 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*broadcastI = \&PDL::broadcastI; | *broadcastI = \&PDL::broadcastI; | |||
#line 1428 "Slices.pm" | #line 1426 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../blib/lib/PDL/PP.pm" | |||
=head2 unbroadcast | =head2 unbroadcast | |||
=for sig | =for sig | |||
Signature: (P(); C(); int atind) | Signature: (P(); C(); int atind) | |||
=for ref | =for ref | |||
skipping to change at line 1301 | skipping to change at line 1301 | |||
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. | |||
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 1456 "Slices.pm" | #line 1454 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*unbroadcast = \&PDL::unbroadcast; | *unbroadcast = \&PDL::unbroadcast; | |||
#line 1463 "Slices.pm" | #line 1461 "Slices.pm" | |||
#line 1948 "slices.pd" | #line 1890 "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 1458 | skipping to change at line 1458 | |||
=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 1619 "Slices.pm" | #line 1617 "Slices.pm" | |||
#line 1058 "../../blib/lib/PDL/PP.pm" | #line 1058 "../../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 | |||
skipping to change at line 1629 | skipping to change at line 1629 | |||
$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. | |||
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 1797 "Slices.pm" | #line 1795 "Slices.pm" | |||
#line 1059 "../../blib/lib/PDL/PP.pm" | #line 1059 "../../blib/lib/PDL/PP.pm" | |||
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; | |||
skipping to change at line 1669 | skipping to change at line 1669 | |||
$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 1839 "Slices.pm" | #line 1837 "Slices.pm" | |||
#line 1060 "../../blib/lib/PDL/PP.pm" | #line 1060 "../../blib/lib/PDL/PP.pm" | |||
*slice = \&PDL::slice; | *slice = \&PDL::slice; | |||
#line 1846 "Slices.pm" | #line 1844 "Slices.pm" | |||
#line 2439 "slices.pd" | #line 2381 "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 1701 | skipping to change at line 1701 | |||
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 1878 "Slices.pm" | #line 1876 "Slices.pm" | |||
# Exit with OK status | # Exit with OK status | |||
1; | 1; | |||
End of changes. 43 change blocks. | ||||
44 lines changed or deleted | 44 lines changed or added |