diff --git a/SimPEG/inverse/Inversion.py b/SimPEG/inverse/Inversion.py index 254e7651..a8e05a1a 100644 --- a/SimPEG/inverse/Inversion.py +++ b/SimPEG/inverse/Inversion.py @@ -118,7 +118,6 @@ class BaseInversion(object): Where the * can be any string. If present, _doEndIteration* will be called at the start of the default doEndIteration call. You may also completely overwrite this function. - :param numpy.ndarray xt: tested new iterate that ensures a descent direction. :rtype: None :return: None """ diff --git a/SimPEG/utils/__init__.py b/SimPEG/utils/__init__.py index f7daf273..724f6f38 100644 --- a/SimPEG/utils/__init__.py +++ b/SimPEG/utils/__init__.py @@ -12,6 +12,10 @@ import Solver from Solver import Solver import Geophysics +import types +import time +import numpy as np + def setKwargs(obj, **kwargs): """Sets key word arguments (kwargs) that are present in the object, throw an error if they don't exist.""" for attr in kwargs: @@ -66,10 +70,17 @@ def callHooks(obj, match, *args, **kwargs): if getattr(obj,'debug',False): print (match+' is calling self.'+method) getattr(obj,method)(*args, **kwargs) +def hook(obj, method, name=None, overwrite=False): + """ + This dynamically binds a method to the instance of the class. - -import time -import numpy as np + If name is None, the name of the method is used. + """ + if name is None: name = method.__name__ + if not hasattr(obj,name) or overwrite: + setattr(obj, name, types.MethodType( method, obj )) + else: + print 'Method '+name+' was not overwritten.' class Counter(object):