Add native decimal Add/Sub kernels#8724
Draft
mhk197 wants to merge 3 commits into
Draft
Conversation
Mechanical move mirroring the compare split: dtype-generic lane machinery stays in numeric/mod.rs (bounds relaxed to T: Default so wider decimal types can reuse it), primitive-specific code moves to numeric/primitive.rs, tests to numeric/tests.rs. Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Add and Sub over decimal arrays sharing a decimal dtype, applied to the unscaled stored integers (exact at a shared scale) in a working width wide enough that in-precision inputs cannot spuriously overflow. Precision violations error only on valid lanes, matching primitive semantics. Mul and Div need rescaling and are gated off until follow-up PRs. widened_buffer moves to arrays/decimal so compare and numeric share it. Signed-off-by: Matt Katz <mhkatz97@gmail.com>
The conformance harness now accepts decimal arrays, checking Add/Sub results element-wise against DecimalScalar::checked_binary_numeric for representative constants. Wire it into the decimal, chunked, and decimal-byte-parts compute tests, and add decimal Add cases to the binary_ops benchmark. Signed-off-by: Matt Katz <mhkatz97@gmail.com>
This was referenced Jul 11, 2026
Merging this PR will improve performance by 12.73%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
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.
Adds shared infrastructure for Decimal arithmetic and Add/Sub kernels.
Semantics
Both operands must share one
DecimalDType(as compare requires since #8661;coerce_args/least_supertypealready coerce to a common decimal dtype), and the result keeps that dtype with unioned nullability. Add/Sub apply to the unscaled stored integers — exact at a shared scale.Implementation
numeric.rssplits intonumeric/{mod,primitive,decimal,tests}.rs, mirroring the compare split in Implement compare in vortex instead of falling back to arrow #8661. The generic checked lane loops move tonumeric/mod.rswith bounds relaxed toT: Defaultso wider decimal types qualify.numeric/decimal.rsfollowscompare/decimal.rs: operands canonicalize throughexecute::<DecimalArray>(so Chunked, DecimalByteParts, Dict, … work with no kernel registration) or extract constants, widen once to a working type, and run one-pass checked lanes.max(storage widths, smallest type for p+1 digits), so in-precision inputs cannot spuriously overflow the sum, and the range check subsumes width overflow. Note precision can be stricter than width:60 + 60fits an i8 but exceeds precision 2 and errors.DecimalDataexplicitly supports wider-than-necessary storage. Happy to add aBigCastnarrowing pass if preferred.DecimalScalar::checked_binary_numeric(whose Add/Sub are already correct) for constants0, 1, -1, 10^s, MAX_BY_PRECISION[p]in both operand orders; wired into the decimal, chunked, and decimal-byte-parts compute tests.widened_buffermoves fromcompare/decimal.rstoarrays/decimalso compare and numeric share it.