Repository navigation
Support lossless float narrowing in Widen and BtrBlocks - #11901
lwwmanning wants to merge 7 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
The lossless check and the compare pushdown hold up. I traced signed zeros, subnormals, constants beyond the narrow range, NaN and null constants, and the rejection of the v1 tag, and the frozen vortex.widen output for integers and decimals is unchanged.
There is one bug. The CUDA WidenExecutor was not updated, so a float child panics on the GPU path (inline).
Beyond that, the PR is larger than a first version needs. The constant folding for values that fall between two narrow floats, a dead float arm in constant_fits_values, an encode_float that only tests call, and a second copy of the aggregate allowlist can all go or move to follow-ups. That would leave a PR that stores floats narrow and pushes down only what fits exactly.
b692593 to
83b1715
Compare
Merging this PR will regress 1 benchmarkWarning vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed. 2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
roborev: Combined Review (
|
|
Addressed the roborev findings in
|
|
Addressed the updated roborev finding in |
45fe86a to
9be8071
Compare
c97549b to
75ab610
Compare
75ab610 to
c178d00
Compare
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
Fresh review of the rewrite at c178d007. The bit-exact fit check, the constant compare pushdown and the cast rules look correct to me, and I found no bugs. Three points:
-
Wire format. Float children reuse tag 1 of the existing
vortex.widenmetadata, with no new ID, which is much simpler than the earliervortex.widen.v2version. Butpreview2026.11.0shipped in 0.94.0 and 0.95.0, and those readers fail on a floatWidenwith "Widen child metadata does not match the parent dtype". The edition has nomin_library_version, so the code treats it as a draft that may change. The plugin's module doc also says that a field that changes the decoded values needs a new ID. A maintainer should check that a draft edition may widen whatvortex.widenmeans. -
compress_with_targetcompresses anf64column that fitsf16twice, once asf16and once asf32, and keeps the smaller. That is reasonable for the sample estimate, butcompressrepeats it on the full array. Could the estimate record which width won, so thatcompressencodes only that width? -
Proportion. About 1,400 of the 2,293 added lines are tests: 53 cases in
tests/float.rs, 35 intests/serde.rs, and 26 test functions inschemes/float/widen.rs. Please check whether cases that exercise the same path can merge.
Smaller notes: the take change, which declines when there are more indices than values, also applies to integer and decimal Widen. CompressorContext::with_sampling becomes public API. On the Codex signaling-NaN thread, I agree with Devin: the reader checks only the metadata, in constant time, as it does for decimal children.
|
Addressed the review points in
|
robert3005
left a comment
There was a problem hiding this comment.
I checked the bit-exact claim for -0.0, NaN payloads, subnormals, and the f64 -> f32 -> f64 and f64/f32 -> f16 round trips. The fit check, the narrow compare with an exact constant, the cast rules and the order aggregates on the child are correct: the accepted values widen one-to-one and keep IEEE order. I did not repeat the points that are already open (wire format of preview2026.11.0, test proportion, pub mod encode, the take change for integer and decimal Widen).
One low-severity question, inline, about f32 subnormals and the FP mode of the reader.
| /// Returns whether `value` round-trips bit-for-bit through `f32`, accepting only the positive | ||
| /// canonical quiet NaN (`f64::NAN`) among NaN bit patterns. | ||
| #[inline] | ||
| pub(in crate::arrays::widen) fn f64_fits_in_f32(value: f64) -> bool { |
There was a problem hiding this comment.
Low severity, a question more than a defect. This accepts f64 values that are subnormal in f32, for example f64::from(f32::from_bits(1)). The reader widens an f32 child in convert_values (primitive/compute/cast.rs) with as, which compiles to cvtps2pd on x86 and fcvt on aarch64. When a thread runs with DAZ (x86 MXCSR) or FZ (aarch64 FPCR) set, these instructions read a subnormal input as zero, so a value written as 1.4e-45 decodes as 0.0. A plain f64 column has no conversion on read, so it is not affected. Rust itself assumes the default FP environment, so this is only a gap between the "bit for bit" doc and a reader that changes FP flags.
If you want the guarantee to hold there too, the f32 fit check can also reject a nonzero f32 with a zero exponent field. Real f64 data rarely holds f32 subnormals, so the size cost is small. I would not apply this to f16, because f16 subnormals reach about 6e-5 and occur in real data. Otherwise, a short note in the module doc is enough.
There was a problem hiding this comment.
Good catch — documented in vortex-array/src/arrays/widen/mod.rs (0cd7217c5) that bit-exact widening assumes the default IEEE-754 floating-point environment (without DAZ/FTZ flushing f32 subnormals to zero), matching Rust's own FP-mode assumption without adding an extra check to the hot f64_fits_in_f32 scan. Happy to reject f32 subnormals in f64_fits_in_f32 instead if you'd prefer that guarantee under DAZ/FTZ.
0deaca5 to
dcf1772
Compare
Extend WidenArray and its existing preview vortex.widen wire format to narrow floating-point arrays bit-exactly (f64 to f32/f16, f32 to f16) using tag 1 (ChildType::Primitive) without introducing a new array ID or protobuf tag, and add FloatWidenScheme to BtrBlocks (excluded in CUDA writer preset, with CUDA WidenExecutor staging float Widen on host). Signed-off-by: Will Manning <will@willmanning.io>
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
dcf1772 to
a220f6c
Compare
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I reviewed a220f6c with fresh eyes, and the core is correct. The fit checks compare bit patterns, so -0.0 stays distinct, and a signaling NaN fails because the narrowing cast quiets it. narrow_slice_with_mask writes zero into null slots. A compare runs on the child only when a non-NaN constant fits the child type exactly. Sum and arithmetic decline, and tag 1 keeps the integer wire bytes.
A cast from the child also matches a cast from the widened values, because widening is exact. Three points follow, most important first.
-
narrow_float_valuesis public and rounds silently.pub mod encodeexposes it andnarrowest_float_ptypefor the BtrBlocks scheme. A caller that skips the fit check gets rounded values inside aWidenand no error. The function already visits every valid value, so it can compare each widened result with its input and return an error on a mismatch. That makes the public entry point safe at little cost. -
FloatWidenSchemeis larger than the problem needs. It has 316 lines before its tests and keeps three caches, while each other float scheme file has 97 to 142 lines in total. The scheme needsNarrowestFloatTargetand the callback that reuses it on the sample, because a sample can miss anf32-only outlier. It also needs thef16andf32comparison, because ALP skipsf16.The rest looks optional.
CachedFullWidenonly saves compressing an array of under 3,072 rows a second time.CachedBestTargetonly saves one extra candidate onf64columns that fitf16. Thefinished_cascadingbranch seems to give the ratio that the sampled callback would also give. Unless a benchmark shows these matter, removing them would make the scheme much shorter. -
The tests could lean on the existing harnesses. About 1,350 of the 2,200 added lines are tests, and much of
tests/float.rshand-picks values for operations that shared suites already check. I suggest these changes:- Add a nullable float fixture, with
-0.0, infinities and NaN, totest_conformanceintests/compute.rs. It runs the cast, filter, take, mask and consistency suites. - Add one Hegel test. Draw each value as either an
f32widened tof64, including subnormals and the edge values, or arbitraryf64bits, and draw a validity. Callencode_float. Check that valid rows decode bit for bit, and that the child is narrower only when every valid value fits. Then pass the result tocheck_encoding_roundtrip_and_ops. The current tests compare bits by hand, so the property should too. - Then remove
test_encode_float_f64_bit_exact_round_trip,test_float_filter_mask_slice_takeand most oftest_compare_f32_widen_to_f64_constants. Keep the tables for NaN and signaling NaN rejection, the constants that decline, the cast rules and the serde cases, because they pin specific contracts.
- Add a nullable float fixture, with
Minor: the take change, which returns None when there are more indices than values, also changes integer and decimal Widen. A measured result in the description would show what it gains.
…iden tests Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed the cleanup items in
|
|
CodSpeed Performance Analysis (
|
lwwmanning
left a comment
There was a problem hiding this comment.
Review by Gemini 4 Carbon on behalf of @lwwmanning.
The bit-exact IEEE-754 narrowing semantics (-0.0, subnormals, canonical positive quiet NaN, and null-slot zeroing) and the preview2026.11.0 compressor gating look good. Three substantive issues need to be addressed before landing:
BetweenReducedouble-decodes floatWidenon non-exact constant bounds (vortex-functions/src/between/widen.rs):BetweenReduce for WidenassumesWiden::comparehandles everyConstantoperand without decoding (let is_operand = |bound| bound.is::<Constant>() || bound.is::<Widen>()). That invariant does not hold for floatWiden:compare_float_constantreturnsOk(None)for any constant not bit-exactly representable invalues_ptype(such as0.1_f64over narrowedf16/f32values) and forNaNbounds. As a result,Between(float_widen, Constant(0.1_f64), Constant(0.9_f64))rewrites toas_two_compares(...), which falls back and decodes the canonicalf64array twice instead of returningOk(None)soBetweendecodes once (violating the invariant documented atvortex-functions/src/between/widen.rs:40).- Conversely, when both bounds are exact non-
NaNconstants invalues_ptype(e.g.,0.0_f64and1.0_f64),constant_fits_valuesreturnsNonefor floats and misses the single-passwiden.values().between(narrow_lower, narrow_upper, ...)fast path.
- Compile break against
develop(vortex-array/src/arrays/widen/compute/compare.rs):develop(#12196) added a thirdCompareModeparameter toArrayBuiltins::compare. Becausecompare_float_constantis a newly added function calling 2-argumentvalues.compare(constant, operator), Git marks the PRMERGEABLEwhile merging intodevelopwill fail to compile. Rebasing will also refresh CodSpeed againstdevelopto clear the unrelatedencode_primitives[u8, (2000, 2)]failure.
- Test bloat (>100 added cases vs
AGENTS.md's<= 20bound), shared-oracle Hegel property, andSTYLE.mdbitmap loops:vortex-array/src/arrays/widen/tests/float.rsalone is 827 lines and monomorphizes ~75 test cases (7 #[rstest]expanding65 #[case]s +9 #[test]+1 #[hegel::test]), pushing the PR past 100 added test cases.test_encode_float_hegel_bit_exact_and_ops(tests/float.rs:277-285) computes expected target width by callingsuper::super::encode::f64_fits_in_f16/f64_fits_in_f32—the encoder's own internal helpers—and only drawsPType::F64(neverPType::F32), so a bug inf64_fits_in_*would agree with itself.tests/float.rs:277-278,294,vortex-btrblocks/src/schemes/float/widen.rs:327, andvortex-functions/src/zip/widen.rs:290callmask.value(i)inside per-element0..lenloops (STYLE.mdhidden-cost accessor table).
(Note on preview2026.11.0: reusing vortex.widen metadata tag 1 without a new ArrayId requires preview2026.11.0 to freeze with min_library_version >= 0.96.0, since 0.94.0/0.95.0 shipped preview2026.11.0 without float Widen deserialization.)
Remediation Plan
- Rebase onto
origin/developand threadCompareMode:- In
vortex-array/src/arrays/widen/compute/compare.rs, passCompareModethroughcompare_float_constanttovalues.compare(constant, operator, mode)and verify parity against canonical execution under bothCompareMode::TOTAL_ORDERandCompareMode::IEEE(including-0.0vs+0.0and quietNaN).
- In
- Update
BetweenReduce for Wideninvortex-functions/src/between/widen.rs:- Extend
constant_fits_values/constant_in_values_dtypeto narrow non-NaN, bit-exactly representable float constants so exact constant bounds push down tovalues.between(lower, upper, options.clone())in one pass. - Tighten
is_operandfor floatWidensoas_two_comparesis only used when both bounds can actually execute inWiden::comparewithout decoding (exact non-NaNfloatConstantorWiden); otherwise returnOk(None)soBetweendecodeswidenonce. Add a test covering both exact and non-exact/NaN float bounds.
- Extend
- Make the Hegel oracle independent, collapse
#[rstest]matrices to<= 20added test cases, and removemask.value(i)loops:- In
vortex-array/src/arrays/widen/tests/float.rs, replacef64_fits_in_f16/f64_fits_in_f32intest_encode_float_hegel_bit_exact_and_opswith an independent inline IEEE bit-roundtrip + canonical-qNaN check, draw bothPType::F32andPType::F64, and includebetweenchecks. - Collapse the single-value
#[rstest]expansions acrosstests/float.rs,tests/serde.rs,vortex-btrblocks/src/schemes/float/widen.rs, andvortex-functions/src/zip/widen.rsinto table loops inside<= 15–18focused test functions total (renamingtest_compare_f16_widen_constants_and_constant_foldingto remove the stale constant-folding reference), and replacemask.value(i)loops withmask.to_bit_buffer()/for_each_set_index.
- In
- Pass CompareMode::TOTAL_ORDER in compare_float_constant and verify float Widen comparisons against canonical under TotalOrder, ZerosEqual, Canonical, and Ieee754 modes. - Extend constant_fits_values for non-NaN bit-exact floats so BetweenReduce pushes exact bounds to values.between(...) in one pass and declines on non-exact or NaN float bounds to avoid double decoding. - Use an independent IEEE bit-roundtrip + canonical-qNaN oracle in test_encode_float_hegel_bit_exact_and_ops, draw both F32 and F64, replace mask.value(i) loops with for_each_set_index, and collapse added test cases to 18 (<= 20). Co-Authored-By: Antigravity <noreply@google.com> Signed-off-by: Will Manning <will@willmanning.io>
| .execute_mask(primitive.len(), exec_ctx)?; | ||
| let Some(narrowest) = data | ||
| .get_or_insert_with(|| NarrowestFloatTarget(narrowest_float_ptype(&primitive, &mask))) | ||
| .0 | ||
| else { | ||
| return Ok(data.array().clone()); | ||
| }; | ||
|
|
||
| let candidates = candidate_targets(primitive.ptype(), narrowest); | ||
| compress_with_candidates( | ||
| compressor, | ||
| &primitive, | ||
| &mask, | ||
| candidates, | ||
| compress_ctx, | ||
| exec_ctx, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::sync::Arc; | ||
| use std::sync::LazyLock; |
There was a problem hiding this comment.
Low: FloatWidenScheme::compress narrows and cascade-compresses an f16-fitting f64 column twice. candidate_targets returns [F16, F32], and compress_with_candidates runs compress_encoded for each. The estimate callback has already chosen a winner on the sample, but only NarrowestFloatTarget is cached. compress does not reuse that winner.
Fix: Cache the target that wins on the sample in the estimate callback and have compress use only that target, trying both candidates only when nothing is cached. Output stays bit-exact.
|
Re: roborev ( |
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I checked 1b8af79. The CompareMode, BetweenReduce and Hegel-oracle fixes are correct. A float constant that does not fit can no longer reach compare_out_of_range, because floats branch to compare_float_constant first.
The test change does not reduce the tests. Added test code grew from 1,420 to 1,680 lines (tests/float.rs from 827 to 938). The #[rstest] cases became loops inside merged functions such as compresses_narrow_targets_and_skips_unnarrowable and wire_round_trip_and_child_policy. Coverage is the same, and a failure no longer names its case. The AGENTS.md limit asks for fewer cases, not fewer test attributes.
The Hegel property now has an independent oracle. With check_encoding_roundtrip_and_ops, it covers the bit-exact round trip and the operations. Please delete the hand-picked cases that the property already covers. Keep separate tests for the contracts it cannot reach: NaN and signaling-NaN rejection, the declining constants, the cast rules and the serde cases.
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed in
|
| .execute_mask(primitive.len(), exec_ctx)?; | ||
| let Some(narrowest) = data | ||
| .get_or_insert_with(|| NarrowestFloatTarget(narrowest_float_ptype(&primitive, &mask))) | ||
| .0 | ||
| else { | ||
| return Ok(data.array().clone()); | ||
| }; | ||
|
|
||
| let candidates = candidate_targets(primitive.ptype(), narrowest); | ||
| compress_with_candidates( | ||
| compressor, | ||
| &primitive, | ||
| &mask, | ||
| candidates, | ||
| compress_ctx, | ||
| exec_ctx, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::sync::Arc; |
There was a problem hiding this comment.
Low: For an f64 column that fits f16 exactly, compress runs full child compression twice, once for each target in [F16, F32]. The estimate callback already compares both candidates, on the sample or on the whole array when the array is too small to sample. It caches only NarrowestFloatTarget and not the winner, so compress repeats that work. This roughly doubles write-time cost for these columns.
Fix: Cache the winning target from the estimate callback in ArrayAndStats and have compress use only that target, trying both candidates only when nothing is cached.
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I checked 3e28425. The deletions match the request, and the Hegel property covers the hand-picked selection cases. The serialized bytes did not change, and the [8, 9] and [8, 8] metadata cases are still pinned. Two contract cases went out with the trim.
-
No hand-written test now compares an
f16child with a constant. So nothing checks that the(F64, F16)and(F32, F16)arms ofconstant_fits_values(compute/mod.rslines 149 and 150) decline. The Hegel compare takes its pivot from the array, so its constants always fit. For example, suppose the(F64, F16)arm calledf64_fits_in_f32by mistake. A compare of thef16value 0.0999755859375 withf64::from(0.1_f32)would then push down, andLtwould return false instead of true. Onef16tof64fixture intest_float_compare_pushdown_and_declinewould cover this, with constants such as0.1,f64::from(0.1_f32)andf64::from(f16::MAX).next_up(). -
No test now rejects a float child as wide as its parent. The trim removed the equal-width rows from
test_float_try_new_and_flattenand the(F64, [8, 10])serde case. The remainingF64underF32case still fails if the check atarray.rsline 80 becomes<=. With that change, a reader would acceptvortex.widenmetadata[8, 10]under anf64parent. One case intest_widen_wire_rejects_invalid_child_metadatarestores the check:#[case::float_same_width(PType::F64.into(), &[8, 10], "narrower")].
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Restored both contract cases in
|
| fn compress( | ||
| &self, | ||
| compressor: &CascadingCompressor, | ||
| data: &ArrayAndStats, | ||
| compress_ctx: CompressorContext, | ||
| exec_ctx: &mut ExecutionCtx, | ||
| ) -> VortexResult<ArrayRef> { | ||
| let primitive = data.array_as_primitive().into_owned(); | ||
| let mask = primitive | ||
| .validity()? | ||
| .execute_mask(primitive.len(), exec_ctx)?; | ||
| let Some(narrowest) = data | ||
| .get_or_insert_with(|| NarrowestFloatTarget(narrowest_float_ptype(&primitive, &mask))) | ||
| .0 | ||
| else { | ||
| return Ok(data.array().clone()); | ||
| }; | ||
|
|
||
| let candidates = candidate_targets(primitive.ptype(), narrowest); | ||
| compress_with_candidates( | ||
| compressor, | ||
| &primitive, | ||
| &mask, | ||
| candidates, | ||
| compress_ctx, | ||
| exec_ctx, | ||
| ) | ||
| } |
There was a problem hiding this comment.
Low: FloatWidenScheme::compress runs the full compress_encoded cascade for both F16 and F32 when an f64 column fits f16. The estimate callback has already compared these candidates, but it caches only NarrowestFloatTarget and not which candidate won. As a result, compress_with_candidates repeats the work on the full array. For these columns, compression at write time costs about twice as much.
Fix: Cache the winning candidate's ptype from the estimate callback in ArrayAndStats and have compress narrow only to that target, falling back to trying both candidates only when no winner is cached.
This adds float children to the
Widenarray, and a BtrBlocks scheme,FloatWidenScheme, that stores float columns narrower when that loses no bits. Integer and decimalWidenarrays keep their behavior and their wire bytes.On develop,
Widenholds only integer and decimal children, so anf64column of exactf32values stays at full width. With this PR,WidenArray::encode_floatnarrowsf64tof32orf16, orf32tof16, when every valid value widens back bit for bit.-0.0stays distinct from+0.0, and anyNaNother than the positive canonical quietNaNkeeps the column wide.Comparisons with an exact constant or another float
Widen,cast,fill_null,zip, and order aggregates such asMinMaxrun on the narrow child. Float arithmetic andSumwiden first, because their rounding depends on the width.The PR also changes three other things. A
takewith more indices than values now declines, soDictwidens its values once, for integer and decimalWidentoo. Thewiden::encodemodule andCompressorContext::with_samplingbecome public, for the scheme. The CUDAWidenkernel decodes a floatWidenon the host.The scheme runs only when the target edition allows
vortex.widen, so default writes do not change, and CUDA writers skip it. In the author's run on 45 benchmark datasets, it madepreview2026.11.0files 11.4% smaller in total, mostly fromf32embeddings stored asf64.Wire format change:
vortex.widennow stores a float child as itsPTypeunder tag 1, with no new ID or tag.vortex.widenbelongs topreview2026.11.0, which has nomin_library_versionyet, so its members can still change. But releases 0.94.0 and 0.95.0 include that edition, and their readers fail on a floatWidenwith "Widen child metadata does not match the parent dtype".Authored with AI assistance.