Skip to content

tf.experimental.numpy.cumsum / cumprod raise for bool input instead of promoting to int like NumPy #129239

Closed

Description

@bodapatisaikrishna

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

binary

TensorFlow version

tf-nightly 2.23.0-dev20261014 (git v1.12.1-146947-gfcb676979cd)

Custom code

Yes

OS platform and distribution

macOS 15.7.2 (arm64)

Mobile device

No response

Python version

3.11.7

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

NumPy promotes bool input to the default int for cumsum/cumprod (np.cumsum([True, False, True]) == [1, 1, 2]). In tnp, _maybe_promote_to_int (np_array_ops.py#L528) only handles integer dtypes, so bool reaches the Cumsum/Cumprod kernels and raises InvalidArgumentError. tnp.sum/tnp.prod already promote bool through _reduce.

Expected: tnp.cumsum([True, False, True]) == [1, 1, 2], tnp.cumprod([True, True, False]) == [1, 1, 0].

Standalone code to reproduce the issue

import numpy as np
import tensorflow.experimental.numpy as tnp

print(np.cumsum([True, False, True]), np.cumprod([True, True, False]))
for f in (tnp.cumsum, tnp.cumprod):
  try:
    print(f([True, False, True]))
  except Exception as e:
    print(f.__name__, type(e).__name__, str(e).splitlines()[0][:120])

Relevant log output

[1 1 2] [1 1 0]
cumsum InvalidArgumentError Value for attr 'T' of bool is not in the list of allowed values: float, double, int32, uint8, int16, int8, complex64, in
cumprod InvalidArgumentError Value for attr 'T' of bool is not in the list of allowed values: float, double, int32, uint8, int16, int8, complex64, in

Activity

  1. added
    comp:ops
    2.21.0
    on Oct 19, 2026
  2. Kayyuri commented on Oct 19, 2026

    @Kayyuri

    Hi @bodapatisaikrishna,
    Thanks for reporting the issue and submitting a fix for TensorFlow. Once the PR is merged, the issue will be resolved. We truly appreciate your initiative and the effort in contributing the fix.

  3. added a commit that references this issue on Oct 23, 2026
    adefc9a
  4. google-ml-butler commented on Oct 23, 2026

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

2.21.0awaiting PR mergecomp:opstype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions