Skip to content

Commit caa8d9f

Browse files
Merge pull request #409 from AayushSabharwal/as/immutable=zero
fix: do not assume `AbstractVectorOfArray` is mutable in `Base.zero`
2 parents 600a9b5 + 439354c commit caa8d9f

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/vector_of_array.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ end
521521

522522
function Base.zero(VA::AbstractVectorOfArray)
523523
val = copy(VA)
524-
val.u = zero.(VA.u)
524+
val.u .= zero.(VA.u)
525525
return val
526526
end
527527

test/interface_tests.jl

+10
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,13 @@ end
269269
f3!(z, zz)
270270
@test z == VectorOfArray([fill(4, SVector{2, Float64}), fill(2, SVector{2, Float64})])
271271
@test (@allocated f3!(z, zz)) == 0
272+
273+
struct ImmutableVectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N, A}
274+
u::A # A <: AbstractArray{<: AbstractArray{T, N - 1}}
275+
end
276+
277+
@testset "Base.zero does not assume mutable struct" begin
278+
voa = ImmutableVectorOfArray{Float64, 2, Vector{Vector{Float64}}}([ones(3), 2ones(3)])
279+
zvoa = zero(voa)
280+
@test zvoa.u[1] == zvoa.u[2] == zeros(3)
281+
end

test/linalg.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ mat = Array(va)
5656
@test all(va'[i] == mat'[i] for i in eachindex(mat'))
5757
@test Array(va') == mat'
5858

59-
@test !ArrayInterface.issingular(VectorOfArray([rand(2),rand(2)]))
59+
@test !ArrayInterface.issingular(VectorOfArray([rand(2), rand(2)]))

test/partitions_test.jl

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ _scalar_op(y) = y + 1
161161
_broadcast_wrapper(y) = _scalar_op.(y)
162162
# Issue #8
163163
@inferred _broadcast_wrapper(x)
164-
@test_broken @inferred _broadcast_wrapper(y)
165164

166165
# Testing map
167166
@test map(x -> x^2, x) == ArrayPartition(x.x[1] .^ 2, x.x[2] .^ 2)

0 commit comments

Comments
 (0)