Consider the following example:
julia> u0 = SharedArray{Float64}(2,3)
2×3 SharedArray{Float64,2}:
0.0 0.0 0.0
0.0 0.0 0.0
julia> u1 = copy(u0)
2×3 Array{Float64,2}:
0.0 0.0 0.0
0.0 0.0 0.0
I would have expected u1::typeof(u0)
. This behaviour is due to the definition of similar
for SharedArray
s in https://github.com/JuliaLang/julia/blob/0d7248e2ff65bd6886ba3f003bf5aeab929edab5/base/sharedarray.jl#L538, giving
julia> u0 = SharedArray{Float64}(2,3)
2×3 SharedArray{Float64,2}:
0.0 0.0 0.0
0.0 0.0 0.0
julia> similar(u0)
2×3 Array{Float64,2}:
6.92442e-310 6.92442e-310 6.92442e-310
6.92442e-310 6.92442e-310 6.92442e-310
Here, I would have expected similar(u0)::typeof(u0)
.
I’m using julia v0.6.1
julia> versioninfo()
Julia Version 0.6.1-pre.1
Commit 4b967d4a9d* (2017-08-21 21:11 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i5-4590S CPU @ 3.00GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
I would like to understand the reasoning for this implementation. Could someone please explain me the reason for this behaviour?
Since copy(u0)
is not of the same type as u0
, SharedArray
s cannot be used in DifferentialEquations.jl (OrdinaryDiffEq.jl) up to now.