Hi,

When I index over a Julia array:

julia> x = reshape(1:16, 4, 4)
4x4 Array{Int64,2}:
 1  5   9  13
 2  6  10  14
 3  7  11  15
 4  8  12  16

julia> b =  x[2:3, 2:end-1]
2x2 Array{Int64,2}:
 6  10
 7  11

julia> b[1,1] = 3
3

julia> b
2x2 Array{Int64,2}:
 3  10
 7  11

julia> x
4x4 Array{Int64,2}:
 1  5   9  13
 2  6  10  14
 3  7  11  15
 4  8  12  16

When does the indexed part of the array gets copied to a new block of 
memory ? Is b produced as a different array just after indexing or is it 
copied when one of its elements are changed or does Julia manage this using 
some other technique ?
Another question over this is if we have a very huge array (which somehow 
just fits in RAM), is it possible to do indexing over it without using more 
and more RAM (avoiding copies) ?
Something like Python :
>>> x = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> b = x[1:2,:]
>>> b
array([[4, 5, 6]])
>>> b[0] = 0
>>> x
array([[1, 2, 3],
       [0, 0, 0],
       [7, 8, 9]])

I am not aware of how Julia actually works while indexing and it might be 
doing something cool like clojure to manage such indexes and avoid copies, 
so please forgive if the question is really stupid.

Reply via email to