@@ -3,9 +3,13 @@ mutable struct VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N, A}
33 u:: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
44end
55# VectorOfArray with an added series for time
6- mutable struct DiffEqArray{T, N, A, B} <: AbstractDiffEqArray{T, N, A}
6+ mutable struct DiffEqArray{T, N, A, B, C, D, E, F } <: AbstractDiffEqArray{T, N, A}
77 u:: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
88 t:: B
9+ syms:: C
10+ indepsym:: D
11+ observed:: E
12+ p:: F
913end
1014
1115Base. Array (VA:: AbstractVectorOfArray{T,N,A} ) where {T,N,A <: AbstractVector{<:AbstractVector} } = reduce (hcat,VA. u)
@@ -20,10 +24,11 @@ VectorOfArray(vec::AbstractVector{T}, ::NTuple{N}) where {T, N} = VectorOfArray{
2024VectorOfArray (vec:: AbstractVector ) = VectorOfArray (vec, (size (vec[1 ])... , length (vec)))
2125VectorOfArray (vec:: AbstractVector{VT} ) where {T, N, VT<: AbstractArray{T, N} } = VectorOfArray {T, N+1, typeof(vec)} (vec)
2226
23- DiffEqArray (vec:: AbstractVector{T} , ts, :: NTuple{N} ) where {T, N} = DiffEqArray {eltype(T), N, typeof(vec), typeof(ts)} (vec, ts)
27+ DiffEqArray (vec:: AbstractVector{T} , ts, :: NTuple{N} ) where {T, N} = DiffEqArray {eltype(T), N, typeof(vec), typeof(ts), Nothing, Nothing, Nothing, Nothing } (vec, ts, nothing , nothing , nothing , nothing )
2428# Assume that the first element is representative of all other elements
2529DiffEqArray (vec:: AbstractVector ,ts:: AbstractVector ) = DiffEqArray (vec, ts, (size (vec[1 ])... , length (vec)))
26- DiffEqArray (vec:: AbstractVector{VT} ,ts:: AbstractVector ) where {T, N, VT<: AbstractArray{T, N} } = DiffEqArray {T, N+1, typeof(vec), typeof(ts)} (vec, ts)
30+ DiffEqArray (vec:: AbstractVector{VT} ,ts:: AbstractVector ) where {T, N, VT<: AbstractArray{T, N} } = DiffEqArray {T, N+1, typeof(vec), typeof(ts), Nothing, Nothing, Nothing, Nothing} (vec, ts, nothing , nothing , nothing , nothing )
31+ DiffEqArray (vec:: AbstractVector{VT} ,ts:: AbstractVector , syms:: Vector{Symbol} , indepsym:: Symbol , observed:: Function , p) where {T, N, VT<: AbstractArray{T, N} } = DiffEqArray {T, N+1, typeof(vec), typeof(ts), typeof(syms), typeof(indepsym), typeof(observed), typeof(p)} (vec, ts, syms, indepsym, observed, p)
2732
2833# Interface for the linear indexing. This is just a view of the underlying nested structure
2934@inline Base. firstindex (VA:: AbstractVectorOfArray ) = firstindex (VA. u)
@@ -38,6 +43,72 @@ Base.@propagate_inbounds Base.getindex(VA::AbstractVectorOfArray{T, N}, I::Int)
3843Base. @propagate_inbounds Base. getindex (VA:: AbstractVectorOfArray{T, N} , I:: Colon ) where {T, N} = VA. u[I]
3944Base. @propagate_inbounds Base. getindex (VA:: AbstractVectorOfArray{T, N} , I:: AbstractArray{Int} ) where {T, N} = VectorOfArray (VA. u[I])
4045Base. @propagate_inbounds Base. getindex (VA:: AbstractDiffEqArray{T, N} , I:: AbstractArray{Int} ) where {T, N} = DiffEqArray (VA. u[I],VA. t[I])
46+ #
47+ Base. @pure __parameterless_type (T) = Base. typename (T). wrapper
48+ parameterless_type (x) = parameterless_type (typeof (x))
49+ parameterless_type (x:: Type ) = __parameterless_type (x)
50+
51+ # ## Abstract Interface
52+ struct AllObserved
53+ end
54+ issymbollike (x) = x isa Symbol ||
55+ x isa AllObserved ||
56+ Symbol (parameterless_type (typeof (x))) == :Operation ||
57+ Symbol (parameterless_type (typeof (x))) == :Variable ||
58+ Symbol (parameterless_type (typeof (x))) == :Sym ||
59+ Symbol (parameterless_type (typeof (x))) == :Num ||
60+ Symbol (parameterless_type (typeof (x))) == :Term
61+
62+ Base. @propagate_inbounds function Base. getindex (A:: AbstractDiffEqArray{T, N} ,sym) where {T, N}
63+ if issymbollike (sym)
64+ i = findfirst (isequal (Symbol (sym)),A. syms)
65+ else
66+ i = sym
67+ end
68+
69+ if i === nothing
70+ # TODO : Check if system actually has a indepsym
71+ if issymbollike (i) && Symbol (i) == A. indepsym
72+ A. t
73+ else
74+ observed (A,sym,:)
75+ end
76+ else
77+ A[i,:]
78+ end
79+ end
80+ Base. @propagate_inbounds function Base. getindex (A:: AbstractDiffEqArray{T, N} ,sym,args... ) where {T, N}
81+ if issymbollike (sym)
82+ i = findfirst (isequal (Symbol (sym)),A. syms)
83+ else
84+ i = sym
85+ end
86+
87+ if i === nothing
88+ # TODO : Check if system actually has a indepsym
89+ if issymbollike (i) && Symbol (i) == A. indepsym
90+ A. t[args... ]
91+ else
92+ observed (A,sym,args... )
93+ end
94+ else
95+ A[i,args... ]
96+ end
97+ end
98+ Base. @propagate_inbounds Base. getindex (A:: AbstractDiffEqArray{T, N} where {T, N}, i:: Int64 , :: Colon ) = Base. getindex .(A. u, i)
99+
100+ function observed (A:: AbstractDiffEqArray{T, N} ,sym,i:: Int ) where {T, N}
101+ A. observed (sym,A. u[i],A. p,A. t[i])
102+ end
103+
104+ function observed (A:: AbstractDiffEqArray{T, N} ,sym,i:: AbstractArray{Int} ) where {T, N}
105+ A. observed .((sym,),A. u[i],(A. p,),A. t[i])
106+ end
107+
108+ function observed (A:: AbstractDiffEqArray{T, N} ,sym,:: Colon ) where {T, N}
109+ A. observed .((sym,),A. u,(A. p,),A. t)
110+ end
111+ #
41112Base. @propagate_inbounds Base. getindex (VA:: AbstractVectorOfArray{T, N} , i:: Int ,:: Colon ) where {T, N} = [VA. u[j][i] for j in 1 : length (VA)]
42113Base. @propagate_inbounds function Base. getindex (VA:: AbstractVectorOfArray{T,N} , ii:: CartesianIndex ) where {T, N}
43114 ti = Tuple (ii)
0 commit comments