Dear Julia experts,
I have been struggling a few hours to understand a massive slow down (x1000) of some computations. I finally spotted the problem to be caused by the use of array views in a context where one (at least myself) could think that it should cause no arm…
I join the following MWE
using BenchmarkTools function test() nx=10 ny=20 nz=30 nxyz=nx*ny*nz x1D=zeros(Float64,nxyz) y1D=zeros(Float64,nxyz) copyto!(x1D,1:nxyz) x3D=reshape(x1D,(nx,ny,nz)) y3D=reshape(y1D,(ny,nz,nx)) t=@belapsed permutedims!($y3D,$x3D,(2,3,1)) println("time permutedims: ",t) x3Dv=reshape(view(x1D,1:nxyz),(nx,ny,nz)) y3Dv=reshape(view(y1D,1:nxyz),(ny,nz,nx)) tv=@belapsed permutedims!($y3Dv,$x3Dv,(2,3,1)) println("time permutedims (view): ",tv) println(" slow down factor:",tv/t) end test()
I wonder about the opportunity to reduce the risk of this kind of mistake like a warning when views are used with linear indexing or, a different kind of view when it refers to a contiguous piece of data. What is your opinion ?