I thought the view function worked something like a refererence in c++, basically both variables are pointing to the same piece of memory.
Why does this work:
julia> a = [1 2 3; 4 5 6; 7 8 9]
3×3 Array{Int64,2}:
1 2 3
4 5 6
7 8 9
julia> b = view(a, 1, :)
3-element view(::Array{Int64,2}, 1, :) with eltype Int64:
1
2
3
julia> b[1] = 100
100
julia> a
3×3 Array{Int64,2}:
100 2 3
4 5 6
7 8 9
julia> a[1, 3] = 200
200
julia> b
3-element view(::Array{Int64,2}, 1, :) with eltype Int64:
100
2
200
Basically you change one and the other changes, too, and vice versa. But this doesn't have the same effect:
julia> a = [1 2 3; 4 5 6; 7 8 9]
3×3 Array{Int64,2}:
1 2 3
4 5 6
7 8 9
julia> a[3, :] = view(a, 1, :)
3-element view(::Array{Int64,2}, 1, :) with eltype Int64:
1
2
3
julia> a
3×3 Array{Int64,2}:
1 2 3
4 5 6
1 2 3
julia> a[1, 1] = 100
100
julia> a
3×3 Array{Int64,2}:
100 2 3
4 5 6
1 2 3
julia> a[3, 1] = 200
200
julia> a
3×3 Array{Int64,2}:
100 2 3
4 5 6
200 2 3
My question: Is that equivalent to just doing: a[3, :] = a[1, :]? Do either have any performance benefits? What is happening behind the scenes on that second scenario?
Any feedback is appreciated!