Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions include/boost/histogram/algorithm/reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ Histogram reduce(const Histogram& hist, const Iterable& options) {
auto result =
Histogram(std::move(axes), detail::make_default(unsafe_access::storage(hist)));

for (auto& o : opts)
o.reduced_end = (o.end.index - o.begin.index) / static_cast<index_type>(o.merge);

auto idx = detail::make_stack_buffer<index_type>(unsafe_access::axes(result));
for (auto&& x : indexed(hist, coverage::all)) {
auto i = idx.begin();
Expand All @@ -417,14 +420,12 @@ Histogram reduce(const Histogram& hist, const Iterable& options) {
*i = -1;
if (!o->use_underflow_bin) skip = true;
} else {
if (*i >= 0)
if (*i < 0)
*i = o->reduced_end;
else if (o->merge > 1)
*i /= static_cast<index_type>(o->merge);
else
*i = o->end.index;
const auto reduced_axis_end =
(o->end.index - o->begin.index) / static_cast<index_type>(o->merge);
if (*i >= reduced_axis_end) {
*i = reduced_axis_end;
if (*i >= o->reduced_end) {
*i = o->reduced_end;
if (!o->use_overflow_bin) skip = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions include/boost/histogram/detail/reduce_command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct reduce_command {
unsigned merge = 0; // default value indicates unset option
bool crop = false;
// for internal use by the reduce algorithm
axis::index_type reduced_end = 0; // (end - begin) / merge
bool is_ordered = true;
bool use_underflow_bin = true;
bool use_overflow_bin = true;
Expand Down
Loading