mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-09 23:04:07 +00:00
fix
This commit is contained in:
parent
16ccde46ee
commit
a2cb137b93
@ -7,15 +7,14 @@ AlignConsecutiveDeclarations: false
|
|||||||
AlignEscapedNewlinesLeft: true
|
AlignEscapedNewlinesLeft: true
|
||||||
AlignOperands: true
|
AlignOperands: true
|
||||||
AlignTrailingComments: true
|
AlignTrailingComments: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: true
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortBlocksOnASingleLine: true
|
AllowShortBlocksOnASingleLine: true
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: true
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
AllowShortLoopsOnASingleLine: true
|
AllowShortLoopsOnASingleLine: true
|
||||||
AlwaysBreakAfterDefinitionReturnType: None
|
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: true
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
AlwaysBreakTemplateDeclarations: true
|
AlwaysBreakTemplateDeclarations: true
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
//[ guide_fill_histogram
|
//[ guide_fill_histogram
|
||||||
|
|
||||||
#include <boost/histogram.hpp>
|
#include <boost/histogram.hpp>
|
||||||
@ -10,8 +11,8 @@
|
|||||||
namespace bh = boost::histogram;
|
namespace bh = boost::histogram;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto h =
|
auto h = bh::make_histogram(bh::axis::regular<>(8, 0, 4),
|
||||||
bh::make_histogram(bh::axis::regular<>(8, 0, 4), bh::axis::regular<>(10, 0, 5));
|
bh::axis::regular<>(10, 0, 5));
|
||||||
|
|
||||||
// fill histogram, number of arguments must be equal to number of axes
|
// fill histogram, number of arguments must be equal to number of axes
|
||||||
h(0, 1.1); // increases bin counter by one
|
h(0, 1.1); // increases bin counter by one
|
||||||
@ -30,8 +31,9 @@ int main() {
|
|||||||
|
|
||||||
// std::for_each takes the functor by value, we use a reference wrapper
|
// std::for_each takes the functor by value, we use a reference wrapper
|
||||||
// here to avoid costly copies
|
// here to avoid costly copies
|
||||||
auto h2 =
|
auto h2 = bh::make_histogram(bh::axis::regular<>(8, 0, 4),
|
||||||
bh::make_histogram(bh::axis::regular<>(8, 0, 4), bh::axis::regular<>(10, 0, 5));
|
bh::axis::regular<>(10, 0, 5));
|
||||||
|
|
||||||
std::for_each(input_data.begin(), input_data.end(), std::ref(h2));
|
std::for_each(input_data.begin(), input_data.end(), std::ref(h2));
|
||||||
|
|
||||||
// h2 is filled
|
// h2 is filled
|
||||||
|
@ -24,86 +24,6 @@ namespace boost {
|
|||||||
namespace histogram {
|
namespace histogram {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename... Ts, typename... Us>
|
|
||||||
bool axes_equal(const std::tuple<Ts...>& t, const std::tuple<Us...>& u) {
|
|
||||||
return static_if<std::is_same<mp11::mp_list<Ts...>, mp11::mp_list<Us...>>>(
|
|
||||||
[](const auto& a, const auto& b) { return a == b; },
|
|
||||||
[](const auto&, const auto&) { return false; }, t, u);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts, typename U>
|
|
||||||
bool axes_equal(const std::tuple<Ts...>& t, const U& u) {
|
|
||||||
if (sizeof...(Ts) != u.size()) return false;
|
|
||||||
bool equal = true;
|
|
||||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Ts)>>([&](auto I) {
|
|
||||||
using T = mp11::mp_at<std::tuple<Ts...>, decltype(I)>;
|
|
||||||
auto up = axis::get<T>(&u[I]);
|
|
||||||
equal &= (up && std::get<I>(t) == *up);
|
|
||||||
});
|
|
||||||
return equal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename... Us>
|
|
||||||
bool axes_equal(const T& t, const std::tuple<Us...>& u) {
|
|
||||||
return axes_equal(u, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
bool axes_equal(const T& t, const U& u) {
|
|
||||||
if (t.size() != u.size()) return false;
|
|
||||||
return std::equal(t.begin(), t.end(), u.begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
void axes_assign(std::tuple<Ts...>& t, const std::tuple<Ts...>& u) {
|
|
||||||
t = u;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts, typename... Us>
|
|
||||||
void axes_assign(std::tuple<Ts...>&, const std::tuple<Us...>&) {
|
|
||||||
throw std::invalid_argument("cannot assign axes if types do not match");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts, typename U>
|
|
||||||
void axes_assign(std::tuple<Ts...>& t, const U& u) {
|
|
||||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Ts)>>([&](auto I) {
|
|
||||||
using T = mp11::mp_at_c<std::tuple<Ts...>, I>;
|
|
||||||
std::get<I>(t) = axis::get<T>(u[I]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename... Us>
|
|
||||||
void axes_assign(T& t, const std::tuple<Us...>& u) {
|
|
||||||
t.resize(sizeof...(Us));
|
|
||||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Us)>>(
|
|
||||||
[&](auto I) { t[I] = std::get<I>(u); });
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
void axes_assign(T& t, const U& u) {
|
|
||||||
t.assign(u.begin(), u.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
constexpr std::size_t axes_size(const std::tuple<Ts...>&) {
|
|
||||||
return sizeof...(Ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::size_t axes_size(const T& axes) {
|
|
||||||
return axes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <int N, typename... Ts>
|
|
||||||
void range_check(const std::tuple<Ts...>&) {
|
|
||||||
static_assert(N < sizeof...(Ts), "index out of range");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <int N, typename T>
|
|
||||||
void range_check(const T& axes) {
|
|
||||||
BOOST_ASSERT_MSG(N < axes.size(), "index out of range");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <int N, typename... Ts>
|
template <int N, typename... Ts>
|
||||||
decltype(auto) axis_get(std::tuple<Ts...>& axes) {
|
decltype(auto) axis_get(std::tuple<Ts...>& axes) {
|
||||||
return std::get<N>(axes);
|
return std::get<N>(axes);
|
||||||
@ -146,6 +66,86 @@ decltype(auto) axis_get(const T& axes, std::size_t i) {
|
|||||||
return axes.at(i);
|
return axes.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Ts, typename... Us>
|
||||||
|
bool axes_equal(const std::tuple<Ts...>& t, const std::tuple<Us...>& u) {
|
||||||
|
return static_if<std::is_same<mp11::mp_list<Ts...>, mp11::mp_list<Us...>>>(
|
||||||
|
[](const auto& a, const auto& b) { return a == b; },
|
||||||
|
[](const auto&, const auto&) { return false; }, t, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Ts, typename U>
|
||||||
|
bool axes_equal(const std::tuple<Ts...>& t, const U& u) {
|
||||||
|
if (sizeof...(Ts) != u.size()) return false;
|
||||||
|
bool equal = true;
|
||||||
|
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Ts)>>([&](auto I) {
|
||||||
|
using T = mp11::mp_at<std::tuple<Ts...>, decltype(I)>;
|
||||||
|
auto up = axis::get<T>(&u[I]);
|
||||||
|
equal &= (up && std::get<I>(t) == *up);
|
||||||
|
});
|
||||||
|
return equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename... Us>
|
||||||
|
bool axes_equal(const T& t, const std::tuple<Us...>& u) {
|
||||||
|
return axes_equal(u, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename U>
|
||||||
|
bool axes_equal(const T& t, const U& u) {
|
||||||
|
if (t.size() != u.size()) return false;
|
||||||
|
return std::equal(t.begin(), t.end(), u.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Ts, typename... Us>
|
||||||
|
void axes_assign(std::tuple<Ts...>& t, const std::tuple<Us...>& u) {
|
||||||
|
static_if<std::is_same<mp11::mp_list<Ts...>, mp11::mp_list<Us...>>>(
|
||||||
|
[](auto& a, const auto& b) { a = b; },
|
||||||
|
[](auto&, const auto&) {
|
||||||
|
throw std::invalid_argument("cannot assign axes, types do not match");
|
||||||
|
},
|
||||||
|
t, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Ts, typename U>
|
||||||
|
void axes_assign(std::tuple<Ts...>& t, const U& u) {
|
||||||
|
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Ts)>>([&](auto I) {
|
||||||
|
using T = mp11::mp_at_c<std::tuple<Ts...>, I>;
|
||||||
|
std::get<I>(t) = axis::get<T>(u[I]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename... Us>
|
||||||
|
void axes_assign(T& t, const std::tuple<Us...>& u) {
|
||||||
|
t.resize(sizeof...(Us));
|
||||||
|
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Us)>>(
|
||||||
|
[&](auto I) { t[I] = std::get<I>(u); });
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename U>
|
||||||
|
void axes_assign(T& t, const U& u) {
|
||||||
|
t.assign(u.begin(), u.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
constexpr std::size_t axes_size(const std::tuple<Ts...>&) {
|
||||||
|
return sizeof...(Ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::size_t axes_size(const T& axes) {
|
||||||
|
return axes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int N, typename... Ts>
|
||||||
|
void range_check(const std::tuple<Ts...>&) {
|
||||||
|
static_assert(N < sizeof...(Ts), "index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int N, typename T>
|
||||||
|
void range_check(const T& axes) {
|
||||||
|
BOOST_ASSERT_MSG(N < axes.size(), "index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
template <typename F, typename... Ts>
|
template <typename F, typename... Ts>
|
||||||
void for_each_axis(const std::tuple<Ts...>& axes, F&& f) {
|
void for_each_axis(const std::tuple<Ts...>& axes, F&& f) {
|
||||||
mp11::tuple_for_each(axes, std::forward<F>(f));
|
mp11::tuple_for_each(axes, std::forward<F>(f));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user