From 72ac0ce6f9b6ba9944dcc3c35f4f998673c85449 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 30 Oct 2024 16:35:45 +0530 Subject: [PATCH 1/3] fix: do not assume `AbstractVectorOfArray` is mutable in `Base.zero` --- src/vector_of_array.jl | 2 +- test/interface_tests.jl | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 95a2a930..fc2fce0b 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -521,7 +521,7 @@ end function Base.zero(VA::AbstractVectorOfArray) val = copy(VA) - val.u = zero.(VA.u) + val.u .= zero.(VA.u) return val end diff --git a/test/interface_tests.jl b/test/interface_tests.jl index f370e21d..a1266082 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -269,3 +269,13 @@ end f3!(z, zz) @test z == VectorOfArray([fill(4, SVector{2, Float64}), fill(2, SVector{2, Float64})]) @test (@allocated f3!(z, zz)) == 0 + +struct ImmutableVectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N, A} + u::A # A <: AbstractArray{<: AbstractArray{T, N - 1}} +end + +@testset "Base.zero does not assume mutable struct" begin + voa = ImmutableVectorOfArray{Float64, 2, Vector{Vector{Float64}}}([ones(3), 2ones(3)]) + zvoa = zero(voa) + @test zvoa.u[1] == zvoa.u[2] == zeros(3) +end From 8b4f756ead697407d1bf796f57f412c85c682587 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 30 Oct 2024 16:35:49 +0530 Subject: [PATCH 2/3] refactor: format --- test/linalg.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/linalg.jl b/test/linalg.jl index 23fedffb..33a8c4ec 100644 --- a/test/linalg.jl +++ b/test/linalg.jl @@ -56,4 +56,4 @@ mat = Array(va) @test all(va'[i] == mat'[i] for i in eachindex(mat')) @test Array(va') == mat' -@test !ArrayInterface.issingular(VectorOfArray([rand(2),rand(2)])) +@test !ArrayInterface.issingular(VectorOfArray([rand(2), rand(2)])) From 439354c5e2910e9b21ebbed35e42c7f2b37ecc3d Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 30 Oct 2024 17:20:02 +0530 Subject: [PATCH 3/3] test: remove working `@test_broken` --- test/partitions_test.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/partitions_test.jl b/test/partitions_test.jl index 2625941e..d444a4ff 100644 --- a/test/partitions_test.jl +++ b/test/partitions_test.jl @@ -161,7 +161,6 @@ _scalar_op(y) = y + 1 _broadcast_wrapper(y) = _scalar_op.(y) # Issue #8 @inferred _broadcast_wrapper(x) -@test_broken @inferred _broadcast_wrapper(y) # Testing map @test map(x -> x^2, x) == ArrayPartition(x.x[1] .^ 2, x.x[2] .^ 2)