These are chat archives for numpy/numpy

25th
Nov 2015
(Venkat) Raghav, Rajagopalan
@raghavrv
Nov 25 2015 14:43

Why does numpy not have a fixed internal representation for nan?

>>> str((np.zeros(1)*np.nan).data)
'\x00\x00\x00\x00\x00\x00\xf8\x7f'
>>> a = np.ones(1)/0
/usr/local/bin/ipython:1: RuntimeWarning: divide by zero encountered in divide
  #!/usr/bin/python
>>> str(a.data)
'\x00\x00\x00\x00\x00\x00\xf0\x7f'

(Context - https://github.com/scikit-learn/scikit-learn/issues/5870#issuecomment-159409438)

(Venkat) Raghav, Rajagopalan
@raghavrv
Nov 25 2015 16:01
Small correction -- a = np.zeros(1)/0 (instead of a=np.ones(1)/0 which gives inf)
(Venkat) Raghav, Rajagopalan
@raghavrv
Nov 25 2015 16:07
Ok so from what I understand, The first one is a qNaN (quiet NaN) while the latter is a sNaN (signalling NaN)... My question is would this affect the performance when is_nan is called?
seberg
@seberg
Nov 25 2015 18:37
the binary blob of NaN's is lots of garbage anyway.... in any case I think numpy has to check the FPU errors pretty much always, so there is no difference as far as I guess. There is always a small overhead for the check (though maybe it depends on the numpy error settings whether they are checked).
though it is entirely possible that what I just said makes no sense at all ;)
(Venkat) Raghav, Rajagopalan
@raghavrv
Nov 25 2015 18:40
Thanks for the response :)
Okay so we can safely use nanfor missing values and check for them at cython level without worrying much about performance right?
seberg
@seberg
Nov 25 2015 18:49
I somewhat thought you have to check the floating point errors by hand, so as long as you don't care for getting the errors, I think so, yes.
but maybe there are some tricks, or C++ voodoo, or whatnot....
(Venkat) Raghav, Rajagopalan
@raghavrv
Nov 25 2015 18:51
No the intention here is not to get an error, instead check for nan and do some operation if the value is a nan... So if that check (for nan) and new operation (for missing a.k.a nan values) are introduced, will there be a performance issue when working with matrices without any nan-s? (due to this additional checking for nan?)
seberg
@seberg
Nov 25 2015 19:05
don't see why, but dunno...
(Venkat) Raghav, Rajagopalan
@raghavrv
Nov 25 2015 19:07
Oki Thanks :D