Repository navigation
Conversation
Replace the recursive enumeration in `to_manhattan_index` and `manhattan_to_multidimensional_index` by an inclusion-exclusion count of the points below a given Manhattan distance, together with a binary search for the inverse mapping. This makes both mappings O(N 2^N) instead of growing polynomially with the distance, which speeds up `findindex` and `getindex` for `values(::ProductSector)`, and with it `isless` for sectors such as SU(N) irreps whose `findindex` relies on these functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Iterating `values(::ProductSector)` previously called `getindex` at every step, recomputing the multidimensional index from scratch. Instead keep the current index in the iterator state and advance it to its Manhattan-order successor with `next_manhattan_index`, which is O(N) per step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Benchmarks show that only `num_manhattan_points_below`, both `localoffset` methods and the recursive `invertlocaloffset` method benefit from the annotation; the recursive base case of `localoffset` is not inlined otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
borisdevos
approved these changes
Oct 19, 2026
borisdevos
left a comment
Member
There was a problem hiding this comment.
I had also looked into stars and bars with my previous attempt but rejected that since it was (as you noted) not better for the finite product sector types I was then interested in. I'm surprised it's this much better for the infinite stuff. Looks definitely good to me!
leburgel
approved these changes
Oct 19, 2026
This was referenced Oct 21, 2026
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.
Speeds up
findindex,getindex, iteration andislessforvalues(::ProductSector)(and for SU(N) irreps in SUNRepresentations.jl, which use the same helpers).to_manhattan_index/manhattan_to_multidimensional_indexnow count points in closed form (inclusion-exclusion) instead of recursively enumerating them, so the cost no longer grows with the Manhattan distance.values(::ProductSector)keeps the multi-index in the iterator state and advances it withnext_manhattan_index, instead of callinggetindexat every step.findindex,U1 ⊠ U1 ⊠ SU2, charge 50getindex, sameisless,U1 ⊠ SU4U1 ⊠ U1 ⊠ SU2Small-index
getindexon finite products is slightly slower (e.g. 59 → 87 ns forZ3 ⊠ Ising ⊠ Fib).🤖 Generated with Claude Code