Move the seterr statement to solve and simulate and use error states instead, as these will automatically reset upon exit.
@@ -21,11 +21,6 @@ import numpy as np
from time import clock
from .parallel import multiThreadCommands, multiThreadCommandsFake
-# Ignore floating point "errors". Numpy calls it "errors", but really it's excep-
-# tions with well-defined answers such as 1.0/0.0 that is np.inf, -1.0/0.0 that is
-# -np.inf, np.inf/np.inf is np.nan and so on.
-np.seterr(all='ignore')
-
def distanceMetric(thing_A,thing_B):
'''
A "universal distance" metric that can be used as a default in many settings.
@@ -377,6 +372,10 @@ class AgentType(HARKobject):
none
'''
+ # Ignore floating point "errors". Numpy calls it "errors", but really it's excep-
+ # tions with well-defined answers such as 1.0/0.0 that is np.inf, -1.0/0.0 that is
+ # -np.inf, np.inf/np.inf is np.nan and so on.
+ with np.errstate(divide='ignore', over='ignore', under='ignore', invalid='ignore'):
self.preSolve() # Do pre-solution stuff
self.solution = solveAgent(self,verbose) # Solve the model by backward induction
if self.time_flow: # Put the solution in chronological order if this instance's time flow runs that way
@@ -685,6 +684,10 @@ class AgentType(HARKobject):
-------
None
'''
+ # Ignore floating point "errors". Numpy calls it "errors", but really it's excep-
+ # tions with well-defined answers such as 1.0/0.0 that is np.inf, -1.0/0.0 that is
+ # -np.inf, np.inf/np.inf is np.nan and so on.
+ with np.errstate(divide='ignore', over='ignore', under='ignore', invalid='ignore'):
orig_time = self.time_flow
self.timeFwd()
if sim_periods is None:
