Skip to content

Commit 13b2a67

Browse files
fix: fix copyto! for StaticArrays
1 parent 4e27909 commit 13b2a67

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Diff for: src/vector_of_array.jl

+16-6
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,26 @@ end
585585
function Base.checkbounds(VA::AbstractVectorOfArray, idx...)
586586
checkbounds(Bool, VA, idx...) || throw(BoundsError(VA, idx))
587587
end
588-
function Base.copyto!(dest::AbstractVectorOfArray{T,N}, src::AbstractVectorOfArray{T,N}) where {T,N}
589-
copyto!.(dest.u, src.u)
588+
function Base.copyto!(dest::AbstractVectorOfArray{T,N}, src::AbstractVectorOfArray{T2,N}) where {T, T2, N}
589+
for (i, j) in zip(eachindex(dest.u), eachindex(src.u))
590+
if ArrayInterface.ismutable(dest.u[i]) || dest.u[i] isa AbstractVectorOfArray
591+
copyto!(dest.u[i], src.u[j])
592+
else
593+
dest.u[i] = StaticArraysCore.similar_type(dest.u[i])(src.u[j])
594+
end
595+
end
590596
end
591-
function Base.copyto!(dest::AbstractVectorOfArray{T, N}, src::AbstractArray{T, N}) where {T, N}
592-
for (i, slice) in enumerate(eachslice(src, dims = ndims(src)))
593-
copyto!(dest.u[i], slice)
597+
function Base.copyto!(dest::AbstractVectorOfArray{T, N}, src::AbstractArray{T2, N}) where {T, T2, N}
598+
for (i, slice) in zip(eachindex(dest.u), eachslice(src, dims = ndims(src)))
599+
if ArrayInterface.ismutable(dest.u[i]) || dest.u[i] isa AbstractVectorOfArray
600+
copyto!(dest.u[i], slice)
601+
else
602+
dest.u[i] = StaticArraysCore.similar_type(dest.u[i])(slice)
603+
end
594604
end
595605
dest
596606
end
597-
function Base.copyto!(dest::AbstractVectorOfArray{T, N, <:AbstractVector{T}}, src::AbstractVector{T}) where {T, N}
607+
function Base.copyto!(dest::AbstractVectorOfArray{T, N, <:AbstractVector{T}}, src::AbstractVector{T2}) where {T, T2, N}
598608
copyto!(dest.u, src)
599609
dest
600610
end

0 commit comments

Comments
 (0)