diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-10-22 20:23:50 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-10-22 20:48:38 +0200 |
commit | a1dad5dcfe075681128638cae47c5ae26045cb41 (patch) | |
tree | 7e8a6aeb47b5755d4467b177ea01d610325ed083 /numpy/core | |
parent | b52487e026fc25e913b226381b185133ea629fc6 (diff) | |
download | numpy-a1dad5dcfe075681128638cae47c5ae26045cb41.tar.gz |
ENH: merge UFUNC_ERR_DEFAULT2 variable into UFUNC_ERR_DEFAULT
It seems it was added as a precaution to avoid breaking the rather
complicated ufunc code. It effectively disabled the skipping of the
dictionary lookup for the default values for the common case and leading
to hardly tested code in third party libraries like pandas which set the
error state to numpys old default (ignore all).
The skipping improves scalar performance by 2.5-5%.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/include/numpy/ufuncobject.h | 5 | ||||
-rw-r--r-- | numpy/core/numeric.py | 2 | ||||
-rw-r--r-- | numpy/core/src/umath/umathmodule.c | 1 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 19 |
4 files changed, 21 insertions, 6 deletions
diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index 423fbc279..a6307df91 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -258,14 +258,11 @@ typedef struct _tagPyUFuncObject { #define UFUNC_FPE_UNDERFLOW 4 #define UFUNC_FPE_INVALID 8 -/* Error mode that avoids look-up (no checking) */ -#define UFUNC_ERR_DEFAULT 0 - #define UFUNC_OBJ_ISOBJECT 1 #define UFUNC_OBJ_NEEDS_API 2 /* Default user error mode */ -#define UFUNC_ERR_DEFAULT2 \ +#define UFUNC_ERR_DEFAULT \ (UFUNC_ERR_WARN << UFUNC_SHIFT_DIVIDEBYZERO) + \ (UFUNC_ERR_WARN << UFUNC_SHIFT_OVERFLOW) + \ (UFUNC_ERR_WARN << UFUNC_SHIFT_INVALID) diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index f43f93d64..1ed339401 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2741,7 +2741,7 @@ class errstate(object): def _setdef(): - defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT2, None] + defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None] umath.seterrobj(defval) # set the default values diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c index 0b789de26..8c95cebf5 100644 --- a/numpy/core/src/umath/umathmodule.c +++ b/numpy/core/src/umath/umathmodule.c @@ -403,7 +403,6 @@ PyMODINIT_FUNC initumath(void) ADDCONST(ERR_PRINT); ADDCONST(ERR_LOG); ADDCONST(ERR_DEFAULT); - ADDCONST(ERR_DEFAULT2); ADDCONST(SHIFT_DIVIDEBYZERO); ADDCONST(SHIFT_OVERFLOW); diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 5a3de8edd..ac341468c 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -8,6 +8,7 @@ import itertools import numpy as np from numpy.core import * +from numpy.core import umath from numpy.random import rand, randint, randn from numpy.testing import * from numpy.core.multiarray import dot as dot_ @@ -439,6 +440,24 @@ class TestSeterr(TestCase): np.seterrobj(olderrobj) del self.called + def test_errobj_noerrmask(self): + # errmask = 0 has a special code path for the default + olderrobj = np.geterrobj() + try: + # set errobj to something non default + np.seterrobj([umath.UFUNC_BUFSIZE_DEFAULT, + umath.ERR_DEFAULT + 1, None]) + #call a ufunc + np.isnan(np.array([6])) + # same with the default, lots of times to get rid of possible + # pre-existing stack in the code + for i in range(10000): + np.seterrobj([umath.UFUNC_BUFSIZE_DEFAULT, umath.ERR_DEFAULT, + None]) + np.isnan(np.array([6])) + finally: + np.seterrobj(olderrobj) + class TestFloatExceptions(TestCase): def assert_raises_fpe(self, fpeerr, flop, x, y): |