I'm too Lazy to go back and look for it, but it was in the discussion of
generalized Empty variables -- I hadn't encountered this particular wart,
before dealing with the even more peculiar case of what happens when an Empty
ends up
on the LHS of ".=".
To recap: in Ingo's case, destructive indexing should have been used:
$x(,(0),(0),(0),(0),) += $y; # what should have been used (DWIM)
$x(,0,0,0,0,) += $y # what Ingo demonstrated
In this case, the non-destructive indexing gives an LHS dim list of (4,1,...),
which matches the RHS dim list of (4,10) by the generalized scalar rule -- so
the LHS gets a dummy dimension of size 10 in position 1. The 10 rows of $y
are thus copied, one after the other, into the same row of $x, and the first
nine rows are dropped on the floor.
It seems to me that, in the long term (2.5?), the threading engine should be
given an "assignment flag" or something, to prevent generalized scalar
expansion in lvalues -- or at least to issue a warning if it is attempted.
Since computed assignment to generalized scalars can't actually do anything
useful (or at least anything non-surprising), it makes sense to mask it out.
On Jan 30, 2012, at 9:26 AM, David Mertens wrote:
> Ingo -
>
> Craig discussed this recently, though I cannot find the thread. The problem
> is that the general threading rules are very generic, so this is one of those
> situations where consistency in the threading engine leads to weird behavior.
> A simple example is here:
>
> pdl> $x = ones(5)
> pdl> $y = sequence(5,4)
> pdl> $x .= $y
> pdl p $x
> [15 16 17 18 19]
>
> Bear in mind that if I'm assigning $x to $y, this would DWIM, but the inverse
> is only confusing.
>
> Craig, do you remember the email in which you discussed this?
>
> David
>
> On Mon, Jan 30, 2012 at 8:20 AM, Ingo Schmid <[email protected]> wrote:
> when adding ;-, mv(-1,1) in the += statement, I get the expected result.
>
> If the sloppy code is not expected to work, please barf, but do not continue
> with nonsense!
>
> Cheers
> Ingo
>
> pdl> $x=zeroes(4,5,3,2,3,10)
> pdl> $y=floor random(4,10)*20
> $x(,0,0,0,0,)+=$y
>
> pdl> p $y
>
> [
> [ 4 7 3 16]
> [ 0 9 8 4]
> [15 10 10 6]
> [17 4 19 10]
> [15 3 0 6]
> [13 13 6 3]
> [ 8 6 13 4]
> [ 4 13 15 11]
> [ 0 6 18 3]
> [15 10 6 18]
> ]
> pdl> p $x(,0,0,0,0,;-)
>
> [
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> [91 81 98 81]
> ]
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>
>
>
> --
> Sent via my carrier pigeon.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl