You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems the behavior of either numpy.random.normal or numpy.abs is not consistent across platforms (at least on Linux and macOS). We use the output of numpy.abs as the scale parameter passed to numpy.random.normal: a ValueError is raised when the array passed to numpy.abs contains a NaN value on some systems whereas the statement is executed without error on others.
Besides, when passing numpy.array([numpy.nan]) (which is the output of numpy.abs(numpy.array([numpy.nan]))) as the scale parameter, there is no error, so there might be a problem with the in-memory representation of the result returned by numpy.abs on some systems.
We tested our code on Linux and didn't check for NaNs at first: since we have been facing issues with wheels on multiple Python packages lately, our first move has been to reinstall NumPy from the source distribution with:
On macOS with a NumPy package reinstalled from source (the wheel version fails as well):
Python 3.7.2 (default, Feb 12 2019, 08:15:36)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import numpy
In [2]: numpy.abs(numpy.array([numpy.nan]))
Out[2]: array([nan])
In [3]: numpy.random.normal(0.0, numpy.array([numpy.nan]), 1)
Out[3]: array([nan])
In [4]: numpy.random.normal(0, numpy.abs(numpy.array([numpy.nan])), 1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-26abddb224ea> in <module>
----> 1 numpy.random.normal(0, numpy.abs(numpy.array([numpy.nan])), 1)
mtrand.pyx in mtrand.RandomState.normal()
ValueError: scale < 0
Just to note for whoever looks at it next. This is related to np.signbit (on my arch I get the error as well), which seems to be a bit ill defined for NaN. I am not sure if this check was not even changed recently and one reason for the signbit may even have been NaN?
EDIT: I get False for fresh created NaN always, but abs(NaN) gives me a True signbit.
signbit is probably the wrong test, or at least is inconsistent with the documentation, which states that scale must be non-negative (and nan is not non-negative). The randomgen WIP #13163 uses not scale < 0 instead of signbit, although this may not be desirable in all cases.
Uh oh!
There was an error while loading. Please reload this page.
It seems the behavior of either
numpy.random.normal
ornumpy.abs
is not consistent across platforms (at least on Linux and macOS). We use the output ofnumpy.abs
as thescale
parameter passed tonumpy.random.normal
: a ValueError is raised when the array passed tonumpy.abs
contains a NaN value on some systems whereas the statement is executed without error on others.Besides, when passing
numpy.array([numpy.nan])
(which is the output ofnumpy.abs(numpy.array([numpy.nan]))
) as thescale
parameter, there is no error, so there might be a problem with the in-memory representation of the result returned bynumpy.abs
on some systems.We tested our code on Linux and didn't check for NaNs at first: since we have been facing issues with wheels on multiple Python packages lately, our first move has been to reinstall NumPy from the source distribution with:
and with this the ValueError went away, so we thought it was just another issue caused by the libraries linked in the wheel.
But then we tested on macOS and this workaround didn't work. Reinstalling both Cython and NumPy with
--no-binary :all:
had no effect.Sorry if this is a bit confuse, the example code and the outputs provided below should make things clearer.
Reproducing code example:
Error message:
On Linux with a NumPy package installed using the wheel:
On Linux with a NumPy package reinstalled from source:
On macOS with a NumPy package reinstalled from source (the wheel version fails as well):
Numpy/Python version information:
On ArchLinux:
On mac OS mojave (10.14.3):
The text was updated successfully, but these errors were encountered: