Skip to content

Commit

Permalink
Fix sf.net bug #369 slice fails with subclass index
Browse files Browse the repository at this point in the history
  • Loading branch information
devel-chm committed Feb 2, 2015
1 parent a69b4d7 commit c958a32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Basic/Slices/slices.pd
Expand Up @@ -60,6 +60,7 @@ C<-E<gt>copy> they would not.
=cut

use PDL::Core ':Internal';
use Scalar::Util 'blessed';

EOD

Expand Down Expand Up @@ -2112,7 +2113,7 @@ Plot, as a line, column 1 of C<$pdl> vs. column 2
*using = \&PDL::using;
sub PDL::using {
my ($x,@ind)=@_;
@ind = list $ind[0] if (ref $ind[0] eq 'PDL');
@ind = list $ind[0] if (blessed($ind[0]) && $ind[0]->isa('PDL'));
foreach (@ind) {
$_ = $x->slice("($_)");
}
Expand Down Expand Up @@ -2961,7 +2962,7 @@ sub PDL::slice (;@) {
# converted into slices for faster handling later.

for my $i(0..$#others) {
if( ref $others[$i] eq 'PDL' ) {
if( blessed($others[$i]) && $others[$i]->isa('PDL') ) {
my $idx = $others[$i];
if($idx->ndims > 1) {
barf("slice: dicing parameters must be at most 1D (arg $i)\n");
Expand Down
7 changes: 6 additions & 1 deletion t/subclass2.t
Expand Up @@ -9,7 +9,7 @@
### then $pdlderived->sumover should return a PDL::derived object.
###
use PDL::LiteF;
use Test::More tests => 13;
use Test::More tests => 14;


# Test PDL Subclassing via hashes
Expand Down Expand Up @@ -131,3 +131,8 @@ ok(ref($w) eq "PDL::Derived", "check type for bifuncs operation");
$a = PDL::Derived->new(1+(xvals zeroes 4,5) + 10*(yvals zeroes 4,5));
$w = $a->slice('1:3:2,2:4:2');
ok(ref($w) eq "PDL::Derived", "check type for slicing operation");

##### Check that slicing with a subclass index works (sf.net bug #369)
$a = sequence(10,3,2);
$idx = PDL::Derived->new(2,5,8);
ok(defined(eval 'my $r = $a->slice($idx,"x","x");'), "slice works with subclass index");

0 comments on commit c958a32

Please sign in to comment.