updated boost on windows

This commit is contained in:
Bassem Girgis
2019-08-13 21:48:48 -05:00
parent 7d77d485fd
commit b40a3bee82
5162 changed files with 473027 additions and 116452 deletions

View File

@@ -0,0 +1,90 @@
// Copyright 2015-2018 Hans Dembinski
//
// Distributed under the Boost Software License, version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HISTOGRAM_ACCUMULATORS_MEAN_HPP
#define BOOST_HISTOGRAM_ACCUMULATORS_MEAN_HPP
#include <boost/histogram/fwd.hpp>
#include <cstddef>
#include <type_traits>
namespace boost {
namespace histogram {
namespace accumulators {
/** Calculates mean and variance of sample.
Uses Welfords's incremental algorithm to improve the numerical
stability of mean and variance computation.
*/
template <class RealType>
class mean {
public:
mean() = default;
mean(const std::size_t n, const RealType& mean, const RealType& variance)
: sum_(n), mean_(mean), sum_of_deltas_squared_(variance * (sum_ - 1)) {}
void operator()(const RealType& x) {
sum_ += 1;
const auto delta = x - mean_;
mean_ += delta / sum_;
sum_of_deltas_squared_ += delta * (x - mean_);
}
template <class T>
mean& operator+=(const mean<T>& rhs) {
const auto tmp = mean_ * sum_ + static_cast<RealType>(rhs.mean_ * rhs.sum_);
sum_ += rhs.sum_;
mean_ = tmp / sum_;
sum_of_deltas_squared_ += static_cast<RealType>(rhs.sum_of_deltas_squared_);
return *this;
}
mean& operator*=(const RealType& s) {
mean_ *= s;
sum_of_deltas_squared_ *= s * s;
return *this;
}
template <class T>
bool operator==(const mean<T>& rhs) const noexcept {
return sum_ == rhs.sum_ && mean_ == rhs.mean_ &&
sum_of_deltas_squared_ == rhs.sum_of_deltas_squared_;
}
template <class T>
bool operator!=(const mean<T>& rhs) const noexcept {
return !operator==(rhs);
}
std::size_t count() const noexcept { return sum_; }
const RealType& value() const noexcept { return mean_; }
RealType variance() const { return sum_of_deltas_squared_ / (sum_ - 1); }
template <class Archive>
void serialize(Archive&, unsigned /* version */);
private:
std::size_t sum_ = 0;
RealType mean_ = 0, sum_of_deltas_squared_ = 0;
};
} // namespace accumulators
} // namespace histogram
} // namespace boost
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
namespace std {
template <class T, class U>
/// Specialization for boost::histogram::accumulators::mean.
struct common_type<boost::histogram::accumulators::mean<T>,
boost::histogram::accumulators::mean<U>> {
using type = boost::histogram::accumulators::mean<common_type_t<T, U>>;
};
} // namespace std
#endif
#endif

View File

@@ -0,0 +1,52 @@
// Copyright 2015-2017 Hans Dembinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HISTOGRAM_ACCUMULATORS_OSTREAM_HPP
#define BOOST_HISTOGRAM_ACCUMULATORS_OSTREAM_HPP
#include <boost/histogram/fwd.hpp>
#include <iosfwd>
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
namespace boost {
namespace histogram {
namespace accumulators {
template <typename CharT, typename Traits, typename W>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
const sum<W>& x) {
os << "sum(" << x.large() << " + " << x.small() << ")";
return os;
}
template <typename CharT, typename Traits, typename W>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
const weighted_sum<W>& x) {
os << "weighted_sum(" << x.value() << ", " << x.variance() << ")";
return os;
}
template <typename CharT, typename Traits, typename W>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
const mean<W>& x) {
os << "mean(" << x.count() << ", " << x.value() << ", " << x.variance() << ")";
return os;
}
template <typename CharT, typename Traits, typename W>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
const weighted_mean<W>& x) {
os << "weighted_mean(" << x.sum_of_weights() << ", " << x.value() << ", "
<< x.variance() << ")";
return os;
}
} // namespace accumulators
} // namespace histogram
} // namespace boost
#endif // BOOST_HISTOGRAM_DOXYGEN_INVOKED
#endif

View File

@@ -0,0 +1,107 @@
// Copyright 2018 Hans Dembinski
//
// Distributed under the Boost Software License, version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HISTOGRAM_ACCUMULATORS_SUM_HPP
#define BOOST_HISTOGRAM_ACCUMULATORS_SUM_HPP
#include <boost/histogram/fwd.hpp>
#include <cmath>
#include <type_traits>
namespace boost {
namespace histogram {
namespace accumulators {
/**
Uses Neumaier algorithm to compute accurate sums.
The algorithm uses memory for two floats and is three to
five times slower compared to a simple floating point
number used to accumulate a sum, but the relative error
of the sum is at the level of the machine precision,
independent of the number of samples.
A. Neumaier, Zeitschrift fuer Angewandte Mathematik
und Mechanik 54 (1974) 39-51.
*/
template <typename RealType>
class sum {
public:
sum() = default;
/// Initialize sum to value
explicit sum(const RealType& value) noexcept : large_(value) {}
/// Set sum to value
sum& operator=(const RealType& value) noexcept {
large_ = value;
small_ = 0;
return *this;
}
/// Increment sum by one
sum& operator++() { return operator+=(1); }
/// Increment sum by value
sum& operator+=(const RealType& value) {
auto temp = large_ + value; // prevent optimization
if (std::abs(large_) >= std::abs(value))
small_ += (large_ - temp) + value;
else
small_ += (value - temp) + large_;
large_ = temp;
return *this;
}
/// Scale by value
sum& operator*=(const RealType& value) {
large_ *= value;
small_ *= value;
return *this;
}
template <class T>
bool operator==(const sum<T>& rhs) const noexcept {
return large_ == rhs.large_ && small_ == rhs.small_;
}
template <class T>
bool operator!=(const T& rhs) const noexcept {
return !operator==(rhs);
}
/// Return large part of the sum.
const RealType& large() const { return large_; }
/// Return small part of the sum.
const RealType& small() const { return small_; }
// allow implicit conversion to RealType
operator RealType() const { return large_ + small_; }
template <class Archive>
void serialize(Archive&, unsigned /* version */);
private:
RealType large_ = RealType();
RealType small_ = RealType();
};
} // namespace accumulators
} // namespace histogram
} // namespace boost
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
namespace std {
template <class T, class U>
struct common_type<boost::histogram::accumulators::sum<T>,
boost::histogram::accumulators::sum<U>> {
using type = boost::histogram::accumulators::sum<common_type_t<T, U>>;
};
} // namespace std
#endif
#endif

View File

@@ -0,0 +1,106 @@
// Copyright 2018 Hans Dembinski
//
// Distributed under the Boost Software License, version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HISTOGRAM_ACCUMULATORS_WEIGHTED_MEAN_HPP
#define BOOST_HISTOGRAM_ACCUMULATORS_WEIGHTED_MEAN_HPP
#include <boost/histogram/fwd.hpp>
#include <type_traits>
namespace boost {
namespace histogram {
namespace accumulators {
/**
Calculates mean and variance of weighted sample.
Uses West's incremental algorithm to improve numerical stability
of mean and variance computation.
*/
template <typename RealType>
class weighted_mean {
public:
weighted_mean() = default;
weighted_mean(const RealType& wsum, const RealType& wsum2, const RealType& mean,
const RealType& variance)
: sum_of_weights_(wsum)
, sum_of_weights_squared_(wsum2)
, weighted_mean_(mean)
, sum_of_weighted_deltas_squared_(
variance * (sum_of_weights_ - sum_of_weights_squared_ / sum_of_weights_)) {}
void operator()(const RealType& x) { operator()(1, x); }
void operator()(const RealType& w, const RealType& x) {
sum_of_weights_ += w;
sum_of_weights_squared_ += w * w;
const auto delta = x - weighted_mean_;
weighted_mean_ += w * delta / sum_of_weights_;
sum_of_weighted_deltas_squared_ += w * delta * (x - weighted_mean_);
}
template <typename T>
weighted_mean& operator+=(const weighted_mean<T>& rhs) {
const auto tmp = weighted_mean_ * sum_of_weights_ +
static_cast<RealType>(rhs.weighted_mean_ * rhs.sum_of_weights_);
sum_of_weights_ += static_cast<RealType>(rhs.sum_of_weights_);
sum_of_weights_squared_ += static_cast<RealType>(rhs.sum_of_weights_squared_);
weighted_mean_ = tmp / sum_of_weights_;
sum_of_weighted_deltas_squared_ +=
static_cast<RealType>(rhs.sum_of_weighted_deltas_squared_);
return *this;
}
weighted_mean& operator*=(const RealType& s) {
weighted_mean_ *= s;
sum_of_weighted_deltas_squared_ *= s * s;
return *this;
}
template <typename T>
bool operator==(const weighted_mean<T>& rhs) const noexcept {
return sum_of_weights_ == rhs.sum_of_weights_ &&
sum_of_weights_squared_ == rhs.sum_of_weights_squared_ &&
weighted_mean_ == rhs.weighted_mean_ &&
sum_of_weighted_deltas_squared_ == rhs.sum_of_weighted_deltas_squared_;
}
template <typename T>
bool operator!=(const T& rhs) const noexcept {
return !operator==(rhs);
}
const RealType& sum_of_weights() const noexcept { return sum_of_weights_; }
const RealType& value() const noexcept { return weighted_mean_; }
RealType variance() const {
return sum_of_weighted_deltas_squared_ /
(sum_of_weights_ - sum_of_weights_squared_ / sum_of_weights_);
}
template <class Archive>
void serialize(Archive&, unsigned /* version */);
private:
RealType sum_of_weights_ = RealType(), sum_of_weights_squared_ = RealType(),
weighted_mean_ = RealType(), sum_of_weighted_deltas_squared_ = RealType();
};
} // namespace accumulators
} // namespace histogram
} // namespace boost
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
namespace std {
template <class T, class U>
/// Specialization for boost::histogram::accumulators::weighted_mean.
struct common_type<boost::histogram::accumulators::weighted_mean<T>,
boost::histogram::accumulators::weighted_mean<U>> {
using type = boost::histogram::accumulators::weighted_mean<common_type_t<T, U>>;
};
} // namespace std
#endif
#endif

View File

@@ -0,0 +1,112 @@
// Copyright 2015-2018 Hans Dembinski
//
// Distributed under the Boost Software License, version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_HISTOGRAM_ACCUMULATORS_WEIGHTED_SUM_HPP
#define BOOST_HISTOGRAM_ACCUMULATORS_WEIGHTED_SUM_HPP
#include <boost/histogram/fwd.hpp>
#include <type_traits>
namespace boost {
namespace histogram {
namespace accumulators {
/// Holds sum of weights and its variance estimate
template <typename RealType>
class weighted_sum {
public:
weighted_sum() = default;
explicit weighted_sum(const RealType& value) noexcept
: sum_of_weights_(value), sum_of_weights_squared_(value) {}
weighted_sum(const RealType& value, const RealType& variance) noexcept
: sum_of_weights_(value), sum_of_weights_squared_(variance) {}
/// Increment by one.
weighted_sum& operator++() { return operator+=(1); }
/// Increment by value.
template <typename T>
weighted_sum& operator+=(const T& value) {
sum_of_weights_ += value;
sum_of_weights_squared_ += value * value;
return *this;
}
/// Added another weighted sum.
template <typename T>
weighted_sum& operator+=(const weighted_sum<T>& rhs) {
sum_of_weights_ += static_cast<RealType>(rhs.sum_of_weights_);
sum_of_weights_squared_ += static_cast<RealType>(rhs.sum_of_weights_squared_);
return *this;
}
/// Scale by value.
weighted_sum& operator*=(const RealType& x) {
sum_of_weights_ *= x;
sum_of_weights_squared_ *= x * x;
return *this;
}
bool operator==(const RealType& rhs) const noexcept {
return sum_of_weights_ == rhs && sum_of_weights_squared_ == rhs;
}
template <typename T>
bool operator==(const weighted_sum<T>& rhs) const noexcept {
return sum_of_weights_ == rhs.sum_of_weights_ &&
sum_of_weights_squared_ == rhs.sum_of_weights_squared_;
}
template <typename T>
bool operator!=(const T& rhs) const noexcept {
return !operator==(rhs);
}
/// Return value of the sum.
const RealType& value() const noexcept { return sum_of_weights_; }
/// Return estimated variance of the sum.
const RealType& variance() const noexcept { return sum_of_weights_squared_; }
// lossy conversion must be explicit
template <class T>
explicit operator T() const {
return static_cast<T>(sum_of_weights_);
}
template <class Archive>
void serialize(Archive&, unsigned /* version */);
private:
RealType sum_of_weights_ = RealType();
RealType sum_of_weights_squared_ = RealType();
};
} // namespace accumulators
} // namespace histogram
} // namespace boost
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
namespace std {
template <class T, class U>
struct common_type<boost::histogram::accumulators::weighted_sum<T>,
boost::histogram::accumulators::weighted_sum<U>> {
using type = boost::histogram::accumulators::weighted_sum<common_type_t<T, U>>;
};
template <class T, class U>
struct common_type<boost::histogram::accumulators::weighted_sum<T>, U> {
using type = boost::histogram::accumulators::weighted_sum<common_type_t<T, U>>;
};
template <class T, class U>
struct common_type<T, boost::histogram::accumulators::weighted_sum<U>> {
using type = boost::histogram::accumulators::weighted_sum<common_type_t<T, U>>;
};
} // namespace std
#endif
#endif