@@ -129,8 +129,8 @@ Base.vec(VA::AbstractVectorOfArray) = vec(convert(Array,VA)) # Allocates
129
129
@inline Statistics. cor (VA:: AbstractVectorOfArray ;kwargs... ) = cor (Array (VA);kwargs... )
130
130
131
131
# make it show just like its data
132
- Base. show (io:: IO , x:: AbstractVectorOfArray ) = show (io, x. u)
133
- Base. show (io:: IO , m:: MIME"text/plain" , x:: AbstractVectorOfArray ) = show (io, m, x. u)
132
+ Base. show (io:: IO , x:: AbstractVectorOfArray ) = Base . print_array (io, x. u)
133
+ Base. show (io:: IO , m:: MIME"text/plain" , x:: AbstractVectorOfArray ) = ( println (io, summary (x), ' : ' ); show (io, m, x. u) )
134
134
Base. summary (A:: AbstractVectorOfArray ) = string (" VectorOfArray{" ,eltype (A)," ," ,ndims (A)," }" )
135
135
136
136
Base. show (io:: IO , x:: AbstractDiffEqArray ) = (print (io," t: " );show (io, x. t);println (io);print (io," u: " );show (io, x. u))
@@ -149,30 +149,25 @@ end
149
149
150
150
# # broadcasting
151
151
152
- struct VectorOfArrayStyle <: Broadcast.AbstractArrayStyle{Any} end
153
- VectorOfArrayStyle (:: Any ) = VectorOfArrayStyle ()
154
- VectorOfArrayStyle (:: Any , :: Any ) = VectorOfArrayStyle ()
152
+ struct VectorOfArrayStyle{N} <: Broadcast.AbstractArrayStyle{N} end # N is only used when voa sees other abstract arrays
153
+ VectorOfArrayStyle (:: Val{N} ) where N = VectorOfArrayStyle {N} ()
155
154
156
- # promotion rules
157
- # @inline function Broadcast.BroadcastStyle(::VectorOfArrayStyle{AStyle} , ::VectorOfArrayStyle{BStyle }) where {AStyle, BStyle}
158
- # VectorOfArrayStyle( Broadcast.BroadcastStyle(AStyle(), BStyle( )))
159
- # end
160
- Broadcast. BroadcastStyle (:: VectorOfArrayStyle , :: Broadcast.BroadcastStyle ) = VectorOfArrayStyle ()
161
- Broadcast. BroadcastStyle (:: VectorOfArrayStyle , :: Broadcast.DefaultArrayStyle{N} ) where N = Broadcast . DefaultArrayStyle {N} ()
155
+ # The order is important here. We want to override Base.Broadcast.DefaultArrayStyle to return another Base.Broadcast.DefaultArrayStyle.
156
+ Broadcast. BroadcastStyle (a :: VectorOfArrayStyle , :: Base.Broadcast.DefaultArrayStyle{0 } ) = a
157
+ Broadcast . BroadcastStyle ( :: VectorOfArrayStyle{N} , a :: Base.Broadcast.DefaultArrayStyle{M} ) where {M,N} = Base . Broadcast. DefaultArrayStyle ( Val ( max (M, N )))
158
+ Broadcast . BroadcastStyle ( :: VectorOfArrayStyle{N} , a :: Base.Broadcast.AbstractArrayStyle{M} ) where {M,N} = typeof (a)( Val ( max (M, N)))
159
+ Broadcast. BroadcastStyle (:: VectorOfArrayStyle{M} , :: VectorOfArrayStyle{N} ) where {M,N} = VectorOfArrayStyle (Val ( max (M, N)) )
160
+ Broadcast. BroadcastStyle (:: Type{<:AbstractVectorOfArray{T,N}} ) where {T,N} = VectorOfArrayStyle {N} ()
162
161
163
- function Broadcast. BroadcastStyle (:: Type{<:AbstractVectorOfArray{T,S}} ) where {T, S}
164
- VectorOfArrayStyle ()
165
- end
166
-
167
- @inline function Base. copy (bc:: Broadcast.Broadcasted{VectorOfArrayStyle} )
162
+ @inline function Base. copy (bc:: Broadcast.Broadcasted{<:VectorOfArrayStyle} )
168
163
N = narrays (bc)
169
164
x = unpack_voa (bc, 1 )
170
165
VectorOfArray (map (1 : N) do i
171
166
copy (unpack_voa (bc, i))
172
167
end )
173
168
end
174
169
175
- @inline function Base. copyto! (dest:: AbstractVectorOfArray , bc:: Broadcast.Broadcasted{VectorOfArrayStyle} )
170
+ @inline function Base. copyto! (dest:: AbstractVectorOfArray , bc:: Broadcast.Broadcasted{<: VectorOfArrayStyle} )
176
171
N = narrays (bc)
177
172
@inbounds for i in 1 : N
178
173
copyto! (dest[i], unpack_voa (bc, i))
@@ -201,11 +196,11 @@ common_length(a, b) =
201
196
_narrays (args:: AbstractVectorOfArray ) = length (args)
202
197
@inline _narrays (args:: Tuple ) = common_length (narrays (args[1 ]), _narrays (Base. tail (args)))
203
198
_narrays (args:: Tuple{Any} ) = _narrays (args[1 ])
204
- _narrays (args :: Tuple{} ) = 0
199
+ _narrays (:: Any ) = 0
205
200
206
201
# drop axes because it is easier to recompute
207
202
@inline unpack_voa (bc:: Broadcast.Broadcasted{Style} , i) where Style = Broadcast. Broadcasted {Style} (bc. f, unpack_args_voa (i, bc. args))
208
- @inline unpack_voa (bc:: Broadcast.Broadcasted{VectorOfArrayStyle} , i) = Broadcast. Broadcasted (bc. f, unpack_args_voa (i, bc. args))
203
+ @inline unpack_voa (bc:: Broadcast.Broadcasted{<: VectorOfArrayStyle} , i) = Broadcast. Broadcasted (bc. f, unpack_args_voa (i, bc. args))
209
204
unpack_voa (x,:: Any ) = x
210
205
unpack_voa (x:: AbstractVectorOfArray , i) = x. u[i]
211
206
unpack_voa (x:: AbstractArray{T,N} , i) where {T,N} = @view x[ntuple (x-> Colon (),N- 1 )... ,i]
0 commit comments