diff --git a/base/array.jl b/base/array.jl index 91e9f800f8cb4..67b406b157112 100644 --- a/base/array.jl +++ b/base/array.jl @@ -64,6 +64,12 @@ const DenseVector{T} = DenseArray{T,1} const DenseMatrix{T} = DenseArray{T,2} const DenseVecOrMat{T} = Union{DenseVector{T}, DenseMatrix{T}} +## More constructors +Array{T,N}(inds::NTuple{N,<:OneTo}) where {T,N} = Array{T,N}(length.(inds)) +Array{T}(inds::NTuple{N,<:OneTo}) where {T,N} = Array{T,N}(inds) +Array{T,N}(ind::OneTo, inds::Vararg{<:OneTo}) where {T,N} = Array{T,N}((ind, inds...)) +Array{T}(ind::OneTo, inds::Vararg{<:OneTo}) where T = Array{T}((ind, inds...)) + ## Basic functions ## """ diff --git a/base/boot.jl b/base/boot.jl index 178f77d0d1857..93f62098cf599 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -355,6 +355,8 @@ const NTuple{N,T} = Tuple{Vararg{T,N}} # primitive array constructors Array{T,N}(d::NTuple{N,Int}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) +Array{T,0}(::Tuple{}) where {T} = + ccall(:jl_new_array, Array{T,0}, (Any, Any), Array{T,0}, ()) Array{T,1}(d::NTuple{1,Int}) where {T} = Array{T,1}(getfield(d,1)) Array{T,2}(d::NTuple{2,Int}) where {T} = Array{T,2}(getfield(d,1), getfield(d,2)) Array{T,3}(d::NTuple{3,Int}) where {T} = Array{T,3}(getfield(d,1), getfield(d,2), getfield(d,3)) @@ -366,6 +368,7 @@ Array{T,3}(m::Int, n::Int, o::Int) where {T} = ccall(:jl_alloc_array_3d, Array{T,3}, (Any, Int, Int, Int), Array{T,3}, m, n, o) Array{T}(d::NTuple{N,Int}) where {T,N} = Array{T,N}(d) +Array{T}(::Tuple{}) where {T} = Array{T,0}(()) Array{T}(m::Int) where {T} = Array{T,1}(m) Array{T}(m::Int, n::Int) where {T} = Array{T,2}(m, n) Array{T}(m::Int, n::Int, o::Int) where {T} = Array{T,3}(m, n, o) diff --git a/test/arrayops.jl b/test/arrayops.jl index 79dd9f788a62b..a5873dbe6ebee 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -327,6 +327,12 @@ end error("unexpected depwarn value") end @test_throws MethodError Array{Int,3}() + + @test size(Array{Int}(Base.OneTo(3), Base.OneTo(2))) == (3,2) + @test size(Array{Int}((Base.OneTo(3), Base.OneTo(2)))) == (3,2) + @test size(Array{Int,2}(Base.OneTo(3), Base.OneTo(2))) == (3,2) + @test size(Array{Int,2}((Base.OneTo(3), Base.OneTo(2)))) == (3,2) + @test_throws MethodError Array{Int,3}((Base.OneTo(3), Base.OneTo(2))) end @testset "get" begin A = reshape(1:24, 3, 8)