This surprised me:
julia> typeof(copy(rand(4,4)'))
Matrix{Float64} (alias for Array{Float64, 2})
julia> typeof(deepcopy(rand(4,4)'))
LinearAlgebra.Adjoint{Float64, Matrix{Float64}}
I have an algorithm which looks prettier when written assuming row-major order. To ensure the code looks pretty and it also runs fast on Julia’s native column-major arrays, I simply used the Adjoint
object. It works great and it is both fast and the code looks nice. However, the speedup was lost when I ran it on copies of my arrays. Personally, I got to fix that simply by using deepcopy
, and it is truly not a problem, but the behavior of copy
surprised me.
This does not seem to be a question of shallow copy vs deep copy, right? It is more of a question related to the fact that copy
implicitly runs collect
on the object it is copying? This sound counterintuitive to me. Is there any rationale behind it, or is it more of a random historic fact?