The threading engine subtracts the zeroth element from all the values in order. 
 First it subtracts from the zeroth element of $t.  On all subsequent 
iterations the zeroth element is zero and the subtraction is a no-op.


(mobile)


On Jan 4, 2013, at 9:48 PM, Derek Lamb <[email protected]> wrote:

> I had a 1D piddle of time values, and was trying to compute the time offset 
> relative to the initial values.  I got some unexpected results when trying to 
> perform an action like '$t-=$t((0));'  This is with perl 5.14.2, and the 
> (more or less) current PDL git, but holds all the way back to PDL-2.4.7.  I 
> run the following script (for clarity, not in the PDL shell, but it happens 
> there too):
> 
> **************
> $ cat testme.pl
> use PDL;
> use PDL::NiceSlice;
> 
> print "PDL::VERSION $PDL::VERSION\n";
> $t_orig = pdl(12..16);
> print "orig:\t$t_orig\n\n";
> 
> for $i(0..4){
>    $t = $t_orig->copy;
>    $t-=$t(($i));
>    print "nslice\t$t\n";
> 
>    $t = $t_orig->copy;
>    $t-=$t->slice("($i)");
>    print "slice\t$t\n";
> 
>    $t = $t_orig->copy;
>    $t-=$t->at($i);
>    print "at($i)\t$t\n";
> 
>    $t = $t_orig->copy;
>    $t-=pdl($t_orig->at($i));
>    print "pdl\t$t\n";
> 
>    $t = $t_orig->copy;
>    $t = $t - $t(($i));
>    print "exp.nsl\t$t\n\n";
> }
> 
> 1;
> *************
> 
> The script just defines a piddle [12 13 14 15 16] and subtracts off the 0th 
> element in 5 different ways, then the 1st element, etc.  The first four ways 
> (niceslice, slice, at, and pdl) all use the -= operator, and the last one 
> does the explicit assignment via subtraction of a niceslice.  And I get the 
> following output:
> 
> *************
> $ perl testme.pl
> PDL::VERSION 2.4.11_001
> orig:    [12 13 14 15 16]
> 
> nslice    [0 13 14 15 16]
> slice    [0 13 14 15 16]
> at(0)    [0 1 2 3 4]
> pdl    [0 1 2 3 4]
> exp.slc    [0 1 2 3 4]
> 
> nslice    [-1 0 14 15 16]
> slice    [-1 0 14 15 16]
> at(1)    [-1 0 1 2 3]
> pdl    [-1 0 1 2 3]
> exp.slc    [-1 0 1 2 3]
> 
> nslice    [-2 -1 0 15 16]
> slice    [-2 -1 0 15 16]
> at(2)    [-2 -1 0 1 2]
> pdl    [-2 -1 0 1 2]
> exp.slc    [-2 -1 0 1 2]
> 
> nslice    [-3 -2 -1 0 16]
> slice    [-3 -2 -1 0 16]
> at(3)    [-3 -2 -1 0 1]
> pdl    [-3 -2 -1 0 1]
> exp.slc    [-3 -2 -1 0 1]
> 
> nslice    [-4 -3 -2 -1 0]
> slice    [-4 -3 -2 -1 0]
> at(4)    [-4 -3 -2 -1 0]
> pdl    [-4 -3 -2 -1 0]
> exp.slc    [-4 -3 -2 -1 0]
> 
> *************
> 
> For each group of 5 methods, I was expecting the output to be what is shown 
> in the 'at', 'pdl', and 'exp.slc' lines.  Obviously something is not quite 
> correct with the 'nslice', and 'slice' lines.
> 
> So, two questions: 1) why do the nslice and slice lines act on just part of 
> the $t piddle, and not the whole thing?  2) why does the explicit assignment 
> w/ nslice not produce the same output as the -= operation with slice?  I 
> thought they were exactly equivalent, that $a-=$b was just syntactic sugar 
> for $a = $a-$b.
> 
> cheers,
> Derek
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
> 

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to