docs(linalg): document the length contract on the public distance entry points - #8879
docs(linalg): document the length contract on the public distance entry points#8879LuciferYang wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The documentation now exposes the established length and batch-layout contracts at the relevant public entry points while preserving the distinction between built-in and downstream trait implementations. The profile-specific L2Prepared cases also match the current behavior.
|
The red This PR changes only doc comments in |
|
A final pass over the rendered docs rather than the diff found one real inconsistency, now fixed: the summary line I added to I only changed the line this PR adds. The rest of that pass came back clean: all 13 |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The author’s latest documentation correction changes the new l2 summary to “squared L2 distance,” which matches the implementation’s sum-of-squared-differences semantics. The existing length and batch-layout panic documentation remains accurate, including its trait-implementation and profile-specific L2Prepared distinctions.
What this changes
Eighteen public items in
lance-linalg's distance module gain a# Panicssection. All of them already panic; none of them said so.assert_equal_lengthsandassert_batch_layoutare always-on asserts, promoted in #8593, #8594 and #8639 precisely so they fire in release. Every public entry point that reaches one now documents it, socargo docshows the contract where the caller looks rather than only in the source of a private helper. The two_arrow_batchfunctions already had a section and are untouched.The wording splits three ways, and the split is deliberate.
Concrete signatures state the panic directly:
l2_f32,l2_distance,l2_distance_uint_scalar,l2_scalar,dot_f32,dot_u8,dot_u8_scalar,l2_u8,l2_u8_scalar.Generic forwarders point at the trait method instead of repeating it, since what they do depends on the
Ta caller supplies:l2,dot,dot_distance,l2_distance_batch,dot_distance_batch.The two trait methods
L2::l2andDot::dotstate a requirement on implementors rather than a fact. Both traits are public and unsealed, so a downstreamimpl L2 for MyTypecould zip to the shorter slice and a flat "panics if the lengths differ" would be a claim about code this crate does not control. The five impls in the crate do panic, and the section says so.L2::l2_batchandDot::dot_batchspell out all three conditionsassert_batch_layoutchecks, since a reader cannot see them from the signature: non-zero dimension,x.len()equal to it, and a batch length that is a whole multiple.L2Preparedis the one place where the contract is enforced bydebug_assert_eq!rather than by those helpers, so its section says which panic is unconditional and which needs debug assertions, instead of implying it validates as much asl2_distance_batchdoes.Test plan
No behavior changes, so the checks are the documentation ones:
RUSTDOCFLAGS="-D warnings -D rustdoc::broken_intra_doc_links" cargo doc -p lance-linalg --no-deps: clean, so every[L2::l2]-style reference resolvescargo test -p lance-linalg: 394 passed, 1 ignoredcargo fmt --all -- --checkandcargo clippy -p lance-linalg --all-targets -- -D warnings: cleancargo clippy -p lance-linalg --lib -- -W clippy::missing_panics_docreports nothing in these four files. That lint only sees panics in a function's own body, so it confirms the direct-assert layer; the delegating chains were traced by hand.Verified against the code rather than assumed, since a
# Panicssection that overstates is worse than none:l2_scalarpanics twice, and the length assert runs beforechunks_exact(LANES), which rejects a zero chunk size even on an empty slice. Both are documented, in that order.L2Prepared::newpanics ondimension == 0in every profile, since integer division by zero always traps. The remainder case is reported only with debug assertions, which for this repo meansdev,testandci:[profile.ci]inheritsdev, and thedebug-assertions = falsein[profile.ci.package."*"]applies to dependencies, not to workspace members.impl L2and fiveimpl Dotblocks callsassert_equal_lengthsas the first statement of itsl2/dot, ahead of the fp16 FFI calls and the x86 runtime tiers, and the only batch override in either family,f32, callsassert_batch_layoutbefore all of its cfg branches.l2_batchis a plain function returningimpl Iterator, so it panics at the call rather than at the firstnext(), which is what makes "panics" the right word for a caller that never polls.