-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
needs decisionA decision on this change is neededA decision on this change is needed
Description
Right now, calling reshape
on a SubArray allocates memory, which means that reshaping a slice causes you to lose your view into the original data. See the example below for the kinds of situations you might find yourself in.
julia> a = ones(9)
9-element Array{Float64,1}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
julia> b = reshape(a, 3, 3)
3x3 Array{Float64,2}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0
julia> b[3, 3] = 9.0
9.0
julia> a
9-element Array{Float64,1}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
9.0
julia> c = slice(a, 4:9)
6-element SubArray{Float64,1,Array{Float64,1},(UnitRange{Int64},),1}:
1.0
1.0
1.0
1.0
1.0
9.0
julia> c[1] = 4.0
4.0
julia> a
9-element Array{Float64,1}:
1.0
1.0
1.0
4.0
1.0
1.0
1.0
1.0
9.0
julia> d = reshape(c, 3, 2)
3x2 Array{Float64,2}:
4.0 1.0
1.0 1.0
1.0 9.0
julia> d[2, 1] = 5.0
5.0
julia> a
9-element Array{Float64,1}:
1.0
1.0
1.0
4.0
1.0
1.0
1.0
1.0
9.0
Metadata
Metadata
Assignees
Labels
needs decisionA decision on this change is neededA decision on this change is needed