48 using array_type = boost::multi_array<T, M + 1>;
49 using count_type = boost::multi_array<std::size_t, M + 1>;
62 std::array<std::pair<U, U>, M> limits)
101 void update(std::span<const U> pos, std::span<const T> value) {
102 if (pos.size() != M) {
103 throw std::invalid_argument(
"Wrong dimensions for the coordinates");
105 if (value.size() != N) {
106 throw std::invalid_argument(
"Wrong dimensions for the value");
108 if (check_limits(pos)) {
109 auto index = calc_bin_index(pos);
110 for (std::size_t i = 0; i < N; ++i) {
120 auto const bin_volume = std::accumulate(
122 std::ranges::transform(
124 [bin_volume](T v) { return static_cast<T>(v / bin_volume); });
132 auto calc_bin_index(std::span<const U>
const &pos)
const {
133 boost::array<array_index, M + 1> index;
134 for (std::size_t i = 0; i < M; ++i) {
135 auto const offset =
m_limits[i].first;
137 auto const n_bins =
static_cast<long>(
m_n_bins[i]);
138 auto const bin =
static_cast<long>(std::floor((pos[i] - offset) / size));
142 index[i] =
static_cast<array_index>(std::clamp(bin, 0l, n_bins - 1l));
150 std::array<U, M> calc_bin_sizes()
const {
151 std::array<U, M> bin_sizes;
152 for (std::size_t i = 0; i < M; ++i) {
163 bool check_limits(std::span<const U>
const &pos)
const {
164 assert(pos.size() == M);
166 return std::ranges::all_of(pos, [&it_limits](U
const value) {
167 auto const [lower, upper] = *it_limits;
169 return value >= lower and value < upper;
173 std::array<std::size_t, M + 1> m_array_dim()
const {
174 std::array<std::size_t, M + 1> dimensions;
175 std::ranges::copy(
m_n_bins, dimensions.begin());
176 dimensions.back() = N;