As I wrote in my last post that's, its quicker to just extract the value directly from the Python scalar.
But for numpy has different scenario to handle integers based on OS 32/64 bit.
For example, There are basically two standards for long on 64 bit os, Microsoft uses long = int (32 bits), Linux uses long = long long
(64 bits).
Hence, before getting into speedup modifications mentioned here, there is need to have much test case to ensure behavior of integer remains same.
Hence, before getting into speedup modifications mentioned here, there is need to have much test case to ensure behavior of integer remains same.
Test to ensure errors are raised as expected
def test_int_raise_behaviour(self): def Overflow_error_func(dtype): res = np.typeDict[dtype](np.iinfo(dtype).max + 1) for code in 'lLqQ': assert_raises(OverflowError, Overflow_error_func, code)
Test to check size of long as per different OS
def test_long_os_behaviour(self): long_iinfo = np.iinfo('l') ulong_iinfo = np.iinfo('L') if (sys.platform == "win32" or sys.platform == "win64" or platform.architecture()[0] == "32bit"): assert_equal(long_iinfo.max, 2**31-1) assert_equal(long_iinfo.min, -2**31) assert_equal(ulong_iinfo.max, 2**32-1) assert_equal(ulong_iinfo.min, 0) elif platform.architecture()[0] == "64bit": assert_equal(long_iinfo.max, 2**63-1) assert_equal(long_iinfo.min, -2**63) assert_equal(ulong_iinfo.max, 2**64-1) assert_equal(ulong_iinfo.min, 0)
Test for iinfo for long values
def test_iinfo_long_values(self): for code in 'bBhH': res = np.array(np.iinfo(code).max + 1, dtype=code) tgt = np.iinfo(code).min assert_(res == tgt) for code in np.typecodes['AllInteger']: res = np.array(np.iinfo(code).max, dtype=code) tgt = np.iinfo(code).max assert_(res == tgt) for code in np.typecodes['AllInteger']: res = np.typeDict[code](np.iinfo(code).max) tgt = np.iinfo(code).max assert_(res == tgt)
No comments:
Post a Comment