Skip to content

Comments

[hist] Implement RBinIndexMultiRange#21322

Open
hahnjo wants to merge 6 commits intoroot-project:masterfrom
hahnjo:hist-multi-range
Open

[hist] Implement RBinIndexMultiRange#21322
hahnjo wants to merge 6 commits intoroot-project:masterfrom
hahnjo:hist-multi-range

Conversation

@hahnjo
Copy link
Member

@hahnjo hahnjo commented Feb 19, 2026

It allows convenient iteration over multiple RBinIndexRange, which will be used to implement future operations on histograms, such as projections, rebinning, slicing.

@hahnjo hahnjo self-assigned this Feb 19, 2026
@hahnjo hahnjo requested a review from bellenot as a code owner February 19, 2026 12:35
@hahnjo hahnjo added the in:Hist label Feb 19, 2026
@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Test Results

    22 files      22 suites   3d 11h 30m 0s ⏱️
 3 799 tests  3 793 ✅ 0 💤 6 ❌
75 514 runs  75 508 ✅ 0 💤 6 ❌

For more details on these failures, see this check.

Results for commit dc110c9.

♻️ This comment has been updated with latest results.

Comment on lines +83 to +85
for (; j < N; j++) {
// Reverse iteration order to advance the innermost index first.
const std::size_t i = N - 1 - j;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could consider:

for (; i > 0; i--) {

This might be easier to read.

Copy link
Member Author

@hahnjo hahnjo Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work unfortunately since the indices are (unsigned) std::size_t which is always >= 0 and wraps around...

Comment on lines 148 to 153
for (auto &&range : fRanges) {
it.fIterators.push_back(range.end());
// NB: We dereference and this is fine because we know the implementation of RBinIndexRange, in the worst case
// the returned RBinIndex will be invalid.
it.fIndices.push_back(*it.fIterators.back());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks expensive to construct. This may be fine, though, if it's used in range-based for loops.
It would not be fine in:

for (.  ; it < multiRange.end(); ++it) {

I don't know if that's supposed to be supported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I didn't consider this pattern. I noticed that RBinIndexMultiRange::RIterator is "expensive" to copy, but I concluded that not much can be done about it. For end() though we can "cheat" and always return the empty iterator, which should be ~cheap to construct without dynamic memory allocations. Dereferencing it doesn't return the "expected" result anymore (an empty fIndices), but that's not allowed by the C++ standard anyway.

TEST(RBinIndexMultiRange, Multi)
{
const auto index0 = RBinIndex(0);
const auto normal = CreateBinIndexRange(index0, RBinIndex(10), 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's internal, but it seems to go against the documentation, which states:

/// \param[in] begin the begin of the bin index range (inclusive)
/// \param[in] end the end of the bin index range (exclusive)
/// \param[in] nNormalBins the number of normal bins, after which iteration advances to RBinIndex::Overflow()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you are referring to nNormalBins = 0? For ranges from a normal begin to normal end, we never advance to the overflow bin, so it is ok to pass in 0. We do the same in RRegularAxis::GetNormalRange(), for example.

It allows convenient iteration over multiple RBinIndexRange, which
will be used to implement future operations on histograms, such as
projections, rebinning, slicing.
The implementation can be reused for a std::vector of RBinIndex.
Test iteration and summation over all bins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants