Undef for Array and SharedArray initialisation

I feel like I’m a bit late to the party on this one but I’m only now getting around to updating some code originally written in Julia 0.3, and was surprised to see this:

Array{Float64}(100) now raises a warning telling me to use Array{Float64}(undef, 100) instead. I’ve found the reference in the docs, but still don’t quite understand why undef is now required.

However, upon updating all my code I also made this change to a SharedArray constructor, to find that this raises an error as SharedArray doesn’t have a method that includes the undef argument. Can someone explain the reasoning behind this?

(NB this is all on Julia 0.7.0 on Win10)

Array{T}(100) has always created an array filled with uninitialized memory, but that wasn’t particularly obvious from the syntax. Providing the undef arg makes that more obvious and also provides a way to specify other kinds of initializations in the future.

I think SharedArray has its own init arg to control initialization, although it would be nice for it to share the same API.

For all the gory details: https://github.com/JuliaLang/julia/issues/24595

1 Like

Great thanks, I’ve opened an issue, as I think aligning the API here would be a useful change to make.