Skip to content

Commit

Permalink
allow Array{T,N}() for arbitrary N
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jan 26, 2017
1 parent 1303dfb commit db8493b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
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
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 size(Array{Float64,5}()) == (0,0,0,0,0)
@test size(Array{Float64,8}()) == (0,0,0,0,0,0,0,0)
end

# Cartesian
Expand Down

0 comments on commit db8493b

Please sign in to comment.