@@ -29,6 +29,7 @@ returns a vector of the series for each component, that is, `A[i,:]` for each `i
29
29
A plot recipe is provided, which plots the `A[i,:]` series.
30
30
31
31
There is also support for `VectorOfArray` constructed from multi-dimensional arrays
32
+
32
33
```julia
33
34
VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}}
34
35
```
@@ -60,8 +61,9 @@ A[1, :] # all time periods for f(t)
60
61
A.t
61
62
```
62
63
"""
63
- mutable struct DiffEqArray{T, N, A, B, F, S, D <: Union{Nothing, ParameterTimeseriesCollection} } < :
64
- AbstractDiffEqArray{T, N, A}
64
+ mutable struct DiffEqArray{
65
+ T, N, A, B, F, S, D <: Union{Nothing, ParameterTimeseriesCollection} } < :
66
+ AbstractDiffEqArray{T, N, A}
65
67
u:: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
66
68
t:: B
67
69
p:: F
@@ -177,7 +179,9 @@ function DiffEqArray(vec::AbstractVector{T},
177
179
:: NTuple{N, Int} ,
178
180
p = nothing ,
179
181
sys = nothing ; discretes = nothing ) where {T, N}
180
- DiffEqArray {eltype(T), N, typeof(vec), typeof(ts), typeof(p), typeof(sys), typeof(discretes)} (vec,
182
+ DiffEqArray{
183
+ eltype (T), N, typeof (vec), typeof (ts), typeof (p), typeof (sys), typeof (discretes)}(
184
+ vec,
181
185
ts,
182
186
p,
183
187
sys,
197
201
function DiffEqArray (vec:: AbstractVector{VT} ,
198
202
ts:: AbstractVector ,
199
203
:: NTuple{N, Int} , p; discretes = nothing ) where {T, N, VT <: AbstractArray{T, N} }
200
- DiffEqArray {eltype(T), N, typeof(vec), typeof(ts), typeof(p), Nothing, typeof(discretes)} (vec,
204
+ DiffEqArray{
205
+ eltype (T), N, typeof (vec), typeof (ts), typeof (p), Nothing, typeof (discretes)}(vec,
201
206
ts,
202
207
p,
203
208
nothing ,
@@ -253,7 +258,7 @@ function DiffEqArray(vec::AbstractVector{VT},
253
258
typeof (ts),
254
259
typeof (p),
255
260
typeof (sys),
256
- typeof (discretes),
261
+ typeof (discretes)
257
262
}(vec,
258
263
ts,
259
264
p,
@@ -375,19 +380,23 @@ Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::NotSymboli
375
380
end
376
381
377
382
struct ParameterIndexingError <: Exception
378
- sym
383
+ sym:: Any
379
384
end
380
385
381
386
function Base. showerror (io:: IO , pie:: ParameterIndexingError )
382
- print (io, " Indexing with parameters is deprecated. Use `getp(A, $(pie. sym) )` for parameter indexing." )
387
+ print (io,
388
+ " Indexing with parameters is deprecated. Use `getp(A, $(pie. sym) )` for parameter indexing." )
383
389
end
384
390
385
391
# Symbolic Indexing Methods
386
392
for (symtype, elsymtype, valtype, errcheck) in [
387
- (ScalarSymbolic, SymbolicIndexingInterface. SymbolicTypeTrait, Any, :(is_parameter (A, sym) && ! is_timeseries_parameter (A, sym))),
388
- (ArraySymbolic, SymbolicIndexingInterface. SymbolicTypeTrait, Any, :(is_parameter (A, sym) && ! is_timeseries_parameter (A, sym))),
389
- (NotSymbolic, SymbolicIndexingInterface. SymbolicTypeTrait, Union{<: Tuple , <: AbstractArray },
390
- :(all (x -> is_parameter (A, x) && ! is_timeseries_parameter (A, x), sym))),
393
+ (ScalarSymbolic, SymbolicIndexingInterface. SymbolicTypeTrait, Any,
394
+ :(is_parameter (A, sym) && ! is_timeseries_parameter (A, sym))),
395
+ (ArraySymbolic, SymbolicIndexingInterface. SymbolicTypeTrait, Any,
396
+ :(is_parameter (A, sym) && ! is_timeseries_parameter (A, sym))),
397
+ (NotSymbolic, SymbolicIndexingInterface. SymbolicTypeTrait,
398
+ Union{<: Tuple , <: AbstractArray },
399
+ :(all (x -> is_parameter (A, x) && ! is_timeseries_parameter (A, x), sym)))
391
400
]
392
401
@eval Base. @propagate_inbounds function _getindex (A:: AbstractDiffEqArray , :: $symtype ,
393
402
:: $elsymtype , sym:: $valtype , arg... )
@@ -413,8 +422,9 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg,
413
422
elsymtype = symbolic_type (eltype (_arg))
414
423
415
424
if symtype == NotSymbolic () && elsymtype == NotSymbolic ()
416
- if _arg isa Union{Tuple, AbstractArray} && any (x -> symbolic_type (x) != NotSymbolic (), _arg)
417
- _getindex (A, symtype, elsymtype, _arg, args... )
425
+ if _arg isa Union{Tuple, AbstractArray} &&
426
+ any (x -> symbolic_type (x) != NotSymbolic (), _arg)
427
+ _getindex (A, symtype, elsymtype, _arg, args... )
418
428
else
419
429
_getindex (A, symtype, _arg, args... )
420
430
end
536
546
537
547
function Base. zero (VA:: AbstractVectorOfArray )
538
548
val = copy (VA)
539
- for i in eachindex (VA. u)
540
- val. u[i] = zero (VA. u[i])
541
- end
549
+ val. u = zero .(VA. u)
542
550
return val
543
551
end
544
552
@@ -707,30 +715,32 @@ end
707
715
708
716
# Tools for creating similar objects
709
717
Base. eltype (:: Type{<:AbstractVectorOfArray{T}} ) where {T} = T
710
- # TODO : Is there a better way to do this?
718
+
711
719
@inline function Base. similar (VA:: AbstractVectorOfArray , args... )
712
720
if args[end ] isa Type
713
721
return Base. similar (eltype (VA)[], args... , size (VA))
714
722
else
715
723
return Base. similar (eltype (VA)[], args... )
716
724
end
717
725
end
718
- @inline function Base. similar (VA:: VectorOfArray , :: Type{T} = eltype (VA)) where {T}
719
- VectorOfArray ([similar (VA[:, i], T) for i in eachindex (VA. u)])
720
- end
721
726
722
- # for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type
723
727
function Base. similar (vec:: VectorOfArray {
724
728
T, N, AT}) where {T, N, AT <: AbstractArray{<:AbstractArray{T}} }
725
729
return VectorOfArray (similar .(Base. parent (vec)))
726
730
end
727
731
728
- # special-case when the multi-dimensional parent array is just an AbstractVector (call the old method)
729
- function Base. similar (vec:: VectorOfArray {
730
- T, N, AT}) where {T, N, AT <: AbstractVector{<:AbstractArray{T}} }
731
- return Base. similar (vec, eltype (vec))
732
+ @inline function Base. similar (VA:: VectorOfArray , :: Type{T} = eltype (VA)) where {T}
733
+ VectorOfArray (similar .(VA. u, T))
732
734
end
733
735
736
+ @inline function Base. similar (VA:: VectorOfArray , dims:: N ) where {N <: Number }
737
+ l = length (VA)
738
+ if dims <= l
739
+ VectorOfArray (similar .(VA. u[1 : dims]))
740
+ else
741
+ VectorOfArray ([similar .(VA. u); [similar (VA. u[end ]) for _ in (l + 1 ): dims]])
742
+ end
743
+ end
734
744
735
745
# fill!
736
746
# For DiffEqArray it ignores ts and fills only u
0 commit comments