GPy/GPy/util/decorators.py

17 lines
453 B
Python
Raw Normal View History

2013-03-12 16:38:18 +00:00
import numpy as np
from functools import wraps
def silence_errors(f):
2013-03-12 16:46:35 +00:00
"""
This wraps a function and it silences numpy errors that
happen during the execution. After the function has exited, it restores
the previous state of the warnings.
"""
2013-03-12 16:38:18 +00:00
@wraps(f)
def wrapper(*args, **kwds):
2013-03-12 16:42:52 +00:00
status = np.seterr(all='ignore')
result = f(*args, **kwds)
np.seterr(**status)
return result
2013-03-12 16:38:18 +00:00
return wrapper