Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,12 @@ end
function Base.fill!(VA::AbstractVectorOfArray, x)
for i in 1:length(VA.u)
if VA[:, i] isa AbstractArray
fill!(VA[:, i], x)
if ArrayInterface.ismutable(VA.u[i]) || VA.u[i] isa AbstractVectorOfArray
fill!(VA[:, i], x)
else
# For immutable arrays like SVector, create a new filled array
VA.u[i] = fill(x, StaticArraysCore.similar_type(VA.u[i]))
end
else
VA[:, i] = x
end
Expand Down
29 changes: 29 additions & 0 deletions test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@ end
@test u1.u[2] isa SVector
end

# Test recursivefill! with immutable StaticArrays (issue #461)
@testset "recursivefill! with immutable StaticArrays (issue #461)" begin
# Test with only immutable SVectors
x = VectorOfArray([SVector{2}(ones(2)), SVector{2}(ones(2))])
recursivefill!(x, 0.0)
@test all(x.u[i] == SVector{2}(zeros(2)) for i in 1:2)
@test all(x.u[i] isa SVector for i in 1:2)

# Test with mixed immutable and mutable StaticArrays
x = VectorOfArray([SVector{2}(ones(2)), MVector{2}(ones(2))])
recursivefill!(x, 0.0)
@test all(x.u[i] == [0.0, 0.0] for i in 1:2)
@test x.u[1] isa SVector
@test x.u[2] isa MVector

# Test fill! on VectorOfArray with immutable SVectors
x = VectorOfArray([SVector{2}(ones(2)), SVector{2}(ones(2))])
fill!(x, 0.0)
@test all(x.u[i] == SVector{2}(zeros(2)) for i in 1:2)
@test all(x.u[i] isa SVector for i in 1:2)

# Test fill! on VectorOfArray with mixed types
x = VectorOfArray([SVector{2}(ones(2)), MVector{2}(ones(2))])
fill!(x, 0.0)
@test all(x.u[i] == [0.0, 0.0] for i in 1:2)
@test x.u[1] isa SVector
@test x.u[2] isa MVector
end

import KernelAbstractions: get_backend
@testset "KernelAbstractions" begin
v = VectorOfArray([randn(2) for i in 1:10])
Expand Down
Loading