Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@jenshnielsen

Description

@jenshnielsen
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.