From 1ff2d4d6bf06dd359227d0ffc96a6abecacf18e4 Mon Sep 17 00:00:00 2001 From: pfackeldey Date: Thu, 31 Jul 2025 09:35:30 -0400 Subject: [PATCH 1/2] perf: add 0-copy reduce-vcat specialization for VectorOfVectors --- src/vector_of_arrays.jl | 2 ++ test/vector_of_arrays.jl | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/vector_of_arrays.jl b/src/vector_of_arrays.jl index 645a9e2..5ffc160 100644 --- a/src/vector_of_arrays.jl +++ b/src/vector_of_arrays.jl @@ -573,3 +573,5 @@ function consgroupedview(source::AbstractVector, target::NamedTuple{syms,<:NTupl elem_ptr = consgrouped_ptrs(source) map(X -> VectorOfVectors(X, elem_ptr), target) end + +Base.reduce(::typeof(vcat), V::VectorOfVectors) = flatview(V) \ No newline at end of file diff --git a/test/vector_of_arrays.jl b/test/vector_of_arrays.jl index 8ea4d00..c9c8659 100644 --- a/test/vector_of_arrays.jl +++ b/test/vector_of_arrays.jl @@ -104,6 +104,21 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr B1_copy = @inferred(copy(B1)); B3_copy = @inferred(copy(B3)) append!(B1_copy, B3_copy) @test B1_copy.data == vcat(B1.data, B3.data) + + V1 = VectorOfVectors(ref_AoA1(Float32, 1)) + V2 = VectorOfVectors(ref_AoA1(Float32, 2)) + V3 = VectorOfVectors(ref_AoA1(Float32, 3)) + V4 = VectorOfVectors(ref_AoA1(Float32, 4)) + + @test reduce(vcat, V1) == flatview(V1) + @test reduce(vcat, V2) == flatview(V2) + @test reduce(vcat, V3) == flatview(V3) + @test reduce(vcat, V4) == flatview(V4) + + @test (@allocated reduce(vcat, V1)) == 0 + @test (@allocated reduce(vcat, V2)) == 0 + @test (@allocated reduce(vcat, V3)) == 0 + @test (@allocated reduce(vcat, V4)) == 0 end From b82e2956ea7c2a96991b6f104ed48880c3cc7395 Mon Sep 17 00:00:00 2001 From: pfackeldey Date: Thu, 31 Jul 2025 10:41:32 -0400 Subject: [PATCH 2/2] tests: flatview -> reduce(vcat, Array(...)) --- test/vector_of_arrays.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/vector_of_arrays.jl b/test/vector_of_arrays.jl index c9c8659..bc27f6a 100644 --- a/test/vector_of_arrays.jl +++ b/test/vector_of_arrays.jl @@ -110,10 +110,10 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr V3 = VectorOfVectors(ref_AoA1(Float32, 3)) V4 = VectorOfVectors(ref_AoA1(Float32, 4)) - @test reduce(vcat, V1) == flatview(V1) - @test reduce(vcat, V2) == flatview(V2) - @test reduce(vcat, V3) == flatview(V3) - @test reduce(vcat, V4) == flatview(V4) + @test reduce(vcat, V1) == reduce(vcat, Array(V1)) + @test reduce(vcat, V2) == reduce(vcat, Array(V2)) + @test reduce(vcat, V3) == reduce(vcat, Array(V3)) + @test reduce(vcat, V4) == reduce(vcat, Array(V4)) @test (@allocated reduce(vcat, V1)) == 0 @test (@allocated reduce(vcat, V2)) == 0