mercredi 27 janvier 2016

is numpy testing assert_array_less working correctly with np.inf?

I found this strange behaviour when testing arrays with infinite type.

This works good:

In [91]: np.testing.assert_array_less(5, 6)

In [92]: np.testing.assert_array_less(5, np.array([6]))

In [93]: 5 < np.inf
Out[93]: True

but when using numpy testing module it occurs that 5 is not less than inf:

In [94]: np.testing.assert_array_less(5, np.array([np.inf]))
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-93-c43a15aa8a1a> in <module>()
----> 1 np.testing.assert_array_less(5, np.array([np.inf]))

c:\python27\lib\site-packages\numpy\testing\utils.pyc in assert_array_less(x, y, err_msg, verbose)
    911     assert_array_compare(operator.__lt__, x, y, err_msg=err_msg,
    912                          verbose=verbose,
--> 913                          header='Arrays are not less-ordered')
    914
    915 def runstring(astr, dict):

c:\python27\lib\site-packages\numpy\testing\utils.pyc in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision)
    629             if any(x_isinf) or any(y_isinf):
    630                 # Check +inf and -inf separately, since they are different
--> 631                 chk_same_position(x == +inf, y == +inf, hasval='+inf')
    632                 chk_same_position(x == -inf, y == -inf, hasval='-inf')
    633

c:\python27\lib\site-packages\numpy\testing\utils.pyc in chk_same_position(x_id, y_id, hasval)
    606                                 % (hasval), verbose=verbose, header=header,
    607                                 names=('x', 'y'), precision=precision)
--> 608             raise AssertionError(msg)
    609
    610     try:

AssertionError:
Arrays are not less-ordered

x and y +inf location mismatch:
 x: array(5)
 y: array([ inf])

Why numpy checks if infs are on the same positions? Is it desired behaviour?

In [99]: np.__version__
Out[99]: '1.9.3'

Aucun commentaire:

Enregistrer un commentaire