Skip to content

Commit

Permalink
Add Vector{T}() and Vector() constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed May 6, 2015
1 parent 90f7cd0 commit 7bd605a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ typealias StridedVector{T,A<:DenseArray,I<:Tuple{Vararg{RangeIndex}}} Union(Den
typealias StridedMatrix{T,A<:DenseArray,I<:Tuple{Vararg{RangeIndex}}} Union(DenseArray{T,2}, SubArray{T,2,A,I})
typealias StridedVecOrMat{T} Union(StridedVector{T}, StridedMatrix{T})

call{T}(::Type{Vector{T}}, m::Integer) = Array{T}(m)
call{T}(::Type{Vector{T}}, m::Integer=0) = Array{T}(m)
call(::Type{Vector}, m::Integer=0) = Array{Any}(m)
call{T}(::Type{Matrix{T}}, m::Integer, n::Integer) = Array{T}(m, n)

## Basic functions ##
Expand Down
8 changes: 8 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ ind = findin(a, b)
rt = Base.return_types(setindex!, Tuple{Array{Int32, 3}, UInt8, Vector{Int}, Float64, UnitRange{Int}})
@test length(rt) == 1 && rt[1] == Array{Int32, 3}

# construction
@test typeof(Vector{Int}()) == Vector{Int}
@test typeof(Vector()) == Vector{Any}
@test Vector() == []
@test length(Vector{Int}(3)) == 3
@test length(Vector(3)) == 3
@test size(Matrix{Int}(2,3)) == (2,3)

# get
let
A = reshape(1:24, 3, 8)
Expand Down

0 comments on commit 7bd605a

Please sign in to comment.