Skip to content

Commit 76bb388

Browse files
committed
DOC: a bit more on RuntimeWarnings
1 parent 61322fd commit 76bb388

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

torch_np/_dtypes_impl.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ def category(dtyp):
8585

8686
def nep50_to_tensors(x1, x2, handle_weaks):
8787
"""If either of inputs is a python scalar, type-promote with NEP 50.
88-
89-
NB: NEP 50 mandates RuntimeWarnings on some overflows. We do not emit them:
90-
we either raise an OverflowError or silently do the computation.
9188
"""
9289
x1_type, x2_type = type(x1), type(x2)
9390
if x1_type == torch.Tensor and x2_type == torch.Tensor:
@@ -120,6 +117,11 @@ def nep50_to_tensors(x1, x2, handle_weaks):
120117

121118
# detect overflows: in PyTorch, uint8(-1) wraps around to 255,
122119
# while NEP50 mandates an exception.
120+
#
121+
# Note that we only check if each element of the binop overflows,
122+
# not the result. Consider, e.g. `uint8(100) + 200`. Operands are OK
123+
# in uint8, but the result overflows and wrap around 255.
124+
# Numpy emits a RuntimeWarning, PyTorch does not, and we do not either.
123125
if cat_weak == 1 and cat_not_weak == 1:
124126
# integers
125127
iinfo = torch.iinfo(not_weak.dtype)

0 commit comments

Comments
 (0)