13class KahanSum final :
public ROOT::Detail::RDF::RActionImpl<class KahanSum<T>> {
19 std::vector<T> fPartialSums;
20 std::vector<T> fCompensations;
23 std::shared_ptr<T> fResultSum;
25 void KahanAlgorithm(
const T &
x,
T &
sum,
T &compensation){
26 T y =
x - compensation;
28 compensation = (t -
sum) -
y;
33 KahanSum(KahanSum &&) =
default;
34 KahanSum(
const KahanSum &) =
delete;
36 KahanSum(
const std::shared_ptr<T> &
r) : fResultSum(
r)
38 static_assert(std::is_floating_point<T>::value,
"Kahan sum makes sense only on floating point numbers");
41 fPartialSums.resize(fNSlots, 0.);
42 fCompensations.resize(fNSlots, 0.);
45 std::shared_ptr<Result_t> GetResultPtr()
const {
return fResultSum; }
50 void Exec(
unsigned int slot,
T x)
52 KahanAlgorithm(
x, fPartialSums[slot], fCompensations[slot]);
55 template <typename V=T, typename std::enable_if<ROOT::Internal::RDF::IsDataContainer<V>::value,
int>
::type = 0>
56 void Exec(
unsigned int slot,
const T &vs)
67 for (
int i = 0; i < fNSlots; ++i) {
68 KahanAlgorithm(fPartialSums[i],
sum, compensation);
73 std::string GetActionName(){
85 auto dd =
d.Define(
"x",
"(rdfentry_ %2 == 0) ? 0.00000001 : 100000000.");
87 auto ptr = std::make_shared<double>();
88 KahanSum<double> helper(ptr);
90 auto kahanResult = dd.Book<
double>(std::move(helper), {
"x"});
91 auto plainResult = dd.Sum<
double>({
"x"});
93 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 TTrees,...
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 long int sum(long int i)