Skip to content

Commit c97e021

Browse files
committed
Fix flatview on view of VectorOfArrays
1 parent 773f466 commit c97e021

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/vector_of_arrays.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ Returns the internal serialized representation of all element arrays of `A` as
176176
a single vector. Do *not* change the length of the returned vector, as it
177177
would break the inner consistency of `A`.
178178
"""
179-
flatview(A::VectorOfArrays) = A.data
179+
flatview(A::VectorOfArrays{<:Any,N,M,<:Any}) where {N,M} = A.data
180+
181+
function flatview(A::VectorOfArrays{<:Any,N,M,<:Any,<:SubArray}) where {N,M}
182+
view(A.data, A.elem_ptr[begin]:A.elem_ptr[end]-1)
183+
end
180184

181185
Base.size(A::VectorOfArrays) = size(A.kernel_size)
182186

test/vector_of_arrays.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
1010

1111

1212
@testset "vector_of_arrays" begin
13+
ref_flatview(A::AbstractVector{<:AbstractArray}) = vcat(map(vec, Array(A))...)
14+
1315
ref_AoA1(T::Type, n::Integer) = n == 0 ? [Array{T}(undef, 5)][1:0] : [rand(T, rand(1:9)) for i in 1:n]
1416
ref_AoA2(T::Type, n::Integer) = n == 0 ? [Array{T}(undef, 4, 2)][1:0] : [rand(T, rand(1:4), rand(1:4)) for i in 1:n]
1517
ref_AoA3(T::Type, n::Integer) = n == 0 ? [Array{T}(undef, 3, 2, 4)][1:0] : [rand(T, rand(1:3), rand(1:3), rand(1:3)) for i in 1:n]
@@ -311,7 +313,8 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
311313

312314
nestedV = @inferred(AbstractVector{AbstractArray{Float64, 4}}([rand(4,2,3,1), rand(5,3,1,3), rand(6,4,3,1), rand(9,2,1,2)]))
313315
VoA1 = @inferred(convert(VectorOfArrays, nestedV))
314-
@test @inferred(flatview(VoA1)) == VoA1.data
316+
@test @inferred(flatview(VoA1)) === VoA1.data == ref_flatview(VoA1)
317+
@test @inferred(flatview(view(VoA1, 2:3))) == ref_flatview(view(VoA1, 2:3))
315318
VoA2 = @inferred(convert(VectorOfArrays{Float32, 4}, nestedV))
316319
@test @inferred(map(Float32, VoA1.data)) == VoA2.data
317320

0 commit comments

Comments
 (0)