Menu

#62 Bug in core with inplace and slicing?

critical
closed-rejected
core (120)
9
2003-05-05
2003-05-05
No

Loaded PDL v2.3.2 (supports bad values)
perldl> $x = pdl([1,2,3,4,5,6,7,8],[5,6,7,8,9,10,11,12]); p $x

[
[ 1 2 3 4 5 6 7 8]
[ 5 6 7 8 9 10 11 12]
]

perldl> p $x(3,:)

[
[4]
[8]
]

perldl> $y = $x / $x(3,:); p $y

[
[ 0.25 0.5 0.75 1 1.25 1.5 1.75 2]
[0.625 0.75 0.875 1 1.125 1.25 1.375 1.5]
]

perldl> $x /= $x(3,:); p $x # EXPECT $x = $y

[
[ 0.25 0.5 0.75 1 5 6 7 8]
[0.625 0.75 0.875 1 9 10 11 12]
]

Note: also occurs if I use the plain slice method
Tried this on OS X and Linux.

- Karl Glazebrook

Discussion

  • Christian Soeller

    • status: open --> closed-rejected
     
  • Christian Soeller

    Logged In: YES
    user_id=1120

    Not a bug. $x(3,:) is a live slice into $x, so as the
    internal division loop proceeds, $x(3,:) gets set to 1 (when
    divided by itself) and all elements encountered after that
    get divided by 1 i.e. stay unchanged.

    Solution: sever link of slice. With current niceslice:

    $x /= $x(3,:;|); # (...;|) implies sever

     
  • Karl Glazebrook

    Karl Glazebrook - 2003-05-05

    Logged In: YES
    user_id=1796

    OK you are right, this is the designed behaviour :-)

    I was stupidly thinking it should copy $spec(3,:) before applying the /=
    operator to $spec.

    Short on neurons today!

     

Log in to post a comment.