summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com>2017-08-25 15:56:36 +0530
committer=Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com>2017-08-31 15:47:55 +0530
commit643b46454c8a2049064744dbf207a3b85f0d91b7 (patch)
treedaea49cefb9af069b5f68f304214dcfb07d894d3
parent9c8413862058c123c3caa5c310c77b1b5c74a12a (diff)
downloadnumpy-643b46454c8a2049064744dbf207a3b85f0d91b7.tar.gz
MAINT: Remove global statement
- Use of `global` variable may have unintented consequences, so it is better to refactor the code so that we do not need to use `global`.
-rw-r--r--numpy/linalg/linalg.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py
index edd980dd5..dc45b79fd 100644
--- a/numpy/linalg/linalg.py
+++ b/numpy/linalg/linalg.py
@@ -69,12 +69,8 @@ class LinAlgError(Exception):
"""
pass
-# Dealing with errors in _umath_linalg
-
-_linalg_error_extobj = None
def _determine_error_states():
- global _linalg_error_extobj
errobj = geterrobj()
bufsize = errobj[0]
@@ -82,9 +78,11 @@ def _determine_error_states():
divide='ignore', under='ignore'):
invalid_call_errmask = geterrobj()[1]
- _linalg_error_extobj = [bufsize, invalid_call_errmask, None]
+ return [bufsize, invalid_call_errmask, None]
-_determine_error_states()
+# Dealing with errors in _umath_linalg
+_linalg_error_extobj = _determine_error_states()
+del _determine_error_states
def _raise_linalgerror_singular(err, flag):
raise LinAlgError("Singular matrix")
@@ -99,7 +97,7 @@ def _raise_linalgerror_svd_nonconvergence(err, flag):
raise LinAlgError("SVD did not converge")
def get_linalg_error_extobj(callback):
- extobj = list(_linalg_error_extobj)
+ extobj = list(_linalg_error_extobj) # make a copy
extobj[2] = callback
return extobj