21 std::vector<T> fPartialSums;
22 std::vector<T> fCompensations;
25 std::shared_ptr<T> fResultSum;
27 void KahanAlgorithm(
const T &
x, T &
sum, T &compensation){
28 T y =
x - compensation;
30 compensation = (t -
sum) -
y;
35 KahanSum(KahanSum &&) =
default;
36 KahanSum(
const KahanSum &) =
delete;
38 KahanSum(
const std::shared_ptr<T> &
r) : fResultSum(
r)
40 static_assert(std::is_floating_point<T>::value,
"Kahan sum makes sense only on floating point numbers");
43 fPartialSums.resize(fNSlots, 0.);
44 fCompensations.resize(fNSlots, 0.);
47 std::shared_ptr<Result_t> GetResultPtr()
const {
return fResultSum; }
52 void Exec(
unsigned int slot, T
x)
54 KahanAlgorithm(
x, fPartialSums[slot], fCompensations[slot]);
57 template <typename V=T, std::enable_if_t<ROOT::Internal::RDF::IsDataContainer<V>::value,
int> = 0>
58 void Exec(
unsigned int slot,
const T &vs)
69 for (
int i = 0; i < fNSlots; ++i) {
70 KahanAlgorithm(fPartialSums[i],
sum, compensation);
75 std::string GetActionName(){
87 auto dd =
d.Define(
"x",
"(rdfentry_ %2 == 0) ? 0.00000001 : 100000000.");
89 auto ptr = std::make_shared<double>();
90 KahanSum<double> helper(ptr);
92 auto kahanResult = dd.Book<
double>(std::move(helper), {
"x"});
93 auto plainResult = dd.Sum<
double>({
"x"});
95 std::cout << std::setprecision(24) <<
"Kahan: " << *kahanResult <<
" Classical: " << *plainResult << std::endl;
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTree,...
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
CPYCPPYY_EXTERN bool Exec(const std::string &cmd)
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
void Initialize(Bool_t useTMVAStyle=kTRUE)
static uint64_t sum(uint64_t i)