tisonkun opened a new pull request, #295:
URL: https://github.com/apache/datasketches-rust/pull/295

   ## Why and scope
   
   An empty sketch currently produces the same error category as a bad query 
argument. Callers should be able to distinguish “no samples” from “invalid 
request”.
   
   - Implements the KLL/REQ part of [the decision in 
#266](https://github.com/apache/datasketches-rust/issues/266#issuecomment-5510650977),
 adapted from #273 onto current `main`.
   - Covers KLL, REQ, and their sorted views. T-Digest is deferred to a 
separate PR, so #266 remains open.
   - Core behavior changes are in four implementation files; the remaining 
changes document the contract and adapt or extend tests.
   
   ## Query contract
   
   The same design is documented in 
[`datasketches::error`](https://github.com/tisonkun/datasketches-rust/blob/codex/kll-req-query-semantics/datasketches/src/error.rs#L20),
 linked from both sketch modules.
   
   | Query | Valid input, non-empty | Valid input, empty | Invalid input, any 
state |
   | --- | --- | --- | --- |
   | `rank` | `Some(rank)` | `None` | No fallible argument validation; items 
implement `Ord` |
   | `quantile`, `quantiles`, `cdf`, `pmf` | `Ok(Some(result))` | `Ok(None)` | 
`Err(InvalidArgument)` |
   
   - **Validation comes first:** ranks must be in `[0.0, 1.0]` and not NaN; 
split points must be strictly increasing.
   - **Empty argument slices are valid:** on a non-empty sketch, 
`quantiles(&[])` returns `Ok(Some(vec![]))`, and `cdf(&[])` / `pmf(&[])` return 
`Ok(Some(vec![1.0]))`. On an empty sketch, all return `Ok(None)`.
   - **Caller migration:** handle `rank` as an `Option`; for the other queries, 
use `?` to propagate invalid arguments, then handle the `Option` for an empty 
sketch.
   - **Existing boundaries stay intact:** `min_item` / `max_item` return 
`Option`; malformed serialized data returns `InvalidData`; broken internal 
invariants remain programming errors.
   
   This is a breaking API change for released REQ callers, recorded in the 
changelog. KLL is still unreleased. The existing exact-extrema behavior, 
endpoint fast paths, and serialization format are preserved.
   
   ## Validation
   
   - `cargo x prepare-testdata`
   - `cargo x check`
   - `cargo x test` (including doctests and cross-language serialization 
fixtures)
   - `cargo x lint`
   
   Regression coverage checks empty, singleton, and estimation states; both 
search criteria; NaN, infinities, and out-of-range ranks; duplicate/descending 
split points; and empty argument slices. Existing endpoint and large-weight 
tests are retained.
   
   ## Credit
   
   Adapted from the KLL/REQ implementation by @Phoenix500526 in #273. The 
commit includes:
   
   ```text
   Co-authored-by: Jiawei Zhao <[email protected]>
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to