diff --git a/Basic/Slices/slices.pd b/Basic/Slices/slices.pd index 4e5c48ebf..7d4debf3c 100644 --- a/Basic/Slices/slices.pd +++ b/Basic/Slices/slices.pd @@ -2540,7 +2540,7 @@ SLICE-MC PDL_Indx end = $COMP(end)[i]; if( /** Trap special case: full slices of an empty dim are empty **/ - (pdsize==0 && start==0 && end==-1 && $COMP(inc)[i] == 0) + (pdsize==0 && start==0 && end==-1 && ($COMP(inc)[i] == 0 || $COMP(inc)[i] == 1)) || /* the values given when PDL::slice gets empty ndarray for index */ (start==1 && end==0 && $COMP(inc)[i] == 1) @@ -2556,7 +2556,7 @@ SLICE-MC if(i >= $PDL(PARENT)->ndims) { $CROAK("slice has too many dims (indexes dim %"IND_FLAG"; highest is %"IND_FLAG")",i,$PDL(PARENT)->ndims-1); } else { - $CROAK("slice starts out of bounds in pos %"IND_FLAG" (start is %"IND_FLAG"; source dim %"IND_FLAG" runs 0 to %"IND_FLAG")",i,start,$COMP(idim)[i],pdsize-1); + $CROAK("slice starts out of bounds in pos %"IND_FLAG" (start is %"IND_FLAG"; end is %"IND_FLAG"; inc is %"IND_FLAG"; source dim %"IND_FLAG" runs 0 to %"IND_FLAG")",i,start,end,$COMP(inc)[i],$COMP(idim)[i],pdsize-1); } } if( $COMP(odim)[i] < 0) { diff --git a/t/slice.t b/t/slice.t index 17d061911..628f357bd 100644 --- a/t/slice.t +++ b/t/slice.t @@ -171,13 +171,14 @@ for ( [pdl([1]), [pdl([])], pdl([]), "slice 1-elt ndarray with empty"], [$x1, [pdl([])], pdl([]), "slice 2-elt ndarray with empty"], [$x1, [pdl(1)], pdl([2]), "slice 2-elt ndarray with length-1 ndarray"], + [zeroes(2,1,0), [\[[],[0,0,0],[]]], zeroes(2,0), "squeeze empty"], ) { my ($src, $sl, $exp, $label) = @$_; my $y = $src; - $y = eval { $y->slice($_)->make_physical } for ref $sl ? @$sl : $sl; + $y = eval { $y->slice(ref($_) eq 'REF' ? @$$_ : $_)->make_physical } for ref $sl ? @$sl : $sl; like($@, $exp, "$label right error"), next if ref($exp) eq 'Regexp'; is $@, '', "$label works"; - is_deeply([$y->dims], ref($exp) eq 'ARRAY' ? $exp : [$exp->dims], "$label dims right"); + is_deeply([$y->dims], ref($exp) eq 'ARRAY' ? $exp : [$exp->dims], "$label dims right") or diag explain [$y->dims]; next if ref($exp) eq 'ARRAY'; is $y->nelem, $exp->nelem, "$label works right"; ok tapprox($y, $exp), "$label works right";