Opened 12 years ago

Closed 11 years ago

#4471 closed Feature Requests (fixed)

Kahan sum

Reported by: anonymous Owned by: Eric Niebler
Milestone: Boost 1.44.0 Component: accumulator
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

Request to have Kahan algorithm added to accumulators.

Attachments (1)

patch.txt (4.3 KB ) - added by mendola@… 12 years ago.
patch for kahan sum

Download all attachments as: .zip

Change History (3)

by mendola@…, 12 years ago

Attachment: patch.txt added

patch for kahan sum

comment:1 by Eric Niebler, 12 years ago

From Gaetano:

At this page:

http://www.boost.org/doc/libs/1_43_0/doc/html/accumulators/user_s_guide.html#accumulators.user_s_guide.the_statistical_accumulators_library

I would add a link sum_kahan pointing to this:

sum_kahan

Implements the summation kahan's algorithm, reducing the accumulation
error in case of floating point types.

Result Type

    sample-type

Depends On

    none
Variants

    none
Initialization Parameters

    none
Accumulator Parameters

    none
Extractor Parameters

    none
Accumulator Complexity

    O(1), however compared to naive sum this accumulator
          performs 4 sum operations for each element accumulated

Extractor Complexity

    O(1)

Header

#include <boost/accumulators/statistics/sum_kahan.hpp>

Example

    accumulator_set<float, stats<tag::sum_kahan> > acc;

    BOOST_CHECK_EQUAL(0.0f, sum_kahan(acc));

    for (size_t i = 0; i < 1e6; ++i) {
      acc(1e-6f);
    }

    BOOST_CHECK_EQUAL(1.0f, sum_kahan(acc));

comment:2 by Eric Niebler, 11 years ago

Resolution: fixed
Status: newclosed

(In [72045]) add kahan sum, fixes #4471

Note: See TracTickets for help on using tickets.