Skip to content

perf: add 0-copy reduce-vcat specialization for VectorOfVectors #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pfackeldey
Copy link

This PR adds a specialization for reduce(vcat, VoV) specialization to directly return a flatview, this operation is zero-copy.

V3 = VectorOfVectors(ref_AoA1(Float32, 3))
V4 = VectorOfVectors(ref_AoA1(Float32, 4))

@test reduce(vcat, V1) == flatview(V1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's test the behavior

@test reduce(vcat, V1) == reduce(vcat, Array(V1))

instead.

Copy link
Collaborator

@oschulz oschulz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comments.

@Moelf
Copy link
Contributor

Moelf commented Jul 31, 2025

See other comments.

is there some forgotten comments due to Github UI?

@oschulz
Copy link
Collaborator

oschulz commented Jul 31, 2025

is there some forgotten comments due to Github UI?

No, I meant the change comment, I just had clicked "approve" by default, so I needed to add another review with "request changes".

Copy link

codecov bot commented Jul 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.21%. Comparing base (021083f) to head (b82e295).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #50   +/-   ##
=======================================
  Coverage   96.20%   96.21%           
=======================================
  Files           8        8           
  Lines         527      528    +1     
=======================================
+ Hits          507      508    +1     
  Misses         20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oschulz
Copy link
Collaborator

oschulz commented Aug 1, 2025

@pfackeldey are you going to add reduce for ArrayOfSimilarArrays to this PR? Then I'd hold off with the merge.

@pfackeldey
Copy link
Author

@pfackeldey are you going to add reduce for ArrayOfSimilarArrays to this PR? Then I'd hold off with the merge.

Ah, I didn't know this reduce + vcat specialization can also be done here for ArrayOfSimilarArrays. Then, yes, I'll add this soon to this PR 👍

Comment on lines +108 to +121
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) == 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
@test (@allocated reduce(vcat, V3)) == 0
@test (@allocated reduce(vcat, V4)) == 0
Copy link
Collaborator

@oschulz oschulz Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can shorten this as

Suggested change
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) == 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
@test (@allocated reduce(vcat, V3)) == 0
@test (@allocated reduce(vcat, V4)) == 0
for n in [1, 2, 3, 4]
V = VectorOfVectors(ref_AoA1(Float32, n))
@test reduce(vcat, V) == reduce(vcat, Array(1))
@test (@allocated reduce(vcat, V)) == 0
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants