@@ -422,6 +422,18 @@ Base.@propagate_inbounds function Base.setindex!(VA::AbstractVectorOfArray{T, N}
422
422
return VA. u[i][jj] = x
423
423
end
424
424
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
+
425
437
# Interface for the two-dimensional indexing, a more standard AbstractArray interface
426
438
@inline Base. size (VA:: AbstractVectorOfArray ) = (size (VA. u[1 ])... , length (VA. u))
427
439
@inline Base. size (VA:: AbstractVectorOfArray , i) = size (VA)[i]
@@ -534,21 +546,24 @@ function Base.checkbounds(::Type{Bool}, VA::AbstractVectorOfArray{T, N, <:Abstra
534
546
return checkbounds (Bool, VA. u, idxs... )
535
547
end
536
548
function 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
543
552
end
544
- return false
553
+ return true
545
554
end
546
555
function Base. checkbounds (VA:: AbstractVectorOfArray , idx... )
547
556
checkbounds (Bool, VA, idx... ) || throw (BoundsError (VA, idx))
548
557
end
549
558
function Base. copyto! (dest:: AbstractVectorOfArray{T,N} , src:: AbstractVectorOfArray{T,N} ) where {T,N}
550
559
copyto! .(dest. u, src. u)
551
560
end
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
552
567
553
568
# Operations
554
569
function Base. isapprox (A:: AbstractVectorOfArray ,
@@ -619,7 +634,7 @@ function Base.fill!(VA::AbstractVectorOfArray, x)
619
634
return VA
620
635
end
621
636
622
- Base. reshape (A:: VectorOfArray , dims... ) = Base. reshape (Array (A), dims... )
637
+ Base. reshape (A:: AbstractVectorOfArray , dims... ) = Base. reshape (Array (A), dims... )
623
638
624
639
# Need this for ODE_DEFAULT_UNSTABLE_CHECK from DiffEqBase to work properly
625
640
@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)
633
648
if ! allequal (size .(VA. u))
634
649
error (" Can only convert non-ragged VectorOfArray to Array" )
635
650
end
636
- return stack (VA)
651
+ return Array (VA)
637
652
end
638
653
639
654
# statistics
0 commit comments