Skip to content

feat: sparse storage add/sub - #442

Open
henryiii wants to merge 2 commits into
boostorg:developfrom
henryiii:fix/sparse-storage-arithmetic
Open

feat: sparse storage add/sub#442
henryiii wants to merge 2 commits into
boostorg:developfrom
henryiii:fix/sparse-storage-arithmetic

Conversation

@henryiii

@henryiii henryiii commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This fixes #440. Closes #441 (could be rebased after that one, if you prefer). This keeps +=/-= from spiking memory on large sparse histograms.

I wasn't sure about protecting for types that don't have ==. Everything except /= and == is already protected, similar to the current code here, while /=/== don't have that protection (like #441), so they can't be used on types without == (but everything else works, including +=). The concept claims it requires ==. I stuck with protecting it, but can remove that if you'd prefer. I could also make /= work for == types (always insert) as a separate PR if you want parity.

Assisted-by: ClaudeCode:claude-fable-5

@HDembinski

Copy link
Copy Markdown
Collaborator

I am leaning towards calling this a feat instead of a fix, you are special-casing on node_access. I merged the other one, that was more straight forward.

Not sure whether the release manager will accept so many fixes in the beta phase. This is supposed to be the time for small fixes.

@HDembinski

Copy link
Copy Markdown
Collaborator

Please rebase.

henryiii added 2 commits July 30, 2026 09:45
operator+= and operator-= on a histogram with map-based storage
iterated the full logical index range, so adding two sparse histograms
touched every cell. Iterate only the stored nodes when the rhs storage
is map-based, via the new has_node_access trait.

operator/= keeps the full loop on purpose: dense semantics require
NaN cells where the divisor is zero.

Assisted-by: ClaudeCode:claude-fable-5
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Skip keys at or beyond the storage size in the sparse add/sub paths;
a corrupt serialization archive could otherwise cause an out-of-bounds
write on a dense left-hand side. Also correct the allocator baselines
in the new storage_adaptor tests to use the net counter.

Assisted-by: ClaudeCode:claude-fable-5
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii
henryiii force-pushed the fix/sparse-storage-arithmetic branch from 16051fc to 6d95349 Compare July 30, 2026 13:48
@henryiii

Copy link
Copy Markdown
Contributor Author

Since the other one didn't protect on == type, and it's merged, I'll drop that from this one too.

@henryiii henryiii changed the title fix: sparse storage add/sub feat: sparse storage add/sub Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sparse histogram operation improvements

2 participants