Fix out-of-range Python integers in binary elementwise functions #3202
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 519 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.374
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3202"
general
weight: 0.35
vlad-perevezentsev
Binary elementwise functions raised
OverflowErrororValueErrorfor a Python integer that the array data type cannot hold, where NumPy returns a result:This PR:
dpnp.tensor, converts a scalar operand once, to the data type the kernel reads, instead of to the resolved data type and then into a 0-d buffer of the kernel's data type. This fixes the functions that compute in floating point for an integer or boolean array (arctan2,hypot,copysign,heaviside,logaddexp,logaddexp2,nextafter,float_power,ldexpwith a Python integer mantissa, anddivideof a boolean array), and saves an allocation and a copy kernel per call.dpnp.divide.dpnp.logical_and,dpnp.logical_oranddpnp.logical_xorafter checking that it fitsint64, as NumPy does. Outside that range they now raiseOverflowErrorfor every array data type, as NumPy does, where they used to return a result for a floating-point array.OverflowErrorinstead of a misleadingValueErrorin thedpnp.tensorcomparison functions,dpnp.tensor.divide,dpnp.tensor.isinanddpnp.tensor.searchsortedfor a Python integer outside theint64anduint64ranges.The Array API standard leaves all these cases unspecified: a Python integer outside the bounds of the array data type, integer arrays in
atan2and similar functions, and Python integers in the logical functions. Results of the cases the standard covers do not change.Not changed:
dpnp.float_powerof anint8array returnsfloat32, anddpnp.ldexpof a Python integer and an integer array returnsfloat64, where NumPy returnsfloat64andfloat16; both also happen with small integers.dpnp.searchsorted(x, 264)now raisesOverflowError, where NumPy returnslen(x).Performance against master on an Intel Data Center GPU Max 1100 (Level Zero) and a Xeon Platinum 8480+ (OpenCL CPU device), n = 1 / 4096 / 224 elements, 8 rounds of fresh processes in alternating order:
| Case | GPU | CPU |
|---|---|---|
| Python scalar the kernel reads natively:
add,less,equal,logical_and,divide,x += 1| no change | no change || Scalar that needed a cast:
arctan2(i4, 2),hypot(i8, 3),divide(i4, 2),divide(b1, 2)| about 10 % faster (20-40 µs per call) at n ≤ 4096, no change at 224 | no change ||
logical_and(b1, 1)| 2.3x / 2.1x / 1.6x faster | 1.9x / 1.8x / 7.5x faster ||
less(i4, 264),less(264, i4),equal(i8, -264)(raised before) | 1.3x / 1.1x / 1.0x the time of the in-range comparison | 1.0-1.1x the time of the in-range comparison |"No change" means within the run-to-run variation of untouched code (GPU 3-9 %, CPU 3-49 %, largest at small n). At 2**24 on the GPU, the cases that make float64 temporaries vary by up to 50 % between processes on both master and this branch; their medians stay within 5 %. The added Python cost is 53 ns per binary call and up to 0.2 µs for a comparison,
divideor logical function with a Python integer.