8000 BUG: Large distances between `start` and `stop` in `np.linspace()` result in non-finite values · Issue #21585 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Large distances between start and stop in np.linspace() result in non-finite values #21585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
honno opened this issue May 24, 2022 · 3 comments
Labels
00 - Bug 57 - Close? Issues which may be closable unless discussion continued

Comments

@honno
Copy link
Contributor
honno commented May 24, 2022

Describe the issue:

I'm guessing some internal logic causes this issue, like in #20226. Given it's such an edge case this is probably not worth fixing, just thought I'd write an issue for prosperity's sake.

Reproduce the code example:

>>> np.linspace(-9.9792015476736e+291, 1.7976931348623157e+308, 1)
RuntimeWarning: overflow encountered in double_scalars
  delta = stop - start
RuntimeWarning: invalid value encountered in multiply
  y = y * delta
array([nan])  # expected -9.9792015476736e+291
>>> np.linspace(-9.9792015476736e+291, 1.7976931348623157e+308, 5)
... same warnings ...
array([ nan, inf, inf, inf, 1.79769313e+308] )  # expected finite values in-between

NumPy/Python version information:

1.23.0.dev0+1084.g5ab08cfa8 3.8.12 (default, Mar 13 2022, 19:12:08)
[GCC 9.4.0]

@bashtage
Copy link
Contributor

This is a well-known limitation due to the limits of floating-point numbers. This can only be described as "by design". The only possible solution would be to warn when linspace produces non-finite values.

@seberg
Copy link
Member
seberg commented Aug 22, 2022

I agree with @bashtage. Unless someone argues from a non hypothesis angle why this is particularly important, I think this is simply one of the many floating-point surprises that can happen and that we should simply not do anything about it.

@seberg seberg added the 57 - Close? Issues which may be closable unless discussion continued label Aug 22, 2022
@rossbar
Copy link
Contributor
rossbar commented Aug 22, 2022

I also agree, closing. Please feel free to reopen if there are further specific instances of users getting bit by this.

@rossbar rossbar closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2022
4C5B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 57 - Close? Issues which may be closable unless discussion continued
Projects
None yet
Development

No branches or pull requests

4 participants
0