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

allow Array{T,N}() for arbitrary N #20250

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function vect(X...)
return copy!(Array{T,1}(length(X)), X)
end

(::Type{Array{T,N}}){T,N}() = Array{T,N}(ntuple(i -> 0, Val{N})...)

size(a::Array, d) = arraysize(a, d)
size(a::Vector) = (arraysize(a,1),)
size(a::Matrix) = (arraysize(a,1), arraysize(a,2))
Expand Down
3 changes: 0 additions & 3 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ typealias NTuple{N,T} Tuple{Vararg{T,N}}
(::Type{Array{T}}){T}(m::Int, n::Int) = Array{T,2}(m, n)
(::Type{Array{T}}){T}(m::Int, n::Int, o::Int) = Array{T,3}(m, n, o)

(::Type{Array{T,1}}){T}() = Array{T,1}(0)
(::Type{Array{T,2}}){T}() = Array{T,2}(0, 0)

# primitive Symbol constructors
function Symbol(s::String)
return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int),
Expand Down
4 changes: 4 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,10 @@ let a = Array{Float64}(10)
@test size(aa) == size(bb)
bbb = Array{Float64, 9}(9,8,7,6,5,4,3,2,1)
@test size(aaa) == size(bbb)

#14201 Test Array{T, N}() constructor
@test @inferred size(Array{Float64,5}()) == (0,0,0,0,0)
@test @inferred size(Array{Float64,8}()) == (0,0,0,0,0,0,0,0)
end

# Cartesian
Expand Down