We desired better control over exception handling than currently exists in Numeric. This has traditionally been a problem area (see the numerous posts in comp.lang.python regarding floating point exceptions, especially those by Tim Peters). Numeric raises an exception for integer computations that result in a divide by zero or multiplications that result in overflows. The exception is raised after that operation has completed on all the array elements. No exceptions are raised for floating point errors (divide by zero, overflow, underflow, and invalid results), the compiler and processor are left to their default behavior (which is usually to return Infs and NaNs as values).
The approach for numarray is to provide customizable error handling behavior. It should be possible to specify three different behaviors for each of the four error types independently. These are:
>>> Error.setMode(all="warn") # the default mode >>> Error.setMode(dividebyzero="raise", underflow="ignore", invalid="warn")
The Error object can also be used in a stacking manner, by using the pushMode and popMode methods rather than setMode. For example:
>>> Error.getMode() _NumErrorMode(overflow='warn', underflow='warn', dividebyzero='warn', invalid='warn') >>> Error.pushMode(all="raise") # get really picky... >>> Error.getMode() _NumErrorMode(overflow='raise', underflow='raise', dividebyzero='raise', invalid='raise') >>> Error.popMode() # pop and return the ``new'' mode _NumErrorMode(overflow='raise', underflow='raise', dividebyzero='raise', invalid='raise') >>> Error.getMode() # verify the original mode is back _NumErrorMode(overflow='warn', underflow='warn', dividebyzero='warn', invalid='warn')
Send comments to the NumArray community.