7
eval 'require PDL::NiceSlice';
12
print "ok 1 # Skipped: no sourcefilter support\n";
18
sub PDL::NiceSlice::findslice;
19
sub translate_and_show {
21
my $etxt = PDL::NiceSlice::findslice $txt;
22
print "$txt -> \n\t$etxt\n";
29
my $a = sequence 10; # shut up -w
31
eval translate_and_show '$b = $a((5));';
36
eval translate_and_show '$b = $a->((5));';
40
my $c = PDL->pdl(7,6);
41
eval translate_and_show '$b = $a(($c(1)->at(0)));';
43
ok($b->getndims == 0 && all $b == 6);
45
# the latest versions should do the 'at' automatically
46
eval translate_and_show '$b = $a(($c(1)));';
48
ok($b->getndims == 0 && all $b == 6);
50
eval translate_and_show '$c = $a(:);';
53
ok ($c->getdim(0) == 10 && all $c == $a);
57
eval translate_and_show '$b = $a($idx);';
61
# use 1-el piddles as indices
64
eval translate_and_show '$b = $a($rg(0):$rg(1):$rg(2));';
68
# mix ranges and index piddles
69
my $twod = sequence 5,5;
71
$cmp = $twod->slice('-1:0')->dice_axis(1,$idx);
72
eval translate_and_show '$b = $twod(-1:0,$idx);';
79
eval translate_and_show '$b = $a($a<3;?)';
81
ok(all $b == pdl(0,1,2));
84
eval translate_and_show '$b = $a(0:-2;_);';
86
ok(all $b == sequence 8);
88
# foreach/for blocking
91
eval translate_and_show "foreach \n" . ' $b(1,2,3,4) {$a .= $b;}';
92
ok(!$@ and $a eq '1234');
95
eval translate_and_show 'for $b(1,2,3,4) {$a .= $b;}';
96
ok(!$@ and $a eq '1234');