Dear Julia community,
I want to change some values of an existing Matrix with some values that are on another array, but I find that this part of my code is the bottleneck of what I am doing. Is there a better way to do this?
This would be a MWE.
function store_values!(A::Matrix{T}, B::Array{T, 4}) where {T}
@inbounds A[:, :] = [
B[1,1,1,1] B[1,1,2,2] B[1,1,3,3] B[1,1,1,2] B[1,1,2,3] B[1,1,3,1];
B[2,2,1,1] B[2,2,2,2] B[2,2,2,3] B[2,2,1,2] B[2,2,2,3] B[2,2,3,1];
B[3,3,1,1] B[3,3,2,2] B[3,3,3,3] B[3,3,1,2] B[3,3,2,3] B[3,3,3,1];
B[1,2,1,1] B[1,2,2,2] B[1,2,3,3] B[1,2,1,2] B[1,2,2,3] B[1,2,3,1];
B[2,3,1,1] B[2,3,2,2] B[2,3,3,3] B[2,3,1,2] B[2,3,2,3] B[2,3,3,1];
B[3,1,1,1] B[3,1,2,2] B[3,1,3,3] B[3,1,1,2] B[3,1,2,3] B[3,1,3,1]
]
return nothing
end #store_values!
using BenchmarkTools
A = zeros(6, 6)
B = rand(3,3,3,3)
@btime store_values!(A, B) # 1.034 μs (38 allocations: 1.22 KiB)
I have read the docs, but did not find something useful. Please let me know if I am missing something.
Thanks!
Eduardo