Skip to content

Commit

Permalink
Replace detail::span and detail::make_span with implementations in bo…
Browse files Browse the repository at this point in the history
…ost::core (#384)

* fix cmake build of benchmarks

* wip

* u

* u

* rename span.hpp to make_span.hpp

* missing file

* also replace make_span
  • Loading branch information
HDembinski authored Feb 19, 2023
1 parent 48ff00b commit 70b9830
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ tools/lcov-*
tools/codecov
coverage-report
.cache
venv
venv
5 changes: 2 additions & 3 deletions include/boost/histogram/detail/array_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef BOOST_HISTOGRAM_DETAIL_ARRAY_WRAPPER_HPP
#define BOOST_HISTOGRAM_DETAIL_ARRAY_WRAPPER_HPP

#include <boost/core/make_span.hpp>
#include <boost/core/nvp.hpp>
#include <boost/histogram/detail/span.hpp>
#include <boost/histogram/detail/static_if.hpp>
#include <boost/mp11/function.hpp>
#include <boost/mp11/utility.hpp>
Expand Down Expand Up @@ -48,8 +48,7 @@ struct array_wrapper {
ar);
},
[this](auto& ar) {
for (auto&& x : boost::histogram::detail::make_span(this->ptr, this->size))
ar& make_nvp("item", x);
for (auto&& x : make_span(this->ptr, this->size)) ar& make_nvp("item", x);
},
ar);
}
Expand Down
7 changes: 4 additions & 3 deletions include/boost/histogram/detail/fill_n.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define BOOST_HISTOGRAM_DETAIL_FILL_N_HPP

#include <algorithm>
#include <boost/core/make_span.hpp>
#include <boost/core/span.hpp>
#include <boost/histogram/axis/option.hpp>
#include <boost/histogram/axis/traits.hpp>
#include <boost/histogram/detail/axes.hpp>
Expand All @@ -16,7 +18,6 @@
#include <boost/histogram/detail/linearize.hpp>
#include <boost/histogram/detail/nonmember_container_access.hpp>
#include <boost/histogram/detail/optional_index.hpp>
#include <boost/histogram/detail/span.hpp>
#include <boost/histogram/detail/static_if.hpp>
#include <boost/histogram/fwd.hpp>
#include <boost/mp11/algorithm.hpp>
Expand Down Expand Up @@ -260,7 +261,7 @@ void fill_n_1(const std::size_t offset, S& storage, A& axes, const std::size_t v
}

template <class A, class T, std::size_t N>
std::size_t get_total_size(const A& axes, const dtl::span<const T, N>& values) {
std::size_t get_total_size(const A& axes, const span<const T, N>& values) {
// supported cases (T = value type; CT = containter of T; V<T, CT, ...> = variant):
// - span<CT, N>: for any histogram, N == rank
// - span<V<T, CT>, N>: for any histogram, N == rank
Expand Down Expand Up @@ -311,7 +312,7 @@ void fill_n_check_extra_args(std::size_t size, weight_type<T>&& w, Ts&&... ts) {

template <class S, class A, class T, std::size_t N, class... Us>
void fill_n(std::true_type, const std::size_t offset, S& storage, A& axes,
const dtl::span<const T, N> values, Us&&... us) {
const span<const T, N> values, Us&&... us) {
// supported cases (T = value type; CT = containter of T; V<T, CT, ...> = variant):
// - span<T, N>: only valid for 1D histogram, N > 1 allowed
// - span<CT, N>: for any histogram, N == rank
Expand Down
2 changes: 1 addition & 1 deletion include/boost/histogram/detail/reduce_command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef BOOST_HISTOGRAM_DETAIL_REDUCE_COMMAND_HPP
#define BOOST_HISTOGRAM_DETAIL_REDUCE_COMMAND_HPP

#include <boost/histogram/detail/span.hpp>
#include <boost/core/span.hpp>
#include <boost/histogram/fwd.hpp>
#include <boost/throw_exception.hpp>
#include <cassert>
Expand Down
250 changes: 0 additions & 250 deletions include/boost/histogram/detail/span.hpp

This file was deleted.

11 changes: 5 additions & 6 deletions include/boost/histogram/histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef BOOST_HISTOGRAM_HISTOGRAM_HPP
#define BOOST_HISTOGRAM_HISTOGRAM_HPP

#include <boost/core/make_span.hpp>
#include <boost/histogram/detail/accumulator_traits.hpp>
#include <boost/histogram/detail/argument_traits.hpp>
#include <boost/histogram/detail/axes.hpp>
Expand All @@ -16,7 +17,6 @@
#include <boost/histogram/detail/index_translator.hpp>
#include <boost/histogram/detail/mutex_base.hpp>
#include <boost/histogram/detail/nonmember_container_access.hpp>
#include <boost/histogram/detail/span.hpp>
#include <boost/histogram/detail/static_if.hpp>
#include <boost/histogram/fwd.hpp>
#include <boost/histogram/indexed.hpp>
Expand Down Expand Up @@ -239,7 +239,7 @@ class histogram : detail::mutex_base<Axes, Storage> {
"sample argument is missing but required by accumulator");
std::lock_guard<typename mutex_base::type> guard{mutex_base::get()};
detail::fill_n(mp11::mp_bool<(n_sample_args_expected == 0)>{}, offset_, storage_,
axes_, detail::make_span(args));
axes_, make_span(args));
}

/** Fill histogram with several values and weights at once.
Expand All @@ -257,8 +257,7 @@ class histogram : detail::mutex_base<Axes, Storage> {
std::is_convertible<std::tuple<>, typename acc_traits::args>::value;
std::lock_guard<typename mutex_base::type> guard{mutex_base::get()};
detail::fill_n(mp11::mp_bool<(weight_valid && sample_valid)>{}, offset_, storage_,
axes_, detail::make_span(args),
weight(detail::to_ptr_size(weights.value)));
axes_, make_span(args), weight(detail::to_ptr_size(weights.value)));
}

/** Fill histogram with several values and weights at once.
Expand Down Expand Up @@ -289,7 +288,7 @@ class histogram : detail::mutex_base<Axes, Storage> {
constexpr bool sample_valid =
std::is_convertible<sample_args_passed, typename acc_traits::args>::value;
detail::fill_n(mp11::mp_bool<(sample_valid)>{}, offset_, storage_, axes_,
detail::make_span(args), detail::to_ptr_size(sargs)...);
make_span(args), detail::to_ptr_size(sargs)...);
},
samples.value);
}
Expand Down Expand Up @@ -321,7 +320,7 @@ class histogram : detail::mutex_base<Axes, Storage> {
constexpr bool sample_valid =
std::is_convertible<sample_args_passed, typename acc_traits::args>::value;
detail::fill_n(mp11::mp_bool<(weight_valid && sample_valid)>{}, offset_,
storage_, axes_, detail::make_span(args),
storage_, axes_, make_span(args),
weight(detail::to_ptr_size(weights.value)),
detail::to_ptr_size(sargs)...);
},
Expand Down
3 changes: 2 additions & 1 deletion test/detail_array_wrapper_serialization_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/make_span.hpp>
#include <boost/histogram/detail/array_wrapper.hpp>
#include <sstream>
#include <vector>
Expand All @@ -24,7 +25,7 @@ struct dummy_array_wrapper {
std::size_t size;
template <class Archive>
void serialize(Archive& ar, unsigned /* version */) {
for (auto&& x : dtl::make_span(ptr, size)) ar& x;
for (auto&& x : boost::make_span(ptr, size)) ar& x;
}
};

Expand Down
Loading

0 comments on commit 70b9830

Please sign in to comment.