BUG: torch: accept Python scalars in binary elementwise functions #478
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.35) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 161 lines diff across 2 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
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.304
Real PR Conversation Timeline
1 comments
"Review active on #478"
general
weight: 0.35
mdhaber
Closes #271 (also covers #410).
torch.maximum,minimum,atan2,hypot,logaddexp,nextafterandlogical_and/or/xorreject Python scalars, andequal,not_equal,less,less_equal,greater,greater_equalandcopysignreject a scalar as the first argument. The 2024.12 standard allows a scalar in either position.Following the idea in the issue,
_two_argnow takesscalar_x1/scalar_x2flags. When set, a Python scalar in that position is converted to a 0-D tensor withresult_type(scalar, other)on the other argument's device. The flags are only set where torch rejects the scalar, so calls that already work (e.g.add(x, 1)) take the same path as before.nextafterand the logical functions are now wrapped too and added to__all__.Testing: removed the matching
test_binary_with_scalars_*entries fromtorch-xfails.txt; those 28 tests pass locally against array-api-tests, along with the rest oftest_operators_and_elementwise_functions.pyandtest_signatures.py. Added tests totests/test_torch.py; they fail on main and pass with this change.ruff check .passes.