2
2
type VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N}
3
3
u:: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
4
4
end
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
5
10
6
11
VectorOfArray {T, N} (vec:: AbstractVector{T} , dims:: NTuple{N} ) = VectorOfArray {eltype(T), N, typeof(vec)} (vec)
7
12
# Assume that the first element is representative all all other elements
8
13
VectorOfArray (vec:: AbstractVector ) = VectorOfArray (vec, (size (vec[1 ])... , length (vec)))
9
14
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
+
10
20
# Interface for the linear indexing. This is just a view of the underlying nested structure
11
21
@inline Base. endof (VA:: AbstractVectorOfArray ) = endof (VA. u)
12
22
@inline Base. length (VA:: AbstractVectorOfArray ) = length (VA. u)
@@ -16,6 +26,7 @@ VectorOfArray(vec::AbstractVector) = VectorOfArray(vec, (size(vec[1])..., length
16
26
@inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Int ) = VA. u[I]
17
27
@inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Colon ) = VA. u[I]
18
28
@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)]
19
30
20
31
# Interface for the two dimensional indexing, a more standard AbstractArray interface
21
32
@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
26
37
Base. start {T, N} (VA:: AbstractVectorOfArray{T, N} ) = 1
27
38
Base. next {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = (VA[state], state + 1 )
28
39
Base. done {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = state >= length (VA. u) + 1
40
+ tuples (VA:: DiffEqArray ) = tuple .(VA. t,VA. u)
29
41
30
42
# Growing the array simply adds to the container vector
31
43
Base. copy (VA:: AbstractVectorOfArray ) = typeof (VA)(copy (VA. u))
41
53
42
54
# conversion tools
43
55
vecarr_to_arr (VA:: AbstractVectorOfArray ) = cat (length (size (VA)), VA. u... )
56
+ vecarr_to_vectors (VA:: AbstractVectorOfArray ) = [VA[i,:] for i in eachindex (VA[1 ])]
44
57
45
58
# make it show just like its data
46
59
Base. show (io:: IO , x:: AbstractVectorOfArray ) = show (io, x. u)
47
60
Base. 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