Skip to content

feature: Add opt-in Kahan compensated summation#134

Open
rtmongold wants to merge 1 commit into
mainfrom
feature/kahan-summation
Open

feature: Add opt-in Kahan compensated summation#134
rtmongold wants to merge 1 commit into
mainfrom
feature/kahan-summation

Conversation

@rtmongold

@rtmongold rtmongold commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #13

Note: Adds a public summation field on IterativeConfig (default Pairwise). Call sites that build the struct with a full literal need the new field; Default, from_parameters, and with_summation are unchanged in behavior for existing users.

Checklist

  • CHANGELOG.md updated under ## [Unreleased] (required for behavior-facing changes)
  • cargo test + cargo clippy --all-targets clean locally
  • New public APIs have a doc example
  • No unwrap/expect/panic on library paths (typed errors instead)

@rtmongold rtmongold requested a review from kmolan as a code owner July 12, 2026 20:05
@rtmongold rtmongold force-pushed the feature/kahan-summation branch from 3ec109a to 407cec2 Compare July 12, 2026 20:05
Note: Adds a public summation field on IterativeConfig (default
Pairwise). Call sites that build the struct with a full literal need the
new field; Default, from_parameters, and with_summation are unchanged in
behavior for existing users.
@rtmongold rtmongold force-pushed the feature/kahan-summation branch from a478499 to ca11954 Compare July 12, 2026 22:23
@kmolan

kmolan commented Jul 13, 2026

Copy link
Copy Markdown
Owner

I do not like changing function APIs to add a new "summation" arg that 99% of the users will never care about. That is why currently pairwise summation is default. Unfortunately Rust does not do default function args so that adds another complication.

I would instead add the summation arg in struct member definitions, with pairwise as default. Users must call builder pattern function to enable kahan sum if needed. So for example LinearApproximator::default().with_kahan_summation() to perform all operations with kahan summation instead of the default pairwise. Similar logic for quadratic approximator and also the iterative integrators. Leave the existing APIs unchanged, add logic in them internally to perform the correct summation using method that user chose during initialization.

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.

Add compensated (Kahan) summation for long sums

2 participants