aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/accurate_accumulate
diff options
context:
space:
mode:
authoralex-sh <alex-sh@yandex-team.ru>2022-02-10 16:50:03 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:03 +0300
commit88ee78b1a163eaddee7e880ac73943456040fce0 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/accurate_accumulate
parent3196904c9f5bf7aff7374eeadcb0671589581f61 (diff)
downloadydb-88ee78b1a163eaddee7e880ac73943456040fce0.tar.gz
Restoring authorship annotation for <alex-sh@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/accurate_accumulate')
-rw-r--r--library/cpp/accurate_accumulate/accurate_accumulate.cpp2
-rw-r--r--library/cpp/accurate_accumulate/accurate_accumulate.h234
-rw-r--r--library/cpp/accurate_accumulate/ya.make18
3 files changed, 127 insertions, 127 deletions
diff --git a/library/cpp/accurate_accumulate/accurate_accumulate.cpp b/library/cpp/accurate_accumulate/accurate_accumulate.cpp
index 41ea8fb3bf..20928f81f4 100644
--- a/library/cpp/accurate_accumulate/accurate_accumulate.cpp
+++ b/library/cpp/accurate_accumulate/accurate_accumulate.cpp
@@ -1 +1 @@
-#include "accurate_accumulate.h"
+#include "accurate_accumulate.h"
diff --git a/library/cpp/accurate_accumulate/accurate_accumulate.h b/library/cpp/accurate_accumulate/accurate_accumulate.h
index 8dd34b57d3..dacced17e9 100644
--- a/library/cpp/accurate_accumulate/accurate_accumulate.h
+++ b/library/cpp/accurate_accumulate/accurate_accumulate.h
@@ -1,15 +1,15 @@
-#pragma once
-
+#pragma once
+
#include <util/ysaveload.h>
-#include <util/generic/vector.h>
-#include <util/system/yassert.h>
-
+#include <util/generic/vector.h>
+#include <util/system/yassert.h>
+
//! See more details here http://en.wikipedia.org/wiki/Kahan_summation_algorithm
-template <typename TAccumulateType>
-class TKahanAccumulator {
-public:
- using TValueType = TAccumulateType;
-
+template <typename TAccumulateType>
+class TKahanAccumulator {
+public:
+ using TValueType = TAccumulateType;
+
template <typename TFloatType>
explicit TKahanAccumulator(const TFloatType x)
: Sum_(x)
@@ -17,31 +17,31 @@ public:
{
}
- TKahanAccumulator()
+ TKahanAccumulator()
: Sum_()
, Compensation_()
- {
- }
-
- template <typename TFloatType>
+ {
+ }
+
+ template <typename TFloatType>
TKahanAccumulator& operator=(const TFloatType& rhs) {
Sum_ = TValueType(rhs);
Compensation_ = TValueType();
- return *this;
- }
-
+ return *this;
+ }
+
TValueType Get() const {
return Sum_ + Compensation_;
- }
-
- template <typename TFloatType>
+ }
+
+ template <typename TFloatType>
inline operator TFloatType() const {
- return Get();
- }
-
- template <typename TFloatType>
+ return Get();
+ }
+
+ template <typename TFloatType>
inline bool operator<(const TKahanAccumulator<TFloatType>& other) const {
- return Get() < other.Get();
+ return Get() < other.Get();
}
template <typename TFloatType>
@@ -65,90 +65,90 @@ public:
const TValueType t = Sum_ + y;
Compensation_ = (t - Sum_) - y;
Sum_ = t;
- return *this;
- }
-
- template <typename TFloatType>
+ return *this;
+ }
+
+ template <typename TFloatType>
inline TKahanAccumulator& operator-=(const TFloatType x) {
return *this += -TValueType(x);
- }
-
- template <typename TFloatType>
+ }
+
+ template <typename TFloatType>
inline TKahanAccumulator& operator*=(const TFloatType x) {
return *this = TValueType(*this) * TValueType(x);
- }
-
- template <typename TFloatType>
+ }
+
+ template <typename TFloatType>
inline TKahanAccumulator& operator/=(const TFloatType x) {
return *this = TValueType(*this) / TValueType(x);
- }
+ }
Y_SAVELOAD_DEFINE(Sum_, Compensation_)
-private:
+private:
TValueType Sum_;
TValueType Compensation_;
-};
-
-template <typename TAccumulateType, typename TFloatType>
+};
+
+template <typename TAccumulateType, typename TFloatType>
inline const TKahanAccumulator<TAccumulateType>
operator+(TKahanAccumulator<TAccumulateType> lhs, const TFloatType rhs) {
return lhs += rhs;
}
-template <typename TAccumulateType, typename TFloatType>
+template <typename TAccumulateType, typename TFloatType>
inline const TKahanAccumulator<TAccumulateType>
operator-(TKahanAccumulator<TAccumulateType> lhs, const TFloatType rhs) {
return lhs -= rhs;
}
-template <typename TAccumulateType, typename TFloatType>
+template <typename TAccumulateType, typename TFloatType>
inline const TKahanAccumulator<TAccumulateType>
operator*(TKahanAccumulator<TAccumulateType> lhs, const TFloatType rhs) {
- return lhs *= rhs;
-}
-
-template <typename TAccumulateType, typename TFloatType>
+ return lhs *= rhs;
+}
+
+template <typename TAccumulateType, typename TFloatType>
inline const TKahanAccumulator<TAccumulateType>
operator/(TKahanAccumulator<TAccumulateType> lhs, const TFloatType rhs) {
- return lhs /= rhs;
-}
-
-template <typename TAccumulatorType, typename It>
+ return lhs /= rhs;
+}
+
+template <typename TAccumulatorType, typename It>
static inline TAccumulatorType TypedFastAccumulate(It begin, It end) {
- TAccumulatorType accumulator = TAccumulatorType();
-
- for (; begin + 15 < end; begin += 16) {
- accumulator += *(begin + 0) +
- *(begin + 1) +
- *(begin + 2) +
- *(begin + 3) +
- *(begin + 4) +
- *(begin + 5) +
- *(begin + 6) +
- *(begin + 7) +
- *(begin + 8) +
- *(begin + 9) +
- *(begin + 10) +
- *(begin + 11) +
- *(begin + 12) +
- *(begin + 13) +
- *(begin + 14) +
- *(begin + 15);
- }
- for (; begin != end; ++begin) {
- accumulator += *begin;
- }
-
- return accumulator;
-}
-
+ TAccumulatorType accumulator = TAccumulatorType();
+
+ for (; begin + 15 < end; begin += 16) {
+ accumulator += *(begin + 0) +
+ *(begin + 1) +
+ *(begin + 2) +
+ *(begin + 3) +
+ *(begin + 4) +
+ *(begin + 5) +
+ *(begin + 6) +
+ *(begin + 7) +
+ *(begin + 8) +
+ *(begin + 9) +
+ *(begin + 10) +
+ *(begin + 11) +
+ *(begin + 12) +
+ *(begin + 13) +
+ *(begin + 14) +
+ *(begin + 15);
+ }
+ for (; begin != end; ++begin) {
+ accumulator += *begin;
+ }
+
+ return accumulator;
+}
+
template <class TOperation, typename TAccumulatorType, typename It1, typename It2>
static inline TAccumulatorType TypedFastInnerOperation(It1 begin1, It1 end1, It2 begin2) {
- TAccumulatorType accumulator = TAccumulatorType();
-
+ TAccumulatorType accumulator = TAccumulatorType();
+
const TOperation op;
- for (; begin1 + 15 < end1; begin1 += 16, begin2 += 16) {
+ for (; begin1 + 15 < end1; begin1 += 16, begin2 += 16) {
accumulator += op(*(begin1 + 0), *(begin2 + 0)) +
op(*(begin1 + 1), *(begin2 + 1)) +
op(*(begin1 + 2), *(begin2 + 2)) +
@@ -165,57 +165,57 @@ static inline TAccumulatorType TypedFastInnerOperation(It1 begin1, It1 end1, It2
op(*(begin1 + 13), *(begin2 + 13)) +
op(*(begin1 + 14), *(begin2 + 14)) +
op(*(begin1 + 15), *(begin2 + 15));
- }
- for (; begin1 != end1; ++begin1, ++begin2) {
+ }
+ for (; begin1 != end1; ++begin1, ++begin2) {
accumulator += op(*begin1, *begin2);
- }
-
- return accumulator;
-}
-
+ }
+
+ return accumulator;
+}
+
template <typename TAccumulatorType, typename It1, typename It2>
static inline TAccumulatorType TypedFastInnerProduct(It1 begin1, It1 end1, It2 begin2) {
return TypedFastInnerOperation<std::multiplies<>, TAccumulatorType>(begin1, end1, begin2);
}
-template <typename It>
+template <typename It>
static inline double FastAccumulate(It begin, It end) {
- return TypedFastAccumulate<double>(begin, end);
-}
-
-template <typename T>
+ return TypedFastAccumulate<double>(begin, end);
+}
+
+template <typename T>
static inline double FastAccumulate(const TVector<T>& sequence) {
- return FastAccumulate(sequence.begin(), sequence.end());
-}
-
-template <typename It>
+ return FastAccumulate(sequence.begin(), sequence.end());
+}
+
+template <typename It>
static inline double FastKahanAccumulate(It begin, It end) {
return TypedFastAccumulate<TKahanAccumulator<double>>(begin, end);
-}
-
-template <typename T>
+}
+
+template <typename T>
static inline double FastKahanAccumulate(const TVector<T>& sequence) {
- return FastKahanAccumulate(sequence.begin(), sequence.end());
-}
-
-template <typename It1, typename It2>
+ return FastKahanAccumulate(sequence.begin(), sequence.end());
+}
+
+template <typename It1, typename It2>
static inline double FastInnerProduct(It1 begin1, It1 end1, It2 begin2) {
- return TypedFastInnerProduct<double>(begin1, end1, begin2);
-}
-
-template <typename T>
+ return TypedFastInnerProduct<double>(begin1, end1, begin2);
+}
+
+template <typename T>
static inline double FastInnerProduct(const TVector<T>& lhs, const TVector<T>& rhs) {
Y_ASSERT(lhs.size() == rhs.size());
- return FastInnerProduct(lhs.begin(), lhs.end(), rhs.begin());
-}
-
-template <typename It1, typename It2>
+ return FastInnerProduct(lhs.begin(), lhs.end(), rhs.begin());
+}
+
+template <typename It1, typename It2>
static inline double FastKahanInnerProduct(It1 begin1, It1 end1, It2 begin2) {
return TypedFastInnerProduct<TKahanAccumulator<double>>(begin1, end1, begin2);
-}
-
-template <typename T>
+}
+
+template <typename T>
static inline double FastKahanInnerProduct(const TVector<T>& lhs, const TVector<T>& rhs) {
Y_ASSERT(lhs.size() == rhs.size());
- return FastKahanInnerProduct(lhs.begin(), lhs.end(), rhs.begin());
-}
+ return FastKahanInnerProduct(lhs.begin(), lhs.end(), rhs.begin());
+}
diff --git a/library/cpp/accurate_accumulate/ya.make b/library/cpp/accurate_accumulate/ya.make
index 4a1a12d872..82630d19be 100644
--- a/library/cpp/accurate_accumulate/ya.make
+++ b/library/cpp/accurate_accumulate/ya.make
@@ -1,10 +1,10 @@
-LIBRARY()
-
+LIBRARY()
+
OWNER(alex-sh)
-
-SRCS(
- accurate_accumulate.h
- accurate_accumulate.cpp
-)
-
-END()
+
+SRCS(
+ accurate_accumulate.h
+ accurate_accumulate.cpp
+)
+
+END()