numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
seterrcall(func)

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-handler to 'log', using seterr . Floating-point errors then trigger a call to the 'write' method of the provided object.

Parameters

func : callable f(err, flag) or object with write method

Function to call upon floating-point errors ('call'-mode) or object whose 'write' method is used to log such message ('log'-mode).

The call function takes two arguments. The first is a string describing the type of error (such as "divide by zero", "overflow", "underflow", or "invalid value"), and the second is the status flag. The flag is a byte, whose four least-significant bits indicate the type of error, one of "divide", "over", "under", "invalid":

[0 0 0 0 divide over under invalid]

In other words, flags = divide + 2*over + 4*under + 8*invalid .

If an object is provided, its write method should take one argument, a string.

Returns

h : callable, log instance or None

The old error handler.

Set the floating-point error callback function or log object.

See Also

geterr
geterrcall
seterr

Examples

Callback upon error:

This example is valid syntax, but we were not able to check execution
>>> def err_handler(type, flag):
...  print("Floating point error (%s), with flag %s" % (type, flag)) ...
This example is valid syntax, but we were not able to check execution
>>> saved_handler = np.seterrcall(err_handler)
... save_err = np.seterr(all='call')
This example is valid syntax, but we were not able to check execution
>>> np.array([1, 2, 3]) / 0.0
Floating point error (divide by zero), with flag 1
array([inf, inf, inf])
This example is valid syntax, but we were not able to check execution
>>> np.seterrcall(saved_handler)
<function err_handler at 0x...>
This example is valid syntax, but we were not able to check execution
>>> np.seterr(**save_err)
{'divide': 'call', 'over': 'call', 'under': 'call', 'invalid': 'call'}

Log error message:

This example is valid syntax, but we were not able to check execution
>>> class Log:
...  def write(self, msg):
...  print("LOG: %s" % msg) ...
This example is valid syntax, but we were not able to check execution
>>> log = Log()
... saved_handler = np.seterrcall(log)
... save_err = np.seterr(all='log')
This example is valid syntax, but we were not able to check execution
>>> np.array([1, 2, 3]) / 0.0
LOG: Warning: divide by zero encountered in true_divide
array([inf, inf, inf])
This example is valid syntax, but we were not able to check execution
>>> np.seterrcall(saved_handler)
<numpy.core.numeric.Log object at 0x...>
This example is valid syntax, but we were not able to check execution
>>> np.seterr(**save_err)
{'divide': 'log', 'over': 'log', 'under': 'log', 'invalid': 'log'}
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.geterrobj numpy.errstate numpy.seterrobj numpy.seterr numpy.geterr numpy.geterrcall

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/_ufunc_config.py#220
type: <class 'function'>
Commit: