Skip to content

Commit 5ae0c43

Browse files
Merge pull request #85 from mforets/mforets/constructor
Constructors with all elements of the same type
2 parents 1b6d95b + 41bb3fa commit 5ae0c43

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/vector_of_array.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ function Base.Array(VA::AbstractVectorOfArray)
1515
end
1616

1717
VectorOfArray(vec::AbstractVector{T}, dims::NTuple{N}) where {T, N} = VectorOfArray{eltype(T), N, typeof(vec)}(vec)
18-
# Assume that the first element is representative all all other elements
18+
# Assume that the first element is representative of all other elements
1919
VectorOfArray(vec::AbstractVector) = VectorOfArray(vec, (size(vec[1])..., length(vec)))
20+
VectorOfArray(vec::AbstractVector{VT}) where {T, N, VT<:AbstractArray{T, N}} = VectorOfArray{T, N+1, typeof(vec)}(vec)
2021

2122
DiffEqArray(vec::AbstractVector{T}, ts, dims::NTuple{N}) where {T, N} = DiffEqArray{eltype(T), N, typeof(vec), typeof(ts)}(vec, ts)
22-
# Assume that the first element is representative all all other elements
23+
# Assume that the first element is representative of all other elements
2324
DiffEqArray(vec::AbstractVector,ts::AbstractVector) = DiffEqArray(vec, ts, (size(vec[1])..., length(vec)))
25+
DiffEqArray(vec::AbstractVector{VT},ts::AbstractVector) where {T, N, VT<:AbstractArray{T, N}} = DiffEqArray{T, N+1, typeof(vec), typeof(ts)}(vec, ts)
2426

2527
# Interface for the linear indexing. This is just a view of the underlying nested structure
2628
@inline Base.firstindex(VA::AbstractVectorOfArray) = firstindex(VA.u)

test/interface_tests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ testval1 = 4
6868
testval2 = 17
6969
@test any(x->(x==testval1), testva)
7070
@test !any(x->(x==testval2), testda)
71+
72+
# check creation from empty arrays
73+
emptyva = VectorOfArray(Array{Vector{Float64}}([]))
74+
@test isempty(emptyva)
75+
emptyda = DiffEqArray(Array{Vector{Float64}}([]), Vector{Float64}())
76+
@test isempty(emptyda)

0 commit comments

Comments
 (0)