Skip to content

Commit

Permalink
Speeds up range by 20%-50% depending on use pattern, just by not copy…
Browse files Browse the repository at this point in the history
…ing the index variable extra times.
  • Loading branch information
Craig DeForest committed Apr 22, 2015
1 parent 14796ae commit 00ec0a1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Basic/Slices/slices.pd
Expand Up @@ -409,8 +409,9 @@ pp_addpm(<<'EOD-range');

sub PDL::range {
my($source,$ind,$sz,$bound) = @_;
my $index = PDL->pdl($ind);

# 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 $size = defined($sz) ? PDL->pdl($sz) : undef;


Expand Down Expand Up @@ -783,7 +784,7 @@ switch(ind_pdl->datatype) {
PDL->converttype(&ind_pdl,PDL_IND,1); /* convert in place. */
break;
case PDL_IND:
/* do nothing */
PDL->make_physical(ind_pdl);
break;
}

Expand Down Expand Up @@ -890,6 +891,7 @@ switch(ind_pdl->datatype) {
PDL->converttype(&size_pdl,PDL_IND,1); /* convert in place. */
break;
case PDL_IND:
PDL->make_physical(size_pdl);
break;
}

Expand Down Expand Up @@ -1083,7 +1085,11 @@ EOD-RedoDims
if(ck < 0 || ck >= $PARENT_P(dims[k])) {
switch($COMP(boundary[k])) {
case 0: /* no boundary breakage allowed */
barf("index out-of-bounds in range");
{
char barfstr[1024];
sprintf(barfstr,"index out-of-bounds in range (index vector #%ld)",item);
barf(barfstr);
}
break;
case 1: /* truncation */
trunc = 1;
Expand Down

0 comments on commit 00ec0a1

Please sign in to comment.