@@ -422,6 +422,18 @@ Base.@propagate_inbounds function Base.setindex!(VA::AbstractVectorOfArray{T, N}
422422 return VA. u[i][jj] = x
423423end
424424
425+ Base. @propagate_inbounds function Base. setindex! (VA:: AbstractVectorOfArray{T, N} , x, idxs:: Union{Int,Colon,CartesianIndex,AbstractArray{Int},AbstractArray{Bool}} ...) where {T, N}
426+ v = view (VA, idxs... )
427+ # error message copied from Base by running `ones(3, 3, 3)[:, 2, :] = 2`
428+ if length (v) != length (x)
429+ throw (ArgumentError (" indexed assignment with a single value to possibly many locations is not supported; perhaps use broadcasting `.=` instead?" ))
430+ end
431+ for (i, j) in zip (eachindex (v), eachindex (x))
432+ v[i] = x[j]
433+ end
434+ return x
435+ end
436+
425437# Interface for the two-dimensional indexing, a more standard AbstractArray interface
426438@inline Base. size (VA:: AbstractVectorOfArray ) = (size (VA. u[1 ])... , length (VA. u))
427439@inline Base. size (VA:: AbstractVectorOfArray , i) = size (VA)[i]
@@ -534,21 +546,24 @@ function Base.checkbounds(::Type{Bool}, VA::AbstractVectorOfArray{T, N, <:Abstra
534546 return checkbounds (Bool, VA. u, idxs... )
535547end
536548function Base. checkbounds (:: Type{Bool} , VA:: AbstractVectorOfArray , idx... )
537- if checkbounds (Bool, VA. u, last (idx))
538- if last (idx) isa Integer
539- return all (checkbounds .(Bool, (VA. u[last (idx)],), Base. front (idx)... ))
540- else
541- return all (checkbounds .(Bool, VA. u[last (idx)], tuple .(Base. front (idx))... ))
542- end
549+ checkbounds (Bool, VA. u, last (idx)) || return false
550+ for i in last (idx)
551+ checkbounds (Bool, VA. u[i], Base. front (idx)... ) || return false
543552 end
544- return false
553+ return true
545554end
546555function Base. checkbounds (VA:: AbstractVectorOfArray , idx... )
547556 checkbounds (Bool, VA, idx... ) || throw (BoundsError (VA, idx))
548557end
549558function Base. copyto! (dest:: AbstractVectorOfArray{T,N} , src:: AbstractVectorOfArray{T,N} ) where {T,N}
550559 copyto! .(dest. u, src. u)
551560end
561+ # Required for broadcasted setindex! when slicing across subarrays
562+ # E.g. if `va = VectorOfArray([rand(3, 3) for i in 1:5])`
563+ # Need this method for `va[2, :, :] .= 3.0`
564+ Base. @propagate_inbounds function Base. maybeview (A:: AbstractVectorOfArray , I... )
565+ return view (A, I... )
566+ end
552567
553568# Operations
554569function Base. isapprox (A:: AbstractVectorOfArray ,
@@ -619,7 +634,7 @@ function Base.fill!(VA::AbstractVectorOfArray, x)
619634 return VA
620635end
621636
622- Base. reshape (A:: VectorOfArray , dims... ) = Base. reshape (Array (A), dims... )
637+ Base. reshape (A:: AbstractVectorOfArray , dims... ) = Base. reshape (Array (A), dims... )
623638
624639# Need this for ODE_DEFAULT_UNSTABLE_CHECK from DiffEqBase to work properly
625640@inline Base. any (f, VA:: AbstractVectorOfArray ) = any (any (f, u) for u in VA. u)
@@ -633,7 +648,7 @@ function Base.convert(::Type{Array}, VA::AbstractVectorOfArray)
633648 if ! allequal (size .(VA. u))
634649 error (" Can only convert non-ragged VectorOfArray to Array" )
635650 end
636- return stack (VA)
651+ return Array (VA)
637652end
638653
639654# statistics
0 commit comments