mirror of
https://github.com/boostorg/histogram.git
synced 2026-01-29 07:32:23 +00:00
nicer naming
This commit is contained in:
@@ -27,12 +27,12 @@ using static_axes = std::tuple<Ts...>;
|
||||
namespace {
|
||||
|
||||
template <typename StaticAxes, typename DynamicAxes>
|
||||
struct axes_equal_tuple_vecvar {
|
||||
struct axes_equal_static_dynamic_impl {
|
||||
bool& equal;
|
||||
const StaticAxes& t;
|
||||
const DynamicAxes& v;
|
||||
axes_equal_tuple_vecvar(bool& eq, const StaticAxes& tt,
|
||||
const DynamicAxes& vv)
|
||||
axes_equal_static_dynamic_impl(bool& eq, const StaticAxes& tt,
|
||||
const DynamicAxes& vv)
|
||||
: equal(eq), t(tt), v(vv) {}
|
||||
template <typename Int>
|
||||
void operator()(Int) const {
|
||||
@@ -42,11 +42,23 @@ struct axes_equal_tuple_vecvar {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
bool axes_equal_static_static_impl(mp11::mp_true, const static_axes<Ts...>& t,
|
||||
const static_axes<Ts...>& u) {
|
||||
return t == u;
|
||||
}
|
||||
|
||||
template <typename... Ts, typename... Us>
|
||||
bool axes_equal_static_static_impl(mp11::mp_false, const static_axes<Ts...>&,
|
||||
const static_axes<Us...>&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename StaticAxes, typename DynamicAxes>
|
||||
struct axes_assign_tuple_vecvar {
|
||||
struct axes_assign_static_dynamic_impl {
|
||||
StaticAxes& t;
|
||||
const DynamicAxes& v;
|
||||
axes_assign_tuple_vecvar(StaticAxes& tt, const DynamicAxes& vv)
|
||||
axes_assign_static_dynamic_impl(StaticAxes& tt, const DynamicAxes& vv)
|
||||
: t(tt), v(vv) {}
|
||||
template <typename Int>
|
||||
void operator()(Int) const {
|
||||
@@ -56,34 +68,21 @@ struct axes_assign_tuple_vecvar {
|
||||
};
|
||||
|
||||
template <typename DynamicAxes, typename StaticAxes>
|
||||
struct axes_assign_vecvar_tuple {
|
||||
struct axes_assign_dynamic_static_impl {
|
||||
DynamicAxes& v;
|
||||
const StaticAxes& t;
|
||||
axes_assign_vecvar_tuple(DynamicAxes& vv, const StaticAxes& tt)
|
||||
axes_assign_dynamic_static_impl(DynamicAxes& vv, const StaticAxes& tt)
|
||||
: v(vv), t(tt) {}
|
||||
template <typename Int>
|
||||
void operator()(Int) const {
|
||||
v[Int::value] = std::get<Int::value>(t);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
bool axes_equal_impl(mp11::mp_true, const static_axes<Ts...>& t,
|
||||
const static_axes<Ts...>& u) {
|
||||
return t == u;
|
||||
}
|
||||
|
||||
template <typename... Ts, typename... Us>
|
||||
bool axes_equal_impl(mp11::mp_false, const static_axes<Ts...>&,
|
||||
const static_axes<Us...>&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
template <typename... Ts, typename... Us>
|
||||
bool axes_equal(const static_axes<Ts...>& t, const static_axes<Us...>& u) {
|
||||
return axes_equal_impl(
|
||||
return axes_equal_static_static_impl(
|
||||
mp11::mp_same<mp11::mp_list<Ts...>, mp11::mp_list<Us...>>(), t, u);
|
||||
}
|
||||
|
||||
@@ -99,16 +98,17 @@ template <typename... Ts, typename... Us>
|
||||
bool axes_equal(const static_axes<Ts...>& t, const dynamic_axes<Us...>& u) {
|
||||
if (sizeof...(Ts) != u.size()) return false;
|
||||
bool equal = true;
|
||||
auto fn = axes_equal_tuple_vecvar<static_axes<Ts...>, dynamic_axes<Us...>>(
|
||||
equal, t, u);
|
||||
auto fn =
|
||||
axes_equal_static_dynamic_impl<static_axes<Ts...>, dynamic_axes<Us...>>(
|
||||
equal, t, u);
|
||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Ts)>>(fn);
|
||||
return equal;
|
||||
}
|
||||
|
||||
template <typename... Ts, typename... Us>
|
||||
void axes_assign(static_axes<Ts...>& t, const dynamic_axes<Us...>& u) {
|
||||
auto fn =
|
||||
axes_assign_tuple_vecvar<static_axes<Ts...>, dynamic_axes<Us...>>(t, u);
|
||||
auto fn = axes_assign_static_dynamic_impl<static_axes<Ts...>,
|
||||
dynamic_axes<Us...>>(t, u);
|
||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Ts)>>(fn);
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ bool axes_equal(const dynamic_axes<Ts...>& t, const static_axes<Us...>& u) {
|
||||
template <typename... Ts, typename... Us>
|
||||
void axes_assign(dynamic_axes<Ts...>& t, const static_axes<Us...>& u) {
|
||||
t.resize(sizeof...(Us));
|
||||
auto fn =
|
||||
axes_assign_vecvar_tuple<dynamic_axes<Ts...>, static_axes<Us...>>(t, u);
|
||||
auto fn = axes_assign_dynamic_static_impl<dynamic_axes<Ts...>,
|
||||
static_axes<Us...>>(t, u);
|
||||
mp11::mp_for_each<mp11::mp_iota_c<sizeof...(Us)>>(fn);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,16 @@ void axes_assign(dynamic_axes<Ts...>& t, const dynamic_axes<Us...>& u) {
|
||||
for (std::size_t i = 0; i < t.size(); ++i) { t[i] = u[i]; }
|
||||
}
|
||||
|
||||
struct field_count_visitor : public static_visitor<void> {
|
||||
struct shape_collector {
|
||||
std::vector<unsigned>::iterator iter;
|
||||
shape_collector(std::vector<unsigned>::iterator i) : iter(i) {}
|
||||
template <typename T>
|
||||
void operator()(const T& a) {
|
||||
*iter++ = a.shape();
|
||||
}
|
||||
};
|
||||
|
||||
struct field_counter {
|
||||
std::size_t value = 1;
|
||||
template <typename T>
|
||||
void operator()(const T& t) {
|
||||
@@ -148,25 +157,15 @@ struct field_count_visitor : public static_visitor<void> {
|
||||
};
|
||||
|
||||
template <typename Unary>
|
||||
struct unary_visitor : public static_visitor<void> {
|
||||
Unary& unary;
|
||||
unary_visitor(Unary& u) : unary(u) {}
|
||||
template <typename Axis>
|
||||
void operator()(const Axis& a) const {
|
||||
struct unary_adaptor_visitor : public static_visitor<void> {
|
||||
Unary&& unary;
|
||||
unary_adaptor_visitor(Unary&& u) : unary(std::forward<Unary>(u)) {}
|
||||
template <typename T>
|
||||
void operator()(const T& a) const {
|
||||
unary(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct shape_vector_visitor {
|
||||
std::vector<unsigned> shapes;
|
||||
std::vector<unsigned>::iterator iter;
|
||||
shape_vector_visitor(unsigned n) : shapes(n) { iter = shapes.begin(); }
|
||||
template <typename Axis>
|
||||
void operator()(const Axis& a) {
|
||||
*iter++ = a.shape();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace histogram
|
||||
} // namespace boost
|
||||
|
||||
@@ -230,7 +230,9 @@ public:
|
||||
template <typename Unary>
|
||||
void for_each_axis(Unary&& unary) const {
|
||||
for (const auto& a : axes_) {
|
||||
apply_visitor(detail::unary_visitor<Unary>(unary), a);
|
||||
apply_visitor(
|
||||
detail::unary_adaptor_visitor<Unary>(std::forward<Unary>(unary)),
|
||||
a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +271,7 @@ private:
|
||||
mutable detail::index_cache index_cache_;
|
||||
|
||||
std::size_t size_from_axes() const noexcept {
|
||||
detail::field_count_visitor v;
|
||||
detail::field_counter v;
|
||||
for_each_axis(v);
|
||||
return v.value;
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ private:
|
||||
mutable detail::index_cache index_cache_;
|
||||
|
||||
std::size_t size_from_axes() const noexcept {
|
||||
detail::field_count_visitor v;
|
||||
detail::field_counter v;
|
||||
for_each_axis(v);
|
||||
return v.value;
|
||||
}
|
||||
@@ -424,9 +424,9 @@ private:
|
||||
|
||||
template <typename H>
|
||||
void reduce_impl(H& h, const std::vector<bool>& b) const {
|
||||
detail::shape_vector_visitor v(dim());
|
||||
for_each_axis(v);
|
||||
detail::index_mapper m(v.shapes, b);
|
||||
std::vector<unsigned> shape(dim());
|
||||
for_each_axis(detail::shape_collector(shape.begin()));
|
||||
detail::index_mapper m(shape, b);
|
||||
do { h.storage_.add(m.second, storage_[m.first]); } while (m.next());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user