22type VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N}
33 u:: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
44end
5+ # VectorOfArray with an added series for time
6+ type DiffEqArray{T, N, A, B} <: AbstractVectorOfArray{T, N}
7+ u:: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
8+ t:: B
9+ end
510
611VectorOfArray {T, N} (vec:: AbstractVector{T} , dims:: NTuple{N} ) = VectorOfArray {eltype(T), N, typeof(vec)} (vec)
712# Assume that the first element is representative all all other elements
813VectorOfArray (vec:: AbstractVector ) = VectorOfArray (vec, (size (vec[1 ])... , length (vec)))
914
15+ DiffEqArray {T, N} (vec:: AbstractVector{T} , ts, dims:: NTuple{N} ) = DiffEqArray {eltype(T), N, typeof(vec), typeof(ts)} (vec, ts)
16+ # Assume that the first element is representative all all other elements
17+ DiffEqArray (vec:: AbstractVector ,ts:: AbstractVector ) = DiffEqArray (vec, ts, (size (vec[1 ])... , length (vec)))
18+
19+
1020# Interface for the linear indexing. This is just a view of the underlying nested structure
1121@inline Base. endof (VA:: AbstractVectorOfArray ) = endof (VA. u)
1222@inline Base. length (VA:: AbstractVectorOfArray ) = length (VA. u)
@@ -16,6 +26,7 @@ VectorOfArray(vec::AbstractVector) = VectorOfArray(vec, (size(vec[1])..., length
1626@inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Int ) = VA. u[I]
1727@inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Colon ) = VA. u[I]
1828@inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: AbstractArray{Int} ) = VA. u[I]
29+ @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , i:: Int ,:: Colon ) = [VA. u[j][i] for j in 1 : length (VA)]
1930
2031# Interface for the two dimensional indexing, a more standard AbstractArray interface
2132@inline Base. size (VA:: AbstractVectorOfArray ) = (size (VA. u[1 ])... , length (VA. u))
@@ -26,6 +37,7 @@ VectorOfArray(vec::AbstractVector) = VectorOfArray(vec, (size(vec[1])..., length
2637Base. start {T, N} (VA:: AbstractVectorOfArray{T, N} ) = 1
2738Base. next {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = (VA[state], state + 1 )
2839Base. done {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = state >= length (VA. u) + 1
40+ tuples (VA:: DiffEqArray ) = tuple .(VA. t,VA. u)
2941
3042# Growing the array simply adds to the container vector
3143Base. copy (VA:: AbstractVectorOfArray ) = typeof (VA)(copy (VA. u))
4153
4254# conversion tools
4355vecarr_to_arr (VA:: AbstractVectorOfArray ) = cat (length (size (VA)), VA. u... )
56+ vecarr_to_vectors (VA:: AbstractVectorOfArray ) = [VA[i,:] for i in eachindex (VA[1 ])]
4457
4558# make it show just like its data
4659Base. show (io:: IO , x:: AbstractVectorOfArray ) = show (io, x. u)
4760Base. show (io:: IO , m:: MIME"text/plain" , x:: AbstractVectorOfArray ) = show (io, m, x. u)
61+
62+ # restore the type rendering in Juno
63+ Juno. @render Juno. Inline x:: AbstractVectorOfArray begin
64+ fields = fieldnames (typeof (x))
65+ Juno. LazyTree (typeof (x), () -> [Juno. SubTree (Juno. Text (" $f → " ), Juno. getfield′ (x, f)) for f in fields])
66+ end
67+
68+ # plot recipes
69+ @recipe function f (VA:: AbstractVectorOfArray )
70+ vecarr_to_vectors (VA)
71+ end
72+ @recipe function f (VA:: DiffEqArray )
73+ A = vecarr_to_vectors (VA)
74+ VA. t,A
75+ end
0 commit comments