Skip to content

Leverage Base reduction functions for sum #37

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 8 commits into
base: master
Choose a base branch
from

Conversation

asinghvi17
Copy link

@asinghvi17 asinghvi17 commented May 10, 2025

Re-implementation of #7 with some extra tests. I could use Kahan summation in some GeometryOps.jl things I am doing, especially the sum_kbn(f, itr) form.

# this implementation
julia> @be sum_kbn($(rand(1000)))
Benchmark: 3348 samples with 16 evaluations
 min    1.677 μs
 median 1.734 μs
 mean   1.738 μs
 max    7.698 μs

# the implementation on master
julia> @be KahanSummation.sum_kbn($(rand(1000)))
Benchmark: 3336 samples with 16 evaluations
 min    1.682 μs
 median 1.698 μs
 mean   1.740 μs
 max    4.336 μs

# compared to current Base pairwise summation, slower of course
julia> @be sum($(rand(1000)))
Benchmark: 3198 samples with 290 evaluations
 min    98.131 ns
 median 98.707 ns
 mean   100.700 ns
 max    268.390 ns

I attached a timer output and it never calls the method for two TwicePrecisions. (Annotations mine)

julia> to
────────────────────────────────────────────────────────────────────
                           Time                    Allocations      
                  ───────────────────────   ────────────────────────
Tot / % measured:      2.13s /   0.8%           3.68MiB /   0.0%    

Section                           ncalls     time    %tot     avg     alloc    %tot      avg
───────────────────────────────────────────────────────────────────────────────
+(::Float64, ::TwicePrecisionN)     1.72M   17.9ms   99.9%  10.4ns     0.00B     - %    0.00B
+(::Float64, ::Float64)             1.72k   17.4μs    0.1%  10.1ns     0.00B     - %    0.00B
───────────────────────────────────────────────────────────────────────────────

Copy link

codecov bot commented May 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (8d24619) to head (c659cf8).

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #37   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           56        64    +8     
=========================================
+ Hits            56        64    +8     

☔ 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.

@asinghvi17 asinghvi17 marked this pull request as ready for review May 10, 2025 15:27
@JeffreySarnoff
Copy link
Member

@simonbyrne any objection?

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.

2 participants