In Julia 0.7 I get an error in the following code:
a=rand(10,10)
index1 = CartesianIndices((1:2,1:2))
index2 = CartesianIndices((1:2,1:2))
a1 = view(a,index1)
a1[index2]=rand(2,2)
ArgumentError: an array of type `CartesianIndices` shares memory with another argument and must
make a preventative copy of itself in order to maintain consistent semantics,
but `copy(A)` returns a new array of type `Array{CartesianIndex{2},2}`. To fix, implement:
`Base.unaliascopy(A::CartesianIndices)::typeof(A)`
Is this a bug or intended behavior? The error only occurs when index1==index2
so when the full view is accessed. Note also that this is an MWE, I know that in this case I could simply do a[:]=rand(2,2)
which works, but in my case the indices are computed and may or may not span over the full array.
I just realized that a[index2.indices...]
actually works, does this have any performance implications?