diff options
author | James Cowgill <james410@cowgill.org.uk> | 2017-03-07 11:39:01 +0000 |
---|---|---|
committer | James Cowgill <james410@cowgill.org.uk> | 2017-03-07 11:40:35 +0000 |
commit | b5cf454008394b05df439e3160618da83e85775a (patch) | |
tree | 8edaab8ddecd166cf6be50cc90127d1136f2baeb /numpy/core/numeric.py | |
parent | 66f1b8a5411e8265ed87ff7bf97c67960af2624d (diff) | |
download | numpy-b5cf454008394b05df439e3160618da83e85775a.tar.gz |
BUG: Don't signal FP exceptions in np.absolute
Fixes #8686
This PR centers around this piece of code in `numpy/core/src/umath/loops.c.src`:
```c
UNARY_LOOP {
const @type@ in1 = *(@type@ *)ip1;
const @type@ tmp = in1 > 0 ? in1 : -in1;
/* add 0 to clear -0.0 */
*((@type@ *)op1) = tmp + 0;
}
```
If in1 is `NaN`, the C99 standard requires that the comparison `in1 > 0`
signals `FE_INVALID`, but the usual semantics for the absolute function are
that no FP exceptions should be generated (eg compare to C `fabs` and Python
`abs`). This was probably never noticed due to a bug in GCC x86 where all
floating point comparisons do not signal exceptions, however Clang on x86 and
GCC on other architectures (including ARM and MIPS) do signal an FP exception
here.
Fix by clearing the floating point exceptions after the loop has
finished. The alternative of rewriting the loop to use `npy_fabs`
instead would also work but has performance issues because that function
is not inlined. The `test_abs_neg_blocked` is adjusted not to ignore
`FE_INVALID` errors because now both absolute and negate should never
produce an FP exceptions.
Diffstat (limited to 'numpy/core/numeric.py')
0 files changed, 0 insertions, 0 deletions