I don’t know what your real application is, but if the indices array Part
is that simple, you could use a simpler and much faster version as update4!
below. You don’t need to use Part
at all in this case.
function update4!(A_field, A)
for i in eachindex(A)
@views A_field[2i-1:2i] = A[i]
end
end
N = 10
shapeA = (N, N)
Part = [[i, i+1] for i in 1:2:prod(shapeA)]
A = [rand(length(J)) for J in Part]
A_field = zeros(shapeA)
@btime update4!(y, $A) setup = (y = copy(A_field))
218.200 ns (0 allocations: 0 bytes)