Skip to content

[claude] Add SafeDiv binary operator#7549

Draft
connortsui20 wants to merge 1 commit intodevelopfrom
claude/add-safe-division-u28Ep
Draft

[claude] Add SafeDiv binary operator#7549
connortsui20 wants to merge 1 commit intodevelopfrom
claude/add-safe-division-u28Ep

Conversation

@connortsui20
Copy link
Copy Markdown
Contributor

Summary

Adds Operator::SafeDiv — a division variant where a non-null zero
divisor yields 0 rather than erroring. Integer overflow still errors
(i32::MIN / -1), matching Div. Null on either side propagates.

Implementation

The array-level kernel is a hand-written single-pass
match_each_native_ptype! loop (not a composition of existing ops). It
runs over primitive slices once, combining validity from both inputs
and producing a PrimitiveArray directly.

Wiring touches the usual places a new binary arithmetic operator hits:
proto enum and generated bindings, Operator / NumericOperator with
their conversions, the Binary scalar-fn dispatcher (including
stat_falsification), scalar-level checked_binary_numeric for both
primitive and decimal scalars, and the FFI C enum.

To combine validity from the two input arrays, the kernel calls
Validity::and and then eagerly materializes the resulting lazy
Binary(And) expression via execute::<BoolArray>(ctx). This required
threading ExecutionCtx through execute_numeric from the Binary
dispatcher.

Scope note: array-level SafeDiv is primitive-only. A decimal-array
input fails with a clear error rather than silently inheriting the
zero-rhs-errs behavior from arrow-arith; scalar-level decimal SafeDiv
(used by the constant-constant fast path) is supported.

Testing

  • 5 primitive scalar tests (integer, integer-by-zero, overflow still
    errs, float-by-zero yields 0.0 not Inf, null propagation)
  • 1 decimal scalar test (by-zero yields zero, not None)
  • 4 array-level tests (integer-by-zero, float-by-zero, nullable
    propagation from both sides, constant-zero rhs fast path)
  • Conformance harness: SafeDiv added to the operator arrays and is
    exercised with zero-valued scalars (unlike Div, which is skipped)
  • cargo test -p vortex-array --lib → 2556 passed, 0 failed
  • cargo clippy -p vortex-array -p vortex-ffi -p vortex-proto --all-targets --all-features → clean
  • cargo fmt --all → clean (nightly fmt unavailable in this sandbox)

Signed-off-by: Claude noreply@anthropic.com

https://claude.ai/code/session_01MLXfBVfMbrUgRPafnt5GHC
Signed-off-by: Claude noreply@anthropic.com

## Summary

Adds `Operator::SafeDiv` — a division variant where a non-null zero
divisor yields 0 rather than erroring. Integer overflow still errors
(`i32::MIN / -1`), matching `Div`. Null on either side propagates.

## Implementation

The array-level kernel is a hand-written single-pass
`match_each_native_ptype!` loop (not a composition of existing ops). It
runs over primitive slices once, combining validity from both inputs
and producing a `PrimitiveArray` directly.

Wiring touches the usual places a new binary arithmetic operator hits:
proto enum and generated bindings, `Operator` / `NumericOperator` with
their conversions, the `Binary` scalar-fn dispatcher (including
stat_falsification), scalar-level `checked_binary_numeric` for both
primitive and decimal scalars, and the FFI C enum.

To combine validity from the two input arrays, the kernel calls
`Validity::and` and then eagerly materializes the resulting lazy
`Binary(And)` expression via `execute::<BoolArray>(ctx)`. This required
threading `ExecutionCtx` through `execute_numeric` from the `Binary`
dispatcher.

Scope note: array-level SafeDiv is primitive-only. A decimal-array
input fails with a clear error rather than silently inheriting the
zero-rhs-errs behavior from arrow-arith; scalar-level decimal SafeDiv
(used by the constant-constant fast path) is supported.

## Testing

- 5 primitive scalar tests (integer, integer-by-zero, overflow still
  errs, float-by-zero yields 0.0 not Inf, null propagation)
- 1 decimal scalar test (by-zero yields zero, not None)
- 4 array-level tests (integer-by-zero, float-by-zero, nullable
  propagation from both sides, constant-zero rhs fast path)
- Conformance harness: SafeDiv added to the operator arrays and is
  exercised with zero-valued scalars (unlike Div, which is skipped)
- `cargo test -p vortex-array --lib` → 2556 passed, 0 failed
- `cargo clippy -p vortex-array -p vortex-ffi -p vortex-proto
  --all-targets --all-features` → clean
- `cargo fmt --all` → clean (nightly fmt unavailable in this sandbox)

Signed-off-by: Claude <noreply@anthropic.com>

https://claude.ai/code/session_01MLXfBVfMbrUgRPafnt5GHC
Signed-off-by: Claude <noreply@anthropic.com>
@connortsui20 connortsui20 marked this pull request as draft April 20, 2026 03:52
@connortsui20 connortsui20 changed the title Add SafeDiv binary operator [claude] Add SafeDiv binary operator Apr 20, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 20, 2026

Merging this PR will improve performance by 29.38%

⚡ 1 improved benchmark
✅ 1162 untouched benchmarks
⏩ 1457 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation chunked_bool_canonical_into[(1000, 10)] 59.8 µs 46.3 µs +29.38%

Comparing claude/add-safe-division-u28Ep (b5224d3) with develop (24fcc56)

Open in CodSpeed

Footnotes

  1. 1457 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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.

2 participants