Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Array{T,N}(nothing/missing, dims) convenience constructors #25054

Merged
merged 1 commit into from
Dec 16, 2017

Conversation

nalimilan
Copy link
Member

These are shorthands for fill!(Array{T,N}(uninitialized, dims), nothing/missing). In the future they could be optimized for isbits Union types in which nothing/missing is the first type of the Union, since such arrays are already filled with nothing/missing.

This implements solution 3. from #24939, which got broad support.

I haven't found a way to attach the new docstrings to the new methods rather than to the general docstring for the function/type, given that methods are generated using @eval with a loop. Anyway the docstrings describe both the nothing and the missing method, so that sounds unavoidable to limit duplication.

@nalimilan nalimilan added arrays [a, r, r, a, y, s] missing data Base.missing and related functionality labels Dec 13, 2017
base/docs/basedocs.jl Outdated Show resolved Hide resolved
@nalimilan
Copy link
Member Author

The new definitions cause weird redefinition warnings during bootstrap:

WARNING: Method definition (::Type{Array{T, N}})(Void, Integer...) where {T, N} in module Inference at array.jl:398 overwritten in module Base at array.jl:398.
WARNING: Method definition (::Type{Array{T, N}})(Void, Tuple{Vararg{Integer, N}}) where {T, N} in module Inference at array.jl:400 overwritten in module Base at array.jl:400.
WARNING: Method definition (::Type{Array{T, N} where N})(Void, Integer...) where {T, N} in module Inference at array.jl:403 overwritten in module Base at array.jl:403.
WARNING: Method definition (::Type{Array{T, N} where N})(Void, Tuple{Vararg{Integer, N}}) where {T, N} in module Inference at array.jl:405 overwritten in module Base at array.jl:405.

For some reason, they do not happen with the ::Missing methods.

@@ -7,15 +7,19 @@ Core.AbstractArray
Base.AbstractVector
Base.AbstractMatrix
Core.Array
Core.Array(::Any)
Core.Array(::Any, ::Any)
Core.Array(::Uninitialized, ::Any)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where these not included in the Array entry on the line above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I got an error:

 !! No docs found for 'Core.Array(::Any, ::Any)'. [src/stdlib/arrays.md]

I thought there was a way to include all methods, but this one doesn't work at least.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I meant that you should remove Core.Array(::Any) and Core.Array(::Any, ::Any) and keep Core.Array. I think that Core.Array should catch everything associated with Array, but perhaps there was some reason for including them all earlier, perhaps to place the type docstring for Array at the top?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that only includes the type, not methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good to know!

base/array.jl Outdated Show resolved Hide resolved
@nalimilan
Copy link
Member Author

I've found a way to avoid the "method redefined" warnings by defining the code in sysimg.jl together with existing Array constructors. I'll merge once CI passes unless somebody objects.

Copy link
Member

@fredrikekre fredrikekre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, lets give @Sacha0 the opportunity to review since he is the one engineering these type of array constructors :)

@nalimilan
Copy link
Member Author

AppVeyor failure on 64-bit is the infamous Bunch-Kaufman bug.

test/arrayops.jl Outdated Show resolved Hide resolved
base/sysimg.jl Outdated Show resolved Hide resolved
These are shorthands for fill!(Array{T,N}(uninitialized, dims...), nothing/missing).
In the future they could be optimized for isbits Union types in which
nothing/missing is the first type of the Union, since such arrays are
already filled with nothing/missing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] missing data Base.missing and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants