You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tf.experimental.numpy.trace overflows for int8/uint8 and fails for bool on the default (offset=0) path #129233
With the default offset=0 and axes covering the last two dimensions, tnp.trace takes a fast path that calls math_ops.trace(a) directly (np_math_ops.py#L1821). That path skips the integer/bool promotion tnp.sum applies, which the non-fast path (diagonal + sum) does use. As a result:
small integer dtypes accumulate in their own width and silently overflow: the trace of a 200x200 int8 ones matrix comes out as -56 (int8) where NumPy gives 200 (int64)
the same matrix with offset=1 takes the slow path and is correct (199, int64), so the result depends on offset
bool input raises InvalidArgumentError (NumPy returns an int count)
Expected: same dtype promotion as np.trace / tnp.sum (int8/int16/bool to int64, uint8/uint16 to uint64), whichever path runs.
Hi @bodapatisaikrishna,
Thanks for reporting this issue and submitting a fix for TensorFlow. Once the PR is merged, the issue will be resolved. We appreciate your contribution.
Activity
Kayyuri commentedon Oct 19, 2026
Hi @bodapatisaikrishna,
Thanks for reporting this issue and submitting a fix for TensorFlow. Once the PR is merged, the issue will be resolved. We appreciate your contribution.
Fix several NumPy mismatches in tf.experimental.numpy
google-ml-butler commentedon Oct 23, 2026
Are you satisfied with the resolution of your issue?
Yes
No