Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

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 authored and mohawk2 committed Aug 30, 2015
1 parent a46d2e0 commit 5627b9d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Basic/Slices/slices.pd
Expand Up @@ -409,11 +409,10 @@ pp_addpm(<<'EOD-range');

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

# Convert to indx type up front (also handled in rangeb if necessary)
my $index = (ref $ind && UNIVERSAL::isa($ind,'PDLA') && $ind->type eq 'indx') ? $ind : indx($ind);
my $size = defined($sz) ? PDLA->pdl($sz) : undef;


# Handle empty PDLA case: return a properly constructed Empty.
if($index->isempty) {
my @sdims= $source->dims;
Expand Down Expand Up @@ -783,7 +782,7 @@ switch(ind_pdl->datatype) {
PDLA->converttype(&ind_pdl,PDLA_IND,1); /* convert in place. */
break;
case PDLA_IND:
/* do nothing */
PDLA->make_physical(ind_pdl);
break;
}

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

Expand Down Expand Up @@ -1083,7 +1083,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 5627b9d

Please sign in to comment.