python - is numpy testing assert_array_less working correctly with np.inf? -
i found strange behaviour when testing arrays 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 occurs 5 not less 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 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 , -inf separately, since 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 not less-ordered x , y +inf location mismatch: x: array(5) y: array([ inf])
why numpy checks if infs on same positions? desired behaviour?
in [99]: np.__version__ out[99]: '1.9.3'
as mentioned warren in comment, was/is bug in numpy. fixed in current master , fixed in upcoming version 1.13:
in [1]: import numpy np in [2]: np.testing.assert_array_less(5, np.array([np.inf])) in [3]: np.testing.assert_array_less(-np.inf, np.array([np.inf])) in [4]: np.testing.assert_array_less(-np.inf, 5) in [5]: np.testing.assert_array_less(np.inf, 5) --------------------------------------------------------------------------- assertionerror traceback (most recent call last) <ipython-input-5-a31a27ca3803> in <module>() ----> 1 np.testing.assert_array_less(np.inf, 5) /xxx/lib/python2.7/site-packages/numpy/testing/utils.pyc in assert_array_less(x, y, err_msg, verbose) 1029 verbose=verbose, 1030 header='arrays not less-ordered', -> 1031 equal_inf=false) 1032 1033 /xxx/lib/python2.7/site-packages/numpy/testing/utils.pyc in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf) 773 names=('x', 'y'), precision=precision) 774 if not cond: --> 775 raise assertionerror(msg) 776 except valueerror: 777 import traceback assertionerror: arrays not less-ordered (mismatch 100.0%) x: array(inf) y: array(5) in [6]: np.__version__ out[6]: '1.13.0.dev0+c5e1773'
Comments
Post a Comment