fix: MultiCell loses contents when a growing axis resizes storage#1159
Draft
NJManganelli wants to merge 1 commit into
Draft
fix: MultiCell loses contents when a growing axis resizes storage#1159NJManganelli wants to merge 1 commit into
NJManganelli wants to merge 1 commit into
Conversation
NJManganelli
marked this pull request as draft
July 14, 2026 21:43
multi_cell_reference is a proxy reference whose element-wise assignment was only provided as a template operator=. A templated assignment operator never suppresses the implicitly declared copy-assignment operator, so for `ref = ref` (both multi_cell_reference), the compiler-generated copy assignment won overload resolution and merely rebound the span instead of writing through to the referenced cells. boost::histogram relocates cells with `*new = *old` in detail::storage_grower::apply when a growing axis enlarges the storage, so every growth silently zeroed all previously filled contents. Filling a MultiCell histogram that has a growth axis (e.g. StrCategory) therefore lost data whenever a new category appeared, unless all categories were declared up front. Provide an explicit write-through copy-assignment operator (and default the copy constructor to keep proxy rebind-on-copy semantics). Add a regression test that fills a growing MultiCell histogram category by category and checks it matches the pre-declared-categories result. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
NJManganelli
force-pushed
the
fix_multicell_growth
branch
from
July 15, 2026 06:15
59904eb to
8aaa032
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Filling a
MultiCellhistogram that has a growing axis (e.g.StrCategory(growth=True))silently zeroes everything filled before the axis grows. Any category that appears
after the first fill triggers a storage resize, and all previously accumulated cells
are lost. The only workaround today is to declare every category up front.
Cause
multi_cell_referenceis a proxy reference (aspanover a cell's elements). Itselement-wise assignment is provided only as a template
operator=. A templatedassignment operator does not suppress the implicitly-declared copy-assignment
operator, so when both sides have the same type —
multi_cell_reference = multi_cell_reference—overload resolution prefers the compiler-generated copy-assignment, which just rebinds
the span instead of writing through to the referenced cells.
boost::histogram relocates cells with
*new = *oldindetail::storage_grower::applywhen a growing axis enlarges the storage. With therebinding assignment the relocation is a no-op, so every growth discards the existing
contents. (Confirmed by reproducing against pristine boost::histogram
develop: thecell-relocation offsets are computed correctly, but
*ns = xnever copies.)Fix
Provide an explicit write-through copy-assignment operator for
multi_cell_reference,and default the copy constructor to keep proxy rebind-on-copy semantics. This is the
same contract every other boost::histogram storage reference already honours.
Adds a regression test that fills a growing
MultiCellhistogram category by categoryand checks it matches the pre-declared-categories result. Full test suite passes; clean
under
-Wall -Wextraand clang-format.Follow-up to #1008 (MultiCell storage).
🤖 Investigated and drafted with Claude Code; reviewed by @NJManganelli.