@@ -28,16 +28,15 @@ the `VectorOfArray` into a matrix/tensor. Also, `vecarr_to_vectors(VA::AbstractV
28
28
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
- There is also support for `VectorOfArray` with constructed from multi-dimensional arrays
32
-
31
+ There is also support for `VectorOfArray` constructed from multi-dimensional arrays
33
32
```julia
34
33
VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}}
35
34
```
36
35
37
36
where `IndexStyle(typeof(u)) isa IndexLinear`.
38
37
"""
39
38
mutable struct VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N, A}
40
- u:: A # A <: AbstractVector {<: AbstractArray{T, N - 1}}
39
+ u:: A # A <: AbstractArray {<: AbstractArray{T, N - 1}}
41
40
end
42
41
# VectorOfArray with an added series for time
43
42
719
718
# for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type
720
719
function Base. similar (vec:: VectorOfArray {
721
720
T, N, AT}) where {T, N, AT <: AbstractArray{<:AbstractArray{T}} }
722
- return VectorOfArray (similar (Base. parent (vec)))
721
+ return VectorOfArray (similar . (Base. parent (vec)))
723
722
end
724
723
725
724
# special-case when the multi-dimensional parent array is just an AbstractVector (call the old method)
@@ -728,6 +727,7 @@ function Base.similar(vec::VectorOfArray{
728
727
return Base. similar (vec, eltype (vec))
729
728
end
730
729
730
+
731
731
# fill!
732
732
# For DiffEqArray it ignores ts and fills only u
733
733
function Base. fill! (VA:: AbstractVectorOfArray , x)
@@ -840,12 +840,37 @@ end
840
840
# make vectorofarrays broadcastable so they aren't collected
841
841
Broadcast. broadcastable (x:: AbstractVectorOfArray ) = x
842
842
843
+ # recurse through broadcast arguments and return a parent array for
844
+ # the first VoA or DiffEqArray in the bc arguments
845
+ function find_VoA_parent (args)
846
+ arg = Base. first (args)
847
+ if arg isa AbstractDiffEqArray
848
+ # if first(args) is a DiffEqArray, use the underlying
849
+ # field `u` of DiffEqArray as a parent array.
850
+ return arg. u
851
+ elseif arg isa AbstractVectorOfArray
852
+ return parent (arg)
853
+ else
854
+ return find_VoA_parent (Base. tail (args))
855
+ end
856
+ end
857
+
843
858
@inline function Base. copy (bc:: Broadcast.Broadcasted{<:VectorOfArrayStyle} )
844
859
bc = Broadcast. flatten (bc)
845
- N = narrays (bc)
846
- VectorOfArray (map (1 : N) do i
847
- copy (unpack_voa (bc, i))
848
- end )
860
+
861
+ parent = find_VoA_parent (bc. args)
862
+
863
+ if parent isa AbstractVector
864
+ # this is the default behavior in v3.15.0
865
+ N = narrays (bc)
866
+ return VectorOfArray (map (1 : N) do i
867
+ copy (unpack_voa (bc, i))
868
+ end )
869
+ else # if parent isa AbstractArray
870
+ return VectorOfArray (map (enumerate (Iterators. product (axes (parent)... ))) do (i, _)
871
+ copy (unpack_voa (bc, i))
872
+ end )
873
+ end
849
874
end
850
875
851
876
for (type, N_expr) in [
0 commit comments