Set the floating-point error callback function or log object. There are two ways to capture floating-point error messages. The first is to set the error-handler to 'call', using `seterr`. Then, set the function to call using this function. The second is to set the error-hand
(func)
| 220 | |
| 221 | @set_module('numpy') |
| 222 | def seterrcall(func): |
| 223 | """ |
| 224 | Set the floating-point error callback function or log object. |
| 225 | |
| 226 | There are two ways to capture floating-point error messages. The first |
| 227 | is to set the error-handler to 'call', using `seterr`. Then, set |
| 228 | the function to call using this function. |
| 229 | |
| 230 | The second is to set the error-handler to 'log', using `seterr`. |
| 231 | Floating-point errors then trigger a call to the 'write' method of |
| 232 | the provided object. |
| 233 | |
| 234 | Parameters |
| 235 | ---------- |
| 236 | func : callable f(err, flag) or object with write method |
| 237 | Function to call upon floating-point errors ('call'-mode) or |
| 238 | object whose 'write' method is used to log such message ('log'-mode). |
| 239 | |
| 240 | The call function takes two arguments. The first is a string describing |
| 241 | the type of error (such as "divide by zero", "overflow", "underflow", |
| 242 | or "invalid value"), and the second is the status flag. The flag is a |
| 243 | byte, whose four least-significant bits indicate the type of error, one |
| 244 | of "divide", "over", "under", "invalid":: |
| 245 | |
| 246 | [0 0 0 0 divide over under invalid] |
| 247 | |
| 248 | In other words, ``flags = divide + 2*over + 4*under + 8*invalid``. |
| 249 | |
| 250 | If an object is provided, its write method should take one argument, |
| 251 | a string. |
| 252 | |
| 253 | Returns |
| 254 | ------- |
| 255 | h : callable, log instance or None |
| 256 | The old error handler. |
| 257 | |
| 258 | See Also |
| 259 | -------- |
| 260 | seterr, geterr, geterrcall |
| 261 | |
| 262 | Examples |
| 263 | -------- |
| 264 | Callback upon error: |
| 265 | |
| 266 | >>> def err_handler(type, flag): |
| 267 | ... print("Floating point error (%s), with flag %s" % (type, flag)) |
| 268 | ... |
| 269 | |
| 270 | >>> saved_handler = np.seterrcall(err_handler) |
| 271 | >>> save_err = np.seterr(all='call') |
| 272 | |
| 273 | >>> np.array([1, 2, 3]) / 0.0 |
| 274 | Floating point error (divide by zero), with flag 1 |
| 275 | array([inf, inf, inf]) |
| 276 | |
| 277 | >>> np.seterrcall(saved_handler) |
| 278 | <function err_handler at 0x...> |
| 279 | >>> np.seterr(**save_err) |
no test coverage detected