Skip to content

Commit 1ff2d4d

Browse files
committed
perf: add 0-copy reduce-vcat specialization for VectorOfVectors
1 parent 021083f commit 1ff2d4d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/vector_of_arrays.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,5 @@ function consgroupedview(source::AbstractVector, target::NamedTuple{syms,<:NTupl
573573
elem_ptr = consgrouped_ptrs(source)
574574
map(X -> VectorOfVectors(X, elem_ptr), target)
575575
end
576+
577+
Base.reduce(::typeof(vcat), V::VectorOfVectors) = flatview(V)

test/vector_of_arrays.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
104104
B1_copy = @inferred(copy(B1)); B3_copy = @inferred(copy(B3))
105105
append!(B1_copy, B3_copy)
106106
@test B1_copy.data == vcat(B1.data, B3.data)
107+
108+
V1 = VectorOfVectors(ref_AoA1(Float32, 1))
109+
V2 = VectorOfVectors(ref_AoA1(Float32, 2))
110+
V3 = VectorOfVectors(ref_AoA1(Float32, 3))
111+
V4 = VectorOfVectors(ref_AoA1(Float32, 4))
112+
113+
@test reduce(vcat, V1) == flatview(V1)
114+
@test reduce(vcat, V2) == flatview(V2)
115+
@test reduce(vcat, V3) == flatview(V3)
116+
@test reduce(vcat, V4) == flatview(V4)
117+
118+
@test (@allocated reduce(vcat, V1)) == 0
119+
@test (@allocated reduce(vcat, V2)) == 0
120+
@test (@allocated reduce(vcat, V3)) == 0
121+
@test (@allocated reduce(vcat, V4)) == 0
107122
end
108123

109124

0 commit comments

Comments
 (0)