Repository navigation
Add sort-first and partition-based weighted quantile tables - #389
Merged
Merged
Conversation
Add weightedQuantileTableSortFirst, rcWeightedQuantileTableSortFirst, and makeWeightedQuantileTableSortFirst so callers can explicitly prepare sorted observations and cumulative weights before the first query. Have the existing factories forward to their sort-first counterparts. Both frequency and relative weights retain their existing preparation, allocation policy, and return type. Add a documented example that builds a reference-counted table from unordered observations and queries it through a const handle. AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Add weightedQuantileTableByPartition and its RC and custom-allocator variants for type 7 and type 8 queries. Tables own the positive-count rows and share discovered partitions across queries and copies. Reserve up to one cache node per positive-count row, capped at 64. A single row needs no cache. Once the cache fills, queries continue partitioning the unresolved rows without sorting the table. Use raw counts to resolve ties when row boundaries affect rounding or the sign of a zero result. Zero observations with the same positive count must have the same sign. Test agreement with SortFirst for signed zeros and wide integers, queries after the cache fills, and custom allocation and disposal. AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
Add tryWeightedQuantileTableByPartition and its RC and custom-allocator variants for inverse CDF and averaged inverse CDF. Reuse the frequency table's bounded partition cache for repeated queries. Check during validation that partial weight sums are exact in any partition order. Otherwise, rounding can move a probability across a cumulative boundary and change the selected observation. Return null before allocating when the check fails or positive-weight observations contain both signs of zero. Callers can then choose SortFirst. Test agreement with SortFirst at and around cumulative boundaries, shared table ownership, allocation-free declines, and allocator cleanup. AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
jmh530
force-pushed
the
codex/weighted-table-sort-first
branch
from
November 30, 2026 16:14
b8c76ae to
b6d509e
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.
Callers who query the same observations several times can now choose when to do the ordering work.
weightedQuantileTableSortFirstprepares sorted rows and cumulative weights at construction for read-only queries. The existingweightedQuantileTableforwards to it and preserves its return type and behavior.The partition factories copy positive-weight rows and discover partitions as queries arrive. Copies of a table share that work. A single positive-weight row needs no cache. Larger tables retain up to 64 partitions and continue selecting from unresolved rows when the cache fills.
weightedQuantileTableByPartition!(WeightInterpretation.frequency)supports type 7 and type 8. Zero observations with the same positive count must have the same sign.tryWeightedQuantileTableByPartitionsupports inverse CDF and averaged inverse CDF. It returns an emptyNullablebefore allocating if it cannot guarantee exact partition sums or if positive-weight observations contain both signs of zero. Rounding at a cumulative boundary can change which observation is selected, so callers choose explicitly whether to use sorted accumulation.For example, a caller can use partition selection when it preserves the sorted median and otherwise choose
SortFirst:All three factory families support GC, reference-counted, and custom allocation. Custom-allocated tables are disposed once with the original allocator after all copies are finished.
Tests cover cumulative boundaries, signed zeros, wide-integer interpolation, shared query state, cache exhaustion, allocation-free declines, and allocator cleanup. Local validation passed all 113 modules with LDC 1.43.0 and DIP1000 on a snapshot including upstream
1529f280f87a. The DMD 2.114.0 documentation check also passed.AI-Assisted-By: Codex (GPT-6.2 Astra Medium)