Skip to content

tf.experimental.numpy.geomspace does not return exact endpoints; integer dtype gives [1, 9, 99, 999] #129236

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?

tnp.geomspace computes the samples as 10 ** linspace(log10(start), log10(stop)) (np_math_ops.py#L1490), so rounding error leaves the endpoints off (999.999999999999 instead of 1000.0). NumPy explicitly sets result[0] = start and result[-1] = stop (when endpoint=True) to avoid this.

With an integer dtype the error turns into wrong values, because the final cast truncates: tnp.geomspace(1, 1000, 4, dtype=np.int32) returns [1, 9, 99, 999] where NumPy returns [1, 10, 100, 1000].

Expected: endpoints exactly equal to start/stop, and integer output matching NumPy.

Standalone code to reproduce the issue

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

print(tnp.geomspace(1, 1000, 4, dtype=np.int32))
print(np.geomspace(1, 1000, 4, dtype=np.int32))
print(repr(tnp.geomspace(1., 1000., 4).numpy()[-1]), repr(np.geomspace(1., 1000., 4)[-1]))

Relevant log output

tf.Tensor([  1   9  99 999], shape=(4,), dtype=int32)
[   1   10  100 1000]
np.float64(999.999999999999) np.float64(1000.0)

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 this issue and submitting a fix for TensorFlow. Once the PR is merged, the issue will be resolved. We appreciate your contribution.

  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