8000 ENH: Added np.seterr handling of errors · numpy/numpy@f48c134 · GitHub
[go: up one dir, main page]

Skip to content

Commit f48c134

Browse files
ovillellaspv
ovillellas
authored andcommitted
ENH: Added np.seterr handling of errors
1 parent a2afc85 commit f48c134

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

numpy/core/src/umath/gufuncs_linalg.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
appropriate kernel depending on the parameters. All wrappers forward the keyword
1414
parameters to the underlying generalized ufunc (the kernel).
1515
16-
The functions are intended to be used on arrays of matrices. For those
17-
functions where a result may not be possible to obtain (like the inverse of
18-
a matrix that is not invertible) no exception is raised, but the results for
19-
the elements involved are set to NaN.
16+
The functions are intended to be used on arrays of matrices. Functions that in
17+
numpy.LinAlg would generate a LinAlgError (for example, inv on a non-invertible
18+
matrix) will just generate NaNs as result. When this happens, invalid floating
19+
point status will be set. Error handling can be configured for this cases
20+
using np.seterr.
2021
2122
Additional functions some fused arithmetic, useful for efficient operation over
2223
"""

numpy/core/src/umath/umath_linalg.c.src

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,10 @@ nan_@TYPE@_matrix(void *dst_in, const LINEARIZE_DATA_t* data)
812812
}
813813
dst += data->row_strides/sizeof(@typ@);
814814
}
815+
816+
/* if this function gets called, the module generates nans */
817+
/* set the fpe status to invalid to notify that nans were generated */
818+
npy_set_floatstatus_invalid();
815819
}
816820

817821
static inline void

0 commit comments

Comments
 (0)
0