Function to view the form?

In Julia v0.5, how do you make a function that resembles reshape but returns a view instead? ArrayViews.jl has a reshape_view function, but it does not seem directly compatible with the new function view. I just want reshape uto sizeugo to some set where I don't know the sizes.

+4
source share
1 answer

If you change the view form, the output will be the changed view.

If your initial variable is a regular array, you can convert it to an on-the-fly representation during a function call.

: pointer. , , "", .

julia> A = ones(5,5,5); B = view(A, 2:4, 2:4, 2:4); C = reshape(B, 1, 27);

julia> is(B,C)
false

julia> pointer(B)
Ptr{Float64} @0x00007ff51e8b1ac8

julia> pointer(C)
Ptr{Float64} @0x00007ff51e8b1ac8

julia> C[1:5] = zeros(1,5);

julia> A[:,:,2]
5×5 Array{Float64,2}:
 1.0  1.0  1.0  1.0  1.0
 1.0  0.0  0.0  1.0  1.0
 1.0  0.0  0.0  1.0  1.0
 1.0  0.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0
+6

Source: https://habr.com/ru/post/1650233/


All Articles