diff options
author | Ganesh Kathiresan <ganesh3597@gmail.com> | 2020-11-12 10:05:32 +0530 |
---|---|---|
committer | Ganesh Kathiresan <ganesh3597@gmail.com> | 2020-11-12 10:05:32 +0530 |
commit | 827bc38a21f8dbeb3b992a26751ef723577cb7d9 (patch) | |
tree | b4713729566975432a68b5be2a2cb7a65e70211f /numpy/core | |
parent | 61c3d38e3293c08f48621ca52808097845252f83 (diff) | |
download | numpy-827bc38a21f8dbeb3b992a26751ef723577cb7d9.tar.gz |
ENH: Removed legacy division
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/setup.py | 6 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 37 |
2 files changed, 6 insertions, 37 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 448499926..68aa0a851 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -386,9 +386,6 @@ def check_mathlib(config_cmd): "MATHLIB env variable") return mathlibs -def check_use_legacy_division(): - return os.environ.get('NPY_USE_LEGACY_DIVISION') is not None - def visibility_define(config): """Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty string).""" @@ -445,9 +442,6 @@ def configuration(parent_package='',top_path=None): mathlibs = check_mathlib(config_cmd) moredefs.append(('MATHLIB', ','.join(mathlibs))) - # Check if legacy division needs to be used - check_use_legacy_division() and moredefs.append('USE_LEGACY_DIVISION') - check_math_capabilities(config_cmd, ext, moredefs, mathlibs) moredefs.extend(cocache.check_ieee_macros(config_cmd)[0]) moredefs.extend(cocache.check_complex(config_cmd, mathlibs)[0]) diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 448e774cc..b37f4c427 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -857,7 +857,6 @@ NPY_NO_EXPORT NPY_GCC_OPT_3 void #endif /**end repeat1**/ -#ifndef USE_LEGACY_DIVISION NPY_NO_EXPORT void @TYPE@_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func)) { @@ -884,6 +883,7 @@ NPY_NO_EXPORT void else { *((@type@ *)op1) = libdivide_@type@_do(in1, &fast_d); + /* Negative quotients needs to be rounded down */ if (((in1 > 0) != (in2 > 0)) && (*((@type@ *)op1) * in2 != in1)) { *((@type@ *)op1) = *((@type@ *)op1) - 1; } @@ -905,42 +905,17 @@ NPY_NO_EXPORT void npy_set_floatstatus_divbyzero(); *((@type@ *)op1) = 0; } - else if (((in1 > 0) != (in2 > 0)) && (in1 % in2 != 0)) { - *((@type@ *)op1) = in1/in2 - 1; - } else { *((@type@ *)op1) = in1/in2; + + /* Negative quotients needs to be rounded down */ + if (((in1 > 0) != (in2 > 0)) && (*((@type@ *)op1) * in2 != in1)) { + *((@type@ *)op1) = *((@type@ *)op1) - 1; + } } } } } -#else -NPY_NO_EXPORT void -@TYPE@_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func)) -{ - BINARY_LOOP { - const @type@ in1 = *(@type@ *)ip1; - const @type@ in2 = *(@type@ *)ip2; - /* - * FIXME: On x86 at least, dividing the smallest representable integer - * by -1 causes a SIFGPE (division overflow). We treat this case here - * (to avoid a SIGFPE crash at python level), but a good solution would - * be to treat integer division problems separately from FPU exceptions - * (i.e. a different approach than npy_set_floatstatus_divbyzero()). - */ - if (in2 == 0 || (in1 == NPY_MIN_@TYPE@ && in2 == -1)) { - npy_set_floatstatus_divbyzero(); - *((@type@ *)op1) = 0; - } - else if (((in1 > 0) != (in2 > 0)) && (in1 % in2 != 0)) { - *((@type@ *)op1) = in1/in2 - 1; - } - else { - *((@type@ *)op1) = in1/in2; - } - } -} -#endif NPY_NO_EXPORT void @TYPE@_remainder(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func)) |