27#ifndef ROOT_Math_VecTypes
34#define MATH_UNUSED(var) (void)var
52 std::ostringstream buf;
55 std::string ret = buf.str();
65 static const T epsilon =
T(2.0 * std::numeric_limits<double>::min());
121 template<
typename T =
double,
unsigned int N = 1>
127 fSum[0] = initialValue;
136 fSum[0] = initialSumValue;
137 fCarry[0] = initialCarryValue;
147 template<
class Iterator>
148 KahanSum(Iterator sumBegin, Iterator sumEnd, Iterator carryBegin, Iterator carryEnd) {
149 assert(std::distance(sumBegin, sumEnd) ==
N);
150 assert(std::distance(carryBegin, carryEnd) ==
N);
151 std::copy(sumBegin, sumEnd, std::begin(
fSum));
152 std::copy(carryBegin, carryEnd, std::begin(
fCarry));
156 template <
unsigned int M>
167 auto t =
fSum[0] +
y;
179 template <
class Iterator>
180 void Add(Iterator begin, Iterator end) {
181 static_assert(std::is_floating_point<
182 typename std::remove_reference<
decltype(*begin)>
::type>
::value,
183 "Iterator needs to point to floating-point values.");
184 const std::size_t
n = std::distance(begin, end);
186 for (std::size_t i=0; i<
n; ++i) {
194 template<
class Container_t>
195 void Add(
const Container_t& inputs) {
197 "Container does not hold floating-point values.");
198 for (std::size_t i=0; i < inputs.size(); ++i) {
210 template <
class Iterator>
212 T initialValue =
T{}) {
214 theSum.Add(begin, end);
232 const unsigned int i =
index %
N;
241 return std::accumulate(std::begin(
fSum), std::end(
fSum), 0.);
256 return std::accumulate(std::begin(
fCarry), std::end(
fCarry), 0.);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
KahanSum & operator+=(const KahanSum< U > &arg)
Add arg into accumulator. Does not vectorise.
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
void Add(Iterator begin, Iterator end)
Accumulate from a range denoted by iterators.
void Add(const Container_t &inputs)
Fill from a container that supports index access.
KahanSum< T, N > & operator-=(KahanSum< T, N > const &other)
Subtract other KahanSum.
KahanSum(KahanSum< T, M > const &other)
Constructor to create a KahanSum from another KahanSum with a different number of accumulators.
void AddIndexed(T input, std::size_t index)
Add input to the sum.
KahanSum< T, N > & operator+=(T arg)
Add arg into accumulator. Does not vectorise.
KahanSum(T initialValue=T{})
Initialise the sum.
KahanSum(T initialSumValue, T initialCarryValue)
Initialise with a sum value and a carry value.
void Add(T x)
Single-element accumulation. Will not vectorise.
KahanSum(Iterator sumBegin, Iterator sumEnd, Iterator carryBegin, Iterator carryEnd)
Initialise the sum with a pre-existing state.
RVec< PromoteType< T > > log(const RVec< T > &v)
Namespace for new Math classes and functions.
T EvalLog(T x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
std::string ToString(const T &val)
Utility function for conversion to strings.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.