summaryrefslogtreecommitdiff
path: root/numpy/numarray/util.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-06-20 00:45:43 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-06-20 00:45:43 +0000
commitc6c3f19d4968ca1971830fddfe391a942ec29edb (patch)
treef5b09eb05826f57d2147d27430014e55c7dffceb /numpy/numarray/util.py
parentaa2c1141f3782ac063f78380bead0be3a066c5cd (diff)
downloadnumpy-c6c3f19d4968ca1971830fddfe391a942ec29edb.tar.gz
Draft of libnumarray C-API.
Diffstat (limited to 'numpy/numarray/util.py')
-rw-r--r--numpy/numarray/util.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/numarray/util.py b/numpy/numarray/util.py
new file mode 100644
index 000000000..c9dbfade5
--- /dev/null
+++ b/numpy/numarray/util.py
@@ -0,0 +1,30 @@
+
+from numpy import geterr
+
+class MathDomainError(ArithmeticError): pass
+class UnderflowError(ArithmeticError): pass
+class NumOverflowError(OverflowError, ArithmeticError): pass
+
+def handleError(errorStatus, sourcemsg):
+ """Take error status and use error mode to handle it."""
+ modes = geterr()
+ if errorStatus & FPE_INVALID:
+ if modes['invalid'] == "warn":
+ print "Warning: Encountered invalid numeric result(s)", sourcemsg
+ if modes['invalid'] == "raise":
+ raise MathDomainError(sourcemsg)
+ if errorStatus & FPE_DIVIDEBYZERO:
+ if modes['dividebyzero'] == "warn":
+ print "Warning: Encountered divide by zero(s)", sourcemsg
+ if modes['dividebyzero'] == "raise":
+ raise ZeroDivisionError(sourcemsg)
+ if errorStatus & FPE_OVERFLOW:
+ if modes['overflow'] == "warn":
+ print "Warning: Encountered overflow(s)", sourcemsg
+ if modes['overflow'] == "raise":
+ raise NumOverflowError(sourcemsg)
+ if errorStatus & FPE_UNDERFLOW:
+ if modes['underflow'] == "warn":
+ print "Warning: Encountered underflow(s)", sourcemsg
+ if modes['underflow'] == "raise":
+ raise UnderflowError(sourcemsg)