Skip to content
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

Numpy 1.16 linspace fails for very large start stop values #13089

Closed
jenshnielsen opened this issue Mar 4, 2019 · 3 comments · Fixed by #13092
Closed

Numpy 1.16 linspace fails for very large start stop values #13089

jenshnielsen opened this issue Mar 4, 2019 · 3 comments · Fixed by #13092

Comments

@jenshnielsen
Copy link

Reproducing code example:

The following corner case works correctly with numpy 1.15.4 but raises an error with numpy 1.16.2

import numpy as np
np.linspace(start = -9223372036854775809, stop = -9223372036854775809, num =1)

This was detected in a test with auto generated input using hypothesis to generate the input.

Error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-aa8cbb862cf0> in <module>
----> 1 np.linspace(start = -9223372036854775809, stop = -9223372036854775809, num =1)

~\AppData\Local\Continuum\miniconda3\envs\qcodes\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    141 
    142     delta = stop - start
--> 143     y = _nx.arange(0, num, dtype=dt).reshape((-1,) + (1,) * delta.ndim)
    144     # In-place multiplication y *= delta/div is faster, but prevents the multiplicant
    145     # from overriding what class is produced, and thus prevents, e.g. use of Quantities,

AttributeError: 'float' object has no attribute 'ndim'

Numpy/Python version information:

1.16.2 3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]

Details

This seems to happen when the number used is sufficiently large end up being represented
as an object dtype. This in turn means that delta will be a regular floating point number and not a numpy float. Therefore it does not have a ndim method. The 1.15 code looks different and does not require the ndim method to be defined.

type(np.asanyarray(-9223372036854775809))
dtype('O')
type(np.asanyarray(-9223372036854775809) * 1.0 - np.asanyarray(-9223372036854775809) *1.0)
float
@mhvk
Copy link
Contributor

mhvk commented Mar 4, 2019

Oops, that's an unexpected one. But fortunately easy to solve...

@mhvk
Copy link
Contributor

mhvk commented Mar 4, 2019

See #13092 for a possible fix.

@jenshnielsen
Copy link
Author

@mhvk thanks looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants