On Sat, Jan 5, 2013 at 9:34 AM, David Mertens <[email protected]> wrote:
> Sorry, I should have included this in the email I just sent.
>
> To expand on my comment about affine slices and on what Craig said, the
> first two methods for getting element $i from $t give affine slices. When
> the threading engine sees an affine slice, it lets the kernel of the
> threaded operation operate directly on the original memory. In contrast, the
> $t->at($i) creates a new perl scalar and copies the value into it and
> pdl($t->at($i)) essentially does the same thing. (The perl scalar gets
> PDLified before entering the threadloop, so these two are identical except
> that the PDLificiation is explicit in the second.)
>
> Finally, we come to the NiceSlice mechanism. In this case, NiceSlice sees
> your expression and decides that the result will be a non-affine slice. Upon
> entering the threading engine for the subtraction operation, PDL makes a
> copy of the current state of $t($i)---which is how PDL handles non-affine
> slices in general---and this copied value is used throughout. Thus the copy
> also occurs in this case, but at a different point in the execution of the
> operation than the two previously mentioned cases.
>
> At least, I'm pretty sure that's what happens. :-)

I think that was one explanation too far.  :-)

The problem is not from NiceSlice (or slice),
as this explanation seems to say, but the
fact that you are changing the values on
both sides of the assignment operation at
the same time.

If you sever in the slice then it works as
expected:

pdl> $t_orig = pdl(12..16);

pdl> print "orig:\t$t_orig\n\n";
orig:   [12 13 14 15 16]


pdl> for $i(0..4){ $t = $t_orig->copy; $t-=$t(($i)); print "nslice\t$t\n"; }
nslice  [0 13 14 15 16]
nslice  [-1 0 14 15 16]
nslice  [-2 -1 0 15 16]
nslice  [-3 -2 -1 0 16]
nslice  [-4 -3 -2 -1 0]

pdl> for $i(0..4){ $t = $t_orig->copy; $t-=$t(($i);|); print "nslice\t$t\n"; }
nslice  [0 1 2 3 4]
nslice  [-1 0 1 2 3]
nslice  [-2 -1 0 1 2]
nslice  [-3 -2 -1 0 1]
nslice  [-4 -3 -2 -1 0]

I wanted to clarify that because of the work
underway to refactor the source filter and
don't want random google searches to
scare new PDL users away from NiceSlice.

In fact, the current implementation works
very nicely (as long as you are aware of
its limitations).

This definitely points to a need for some
clear discussion and examples in the
book and our pod.  I wonder if there is
a way to catch  these indeterminate forms
to warn users?

--Chris

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

Reply via email to