Skip to content

Add caller-provided, RC, and custom storage for sorted quantile results - #311

Merged
jmh530 merged 3 commits into
libmir:masterfrom
jmh530:sorted-quantile-storage
Nov 19, 2026
Merged

jmh530 merged 3 commits into
libmir:masterfrom
jmh530:sorted-quantile-storage

Conversation

@jmh530

@jmh530 jmh530 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

PR #310 added quantileAssumeSorted for ascending observations. This change extends the same direct rank lookup to callers who supply their own output buffer, use reference counting, or manage allocations with a custom allocator.

  • quantileAssumeSortedInto(values, probabilities, output) accepts read-only observations and writes results in probability order. The output element type determines result precision. The call requires no allocation or partition scratch.
  • rcquantileAssumeSorted returns a reference-counted batch result that can outlive the input.
  • makeQuantileAssumeSorted allocates the batch result with the caller’s allocator and releases it if evaluation throws before the result is returned.

Scalar RC and custom-allocator calls allocate nothing. All owning batch variants allocate only their result and share the output loop with quantileAssumeSortedInto.

rcquantile, makeQuantile, and three-argument quantileInto forward a random-access Phobos SortedRange with a length and the default ascending predicate to the corresponding sorted path.

Tests

Each of the three commits passed all 42 imported modules under Windows DMD with DIP1000. Focused tests cover read-only strided observations, writes through a strided output view, RC result lifetime, custom allocation counts, cleanup after a probability read throws, and forwarding from the existing entry points.

AI-Assisted-By: Codex (GPT-6.2 Astra Medium)

Write quantiles from ascending observations directly into the caller's
output buffer in probability order. Accept read-only observations and
use the output element type to determine result precision.

Share the batch loop with quantileAssumeSorted so both entry points
use the same rank lookup and interpolation. Test strided observations
and output, including that elements outside the output view retain
their values.

AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
Add rcquantileAssumeSorted for reference-counted batch results and
makeQuantileAssumeSorted for results owned by the caller's allocator.
Scalar queries allocate nothing. Batch queries allocate only the
result and fill it through the shared sorted output loop.

Test that an RC result outlives its input and that custom allocation
occurs only for batch results. Verify that a probability read throwing
partway through a batch releases the custom result allocation.

AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
… quantileInto

Recognize a random-access Phobos SortedRange with a length and the
default ascending predicate. Route rcquantile and makeQuantile to
their sorted variants, preserving the requested result ownership.
Route three-argument quantileInto to quantileAssumeSortedInto so it
can read ordered observations and write directly to the caller's output.

Document the dispatch rule and test all three entry points with a
SortedRange over read-only strided observations.

AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jmh530
jmh530 merged commit ce0f290 into libmir:master Nov 19, 2026
23 checks passed
@jmh530
jmh530 deleted the sorted-quantile-storage branch November 19, 2026 16:58
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.

1 participant