Skip to content

fix: support sparse storage with accumulators - #421

Merged
HDembinski merged 1 commit into
boostorg:developfrom
henryiii:henryiii/fix/416
Mar 26, 2026
Merged

HDembinski merged 1 commit into
boostorg:developfrom
henryiii:henryiii/fix/416

Conversation

@henryiii

Copy link
Copy Markdown
Contributor

This is a fix for #416. Added test fails without the fix, compiles and passes with the fix. This was blocking sparse storage in boost-histogram (can't promise it is the only blocker, but was the first one we hit).

Use copilot in VSCode, which selected GPT-5.3-Codex, to convert the issue into a fix and test.

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii

henryiii commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor Author

C++17 version, FWIW:

auto [it, _] = map->try_emplace(idx, value_type{});
it->second += u;

@HDembinski
HDembinski merged commit 40add38 into boostorg:develop Mar 26, 2026
9 checks passed
@HDembinski

Copy link
Copy Markdown
Collaborator

Looks good, thanks.

@henryiii
henryiii deleted the henryiii/fix/416 branch March 26, 2026 20:56
@henryiii

Copy link
Copy Markdown
Contributor Author

Will this make it into 1.91? The deadline for fixes is April 1. (Doesn't have to)

@HDembinski

Copy link
Copy Markdown
Collaborator

Yeah, I think I can merge it into the release, because it is a bug-fix.

henryiii added a commit to henryiii/boost-histogram that referenced this pull request Jun 15, 2026
Add a hash-map backed `DoubleSparse` storage that only allocates filled
cells, making histograms over very large or high-dimensional axis spaces
feasible. Backed by `storage_adaptor<unordered_map<size_t, double>>`.

Scoped to `double` only for now: accumulator-backed sparse storages need
boostorg/histogram#421, which ships in Boost 1.92 (the repo vendors 1.90).

Data access is COO-first and deliberately not a full drop-in:
- `.view()` raises (no contiguous buffer to view into).
- `Histogram.to_coo(flow=False)` returns the filled cells as
  `(per-axis index tuple, values)`, numpy-nonzero style.
- The copying accessors `values()`/`variances()`/`counts()` and
  `np.asarray(h)` densify into a fresh array, so they keep working.
- `at()` reads, slicing, projection, sum and histogram addition stay sparse.

Serialization: pickle round-trips via free save/load on `double_sparse`
(COO key/value arrays); UHI to_uhi/from_uhi store COO under a `"sparse"`
payload plus writer_info, reconstructed via a C++ `_from_coo` bulk setter.

Assisted-by: ClaudeCode:claude-opus-4.8
@henryiii

henryiii commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@HDembinski Will this make it into 1.92? The deadline for all changes is August 5.

(I've got a few other fixes open too, and I can submit a fix for #430 if you want me to).

@HDembinski

Copy link
Copy Markdown
Collaborator

yeah let's aim for that

@henryiii

henryiii commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@HDembinski Will this make it into 1.93? The deadline for new libraries is October 21, and breaking changes is October 28, and all changes is November 4. I assume it's easier before those deadlines to update.

(I've got a few open PRs too, #429 should be ready for review).

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.

2 participants