update boost on linux
This commit is contained in:
98
linx64/include/boost/histogram/algorithm/project.hpp
Normal file
98
linx64/include/boost/histogram/algorithm/project.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
// 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_ALGORITHM_PROJECT_HPP
|
||||
#define BOOST_HISTOGRAM_ALGORITHM_PROJECT_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/histogram/detail/meta.hpp>
|
||||
#include <boost/histogram/histogram.hpp>
|
||||
#include <boost/histogram/indexed.hpp>
|
||||
#include <boost/histogram/unsafe_access.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/set.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace histogram {
|
||||
namespace algorithm {
|
||||
|
||||
/**
|
||||
Returns a lower-dimensional histogram, summing over removed axes.
|
||||
|
||||
Arguments are the source histogram and compile-time numbers, the remaining indices of
|
||||
the axes. Returns a new histogram which only contains the subset of axes. The source
|
||||
histogram is summed over the removed axes.
|
||||
*/
|
||||
template <class A, class S, unsigned N, typename... Ns>
|
||||
auto project(const histogram<A, S>& h, std::integral_constant<unsigned, N>, Ns...) {
|
||||
using LN = mp11::mp_list<std::integral_constant<unsigned, N>, Ns...>;
|
||||
static_assert(mp11::mp_is_set<LN>::value, "indices must be unique");
|
||||
|
||||
const auto& old_axes = unsafe_access::axes(h);
|
||||
auto axes = detail::static_if<detail::is_tuple<A>>(
|
||||
[&](const auto& old_axes) {
|
||||
return std::make_tuple(std::get<N>(old_axes), std::get<Ns::value>(old_axes)...);
|
||||
},
|
||||
[&](const auto& old_axes) {
|
||||
return detail::remove_cvref_t<decltype(old_axes)>(
|
||||
{old_axes[N], old_axes[Ns::value]...});
|
||||
},
|
||||
old_axes);
|
||||
|
||||
const auto& old_storage = unsafe_access::storage(h);
|
||||
using A2 = decltype(axes);
|
||||
auto result = histogram<A2, S>(std::move(axes), detail::make_default(old_storage));
|
||||
auto idx = detail::make_stack_buffer<int>(unsafe_access::axes(result));
|
||||
for (auto x : indexed(h, coverage::all)) {
|
||||
auto i = idx.begin();
|
||||
mp11::mp_for_each<LN>([&i, &x](auto J) { *i++ = x.index(J); });
|
||||
result.at(idx) += *x;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a lower-dimensional histogram, summing over removed axes.
|
||||
|
||||
This version accepts a source histogram and an iterable range containing the remaining
|
||||
indices.
|
||||
*/
|
||||
template <class A, class S, class Iterable, class = detail::requires_iterable<Iterable>>
|
||||
auto project(const histogram<A, S>& h, const Iterable& c) {
|
||||
static_assert(detail::is_sequence_of_any_axis<A>::value,
|
||||
"this version of project requires histogram with non-static axes");
|
||||
|
||||
const auto& old_axes = unsafe_access::axes(h);
|
||||
auto axes = detail::make_default(old_axes);
|
||||
axes.reserve(c.size());
|
||||
auto seen = detail::make_stack_buffer<bool>(old_axes, false);
|
||||
for (auto d : c) {
|
||||
if (seen[d]) BOOST_THROW_EXCEPTION(std::invalid_argument("indices must be unique"));
|
||||
seen[d] = true;
|
||||
axes.emplace_back(old_axes[d]);
|
||||
}
|
||||
|
||||
const auto& old_storage = unsafe_access::storage(h);
|
||||
auto result = histogram<A, S>(std::move(axes), detail::make_default(old_storage));
|
||||
auto idx = detail::make_stack_buffer<int>(unsafe_access::axes(result));
|
||||
for (auto x : indexed(h, coverage::all)) {
|
||||
auto i = idx.begin();
|
||||
for (auto d : c) *i++ = x.index(d);
|
||||
result.at(idx) += *x;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
} // namespace histogram
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
222
linx64/include/boost/histogram/algorithm/reduce.hpp
Normal file
222
linx64/include/boost/histogram/algorithm/reduce.hpp
Normal file
@@ -0,0 +1,222 @@
|
||||
// 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_ALGORITHM_REDUCE_HPP
|
||||
#define BOOST_HISTOGRAM_ALGORITHM_REDUCE_HPP
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/histogram/detail/axes.hpp>
|
||||
#include <boost/histogram/detail/meta.hpp>
|
||||
#include <boost/histogram/fwd.hpp>
|
||||
#include <boost/histogram/indexed.hpp>
|
||||
#include <boost/histogram/unsafe_access.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace histogram {
|
||||
namespace algorithm {
|
||||
|
||||
/**
|
||||
Option type returned by the helper functions shrink_and_rebin(), shrink(), rebin().
|
||||
*/
|
||||
struct reduce_option {
|
||||
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
|
||||
unsigned iaxis = 0;
|
||||
double lower, upper;
|
||||
unsigned merge = 0;
|
||||
|
||||
reduce_option() noexcept = default;
|
||||
|
||||
reduce_option(unsigned i, double l, double u, unsigned m)
|
||||
: iaxis(i), lower(l), upper(u), merge(m) {
|
||||
if (lower == upper)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("lower != upper required"));
|
||||
if (merge == 0) BOOST_THROW_EXCEPTION(std::invalid_argument("merge > 0 required"));
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
Shrink and rebin option.
|
||||
|
||||
@param iaxis which axis to operate on.
|
||||
@param lower lowest bound that should be kept.
|
||||
@param upper highest bound that should be kept. If upper is inside bin interval, the
|
||||
whole interval is removed.
|
||||
@param merge how many adjacent bins to merge into one.
|
||||
*/
|
||||
inline auto shrink_and_rebin(unsigned iaxis, double lower, double upper, unsigned merge) {
|
||||
return reduce_option{iaxis, lower, upper, merge};
|
||||
}
|
||||
|
||||
/**
|
||||
Shrink option.
|
||||
|
||||
@param iaxis which axis to operate on.
|
||||
@param lower lowest bound that should be kept.
|
||||
@param upper highest bound that should be kept. If upper is inside bin interval, the
|
||||
whole interval is removed.
|
||||
*/
|
||||
inline auto shrink(unsigned iaxis, double lower, double upper) {
|
||||
return reduce_option{iaxis, lower, upper, 1};
|
||||
}
|
||||
|
||||
/**
|
||||
Rebin option.
|
||||
|
||||
@param iaxis which axis to operate on.
|
||||
@param merge how many adjacent bins to merge into one.
|
||||
*/
|
||||
inline auto rebin(unsigned iaxis, unsigned merge) {
|
||||
return reduce_option{iaxis, std::numeric_limits<double>::quiet_NaN(),
|
||||
std::numeric_limits<double>::quiet_NaN(), merge};
|
||||
}
|
||||
|
||||
/**
|
||||
Convenience overload for single axis.
|
||||
|
||||
@param lower lowest bound that should be kept.
|
||||
@param upper highest bound that should be kept. If upper is inside bin interval, the
|
||||
whole interval is removed.
|
||||
@param merge how many adjacent bins to merge into one.
|
||||
*/
|
||||
inline auto shrink_and_rebin(double lower, double upper, unsigned merge) {
|
||||
return shrink_and_rebin(0, lower, upper, merge);
|
||||
}
|
||||
|
||||
/**
|
||||
Convenience overload for single axis.
|
||||
|
||||
@param lower lowest bound that should be kept.
|
||||
@param upper highest bound that should be kept. If upper is inside bin interval, the
|
||||
whole interval is removed.
|
||||
*/
|
||||
inline auto shrink(double lower, double upper) { return shrink(0, lower, upper); }
|
||||
|
||||
/**
|
||||
Convenience overload for single axis.
|
||||
|
||||
@param merge how many adjacent bins to merge into one.
|
||||
*/
|
||||
inline auto rebin(unsigned merge) { return rebin(0, merge); }
|
||||
|
||||
/**
|
||||
Shrink and/or rebin axes of a histogram.
|
||||
|
||||
Returns the reduced copy of the histogram.
|
||||
|
||||
@param hist original histogram.
|
||||
@param options iterable sequence of reduce_options, generated by shrink_and_rebin(),
|
||||
shrink(), and rebin().
|
||||
*/
|
||||
#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
|
||||
template <class Histogram, class Iterable, class = detail::requires_iterable<Iterable>>
|
||||
#else
|
||||
template <class Histogram, class Iterable>
|
||||
#endif
|
||||
decltype(auto) reduce(const Histogram& hist, const Iterable& options) {
|
||||
const auto& old_axes = unsafe_access::axes(hist);
|
||||
|
||||
struct option_item : reduce_option {
|
||||
int begin, end;
|
||||
};
|
||||
|
||||
auto opts = detail::make_stack_buffer<option_item>(old_axes);
|
||||
for (const auto& o : options) {
|
||||
auto& oi = opts[o.iaxis];
|
||||
if (oi.merge > 0) // did we already set the option for this axis?
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("indices must be unique"));
|
||||
oi.lower = o.lower;
|
||||
oi.upper = o.upper;
|
||||
oi.merge = o.merge;
|
||||
}
|
||||
|
||||
// make new axes container with default-constructed axis instances
|
||||
auto axes = detail::make_default(old_axes);
|
||||
detail::static_if<detail::is_tuple<decltype(axes)>>(
|
||||
[](auto&, const auto&) {},
|
||||
[](auto& axes, const auto& old_axes) {
|
||||
axes.reserve(old_axes.size());
|
||||
for (const auto& a : old_axes) axes.emplace_back(detail::make_default(a));
|
||||
},
|
||||
axes, old_axes);
|
||||
|
||||
// override default-constructed axis instances with modified instances
|
||||
unsigned iaxis = 0;
|
||||
hist.for_each_axis([&](const auto& a) {
|
||||
using T = detail::remove_cvref_t<decltype(a)>;
|
||||
|
||||
auto& o = opts[iaxis];
|
||||
o.begin = 0;
|
||||
o.end = a.size();
|
||||
if (o.merge > 0) { // option is set?
|
||||
if (o.lower < o.upper) {
|
||||
while (o.begin != o.end && a.value(o.begin) < o.lower) ++o.begin;
|
||||
while (o.end != o.begin && a.value(o.end - 1) >= o.upper) --o.end;
|
||||
} else if (o.lower > o.upper) {
|
||||
// for inverted axis::regular
|
||||
while (o.begin != o.end && a.value(o.begin) > o.lower) ++o.begin;
|
||||
while (o.end != o.begin && a.value(o.end - 1) <= o.upper) --o.end;
|
||||
}
|
||||
o.end -= (o.end - o.begin) % o.merge;
|
||||
auto a2 = T(a, o.begin, o.end, o.merge);
|
||||
axis::get<T>(detail::axis_get(axes, iaxis)) = a2;
|
||||
} else {
|
||||
o.merge = 1;
|
||||
axis::get<T>(detail::axis_get(axes, iaxis)) = a;
|
||||
}
|
||||
++iaxis;
|
||||
});
|
||||
|
||||
auto storage = detail::make_default(unsafe_access::storage(hist));
|
||||
auto result = Histogram(std::move(axes), std::move(storage));
|
||||
|
||||
auto idx = detail::make_stack_buffer<int>(unsafe_access::axes(result));
|
||||
for (auto x : indexed(hist, coverage::all)) {
|
||||
auto i = idx.begin();
|
||||
auto o = opts.begin();
|
||||
for (auto j : x.indices()) {
|
||||
*i = (j - o->begin);
|
||||
if (*i <= -1)
|
||||
*i = -1;
|
||||
else {
|
||||
*i /= o->merge;
|
||||
const int end = (o->end - o->begin) / o->merge;
|
||||
if (*i > end) *i = end;
|
||||
}
|
||||
++i;
|
||||
++o;
|
||||
}
|
||||
result.at(idx) += *x;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
Shrink and/or rebin axes of a histogram.
|
||||
|
||||
Returns the modified copy.
|
||||
|
||||
@param hist original histogram.
|
||||
@param opt reduce option generated by shrink_and_rebin(), shrink(), and rebin().
|
||||
@param opts more reduce_options.
|
||||
*/
|
||||
template <class Histogram, class... Ts>
|
||||
decltype(auto) reduce(const Histogram& hist, const reduce_option& opt, Ts&&... opts) {
|
||||
// this must be in one line, because any of the ts could be a temporary
|
||||
return reduce(hist, std::initializer_list<reduce_option>{opt, opts...});
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
} // namespace histogram
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
41
linx64/include/boost/histogram/algorithm/sum.hpp
Normal file
41
linx64/include/boost/histogram/algorithm/sum.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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_ALGORITHM_SUM_HPP
|
||||
#define BOOST_HISTOGRAM_ALGORITHM_SUM_HPP
|
||||
|
||||
#include <boost/histogram/accumulators/sum.hpp>
|
||||
#include <boost/histogram/fwd.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <numeric>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace histogram {
|
||||
namespace algorithm {
|
||||
/** Compute the sum over all histogram cells, including underflow/overflow bins.
|
||||
|
||||
If the value type of the histogram is an integral or floating point type,
|
||||
boost::accumulators::sum<double> is used to compute the sum, else the original value
|
||||
type is used. Compilation fails, if the value type does not support operator+=.
|
||||
|
||||
Return type is double if the value type of the histogram is integral or floating point,
|
||||
and the original value type otherwise.
|
||||
*/
|
||||
template <class A, class S>
|
||||
auto sum(const histogram<A, S>& h) {
|
||||
using T = typename histogram<A, S>::value_type;
|
||||
using Sum = mp11::mp_if<std::is_arithmetic<T>, accumulators::sum<double>, T>;
|
||||
Sum sum;
|
||||
for (auto x : h) sum += x;
|
||||
using R = mp11::mp_if<std::is_arithmetic<T>, double, T>;
|
||||
return static_cast<R>(sum);
|
||||
}
|
||||
} // namespace algorithm
|
||||
} // namespace histogram
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user