module mbas001
elxs = fill(Matrix{Float64}(undef, 3, 3), 7)
for _i in eachindex(elxs)
elxs[_i] = rand(3, 3)
end
ex = fill(zero(Float64), 3, 3)
copy2ex!(ex, elxs, j, k) = let
elxsc = elxs[c]
for _i in axes(ex, 2)
ex[1, _i] = elxsc[j, _i];
ex[2, _i] = elxsc[k, _i];
end
ex
end
c = 4
@time let
ex[1,:] = elxs[c][1,:]; ex[2,:] = elxs[c][2,:];
end
@time copy2ex!(ex, elxs, 1, 2)
@time copy2ex!(ex, elxs, 1, 2)
@time copy2ex!(ex, elxs, 1, 2)
end
produces
julia> include("C:\\Users\\pkonl\\Documents\\00WIP\\HelmBEM.jl\\test\\littletest.jl")
WARNING: replacing module mbas001.
0.000023 seconds (6 allocations: 224 bytes)
0.018632 seconds (9.56 k allocations: 517.691 KiB, 99.73% compilation time)
0.000017 seconds (6 allocations: 96 bytes)
0.000016 seconds (6 allocations: 96 bytes)
Main.mbas001
What puzzles me is why the function copy2ex!
allocates memory.
It happens in the loop
for _i in axes(ex, 2)
ex[1, _i] = elxsc[j, _i];
ex[2, _i] = elxsc[k, _i];
end
Which, in my understanding, should be simply assignment of one matrix location the value of another matrix location. In other words, scalars.