My understanding is that in numpy these aliasing operations are NOT well- defined; that is, they may produce sensible results but there is not guarantee.
If for example memcpy was used for this, then copying overlapping ranges in one direction might work, but not in the reverse direction. Keno Fischer wrote: > The python example doesn't show anything different. The matlab example does > in that it returns x (though not the slice assigned to). The real > difference to python is this: > >>>> x = numpy.arange(1,11) >>>> y = x[0:9] = x[1:10] >>>> y > array([ 3, 4, 5, 6, 7, 8, 9, 10, 10]) > > so in python that means > x[0:9] = x[1:10] > y = x[1:10] > > whereas in Julia it means > > temp = x[1:10] > x = temp > y = temp > > > > > On Fri, May 9, 2014 at 2:59 AM, Dominique Orban > <[email protected]>wrote: > >> Is that *really* the intended effect??? Python and Matlab seem much more >> intuitive and return something sensible: >> >> >> x = [1:10]; >> >> x(1:9) = x(2:10) >> >> x = >> 2 3 4 5 6 7 8 9 10 10 >> >> >> >>> import numpy >> >>> x = numpy.arange(1,11) >> >>> x[0:9] = x[1:10] >> >>> x >> array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]) >> >> >> On Thursday, May 8, 2014 8:59:58 PM UTC-7, Jeff Bezanson wrote: >> >>> Yes, it is well-defined. The right-hand side is returned, which might >>> cause some confusion here. >>> >>> On Thu, May 8, 2014 at 10:10 AM, Neal Becker >>> <[email protected]> wrote: >>> > Is the following well-defined in julia? >>> > >>> > julia> x = [1:10] >>> > 10-element Array{Int64,1}: >>> > 1 >>> > 2 >>> > 3 >>> > 4 >>> > 5 >>> > 6 >>> > 7 >>> > 8 >>> > 9 >>> > 10 >>> > >>> > julia> x[1:9] = x[2:10] >>> > 9-element Array{Int64,1}: >>> > 2 >>> > 3 >>> > 4 >>> > 5 >>> > 6 >>> > 7 >>> > 8 >>> > 9 >>> > 10 >>> > >>> > In general, are all such aliased assignments well-defined (all, as in >>> for >>> > arbitrary ranges)? >>> > >>> >>
