2015-09-07 15:18:45 +01:00
|
|
|
from __future__ import print_function
|
2015-03-27 15:14:52 +00:00
|
|
|
import numpy as np
|
|
|
|
|
import scipy as sp
|
|
|
|
|
import GPy
|
2015-08-13 08:54:56 +01:00
|
|
|
import warnings
|
2015-03-27 15:14:52 +00:00
|
|
|
|
|
|
|
|
class MiscTests(np.testing.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
Testing some utilities of misc
|
|
|
|
|
"""
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self._lim_val = np.finfo(np.float64).max
|
|
|
|
|
self._lim_val_exp = np.log(self._lim_val)
|
|
|
|
|
|
|
|
|
|
def test_safe_exp_upper(self):
|
2015-08-13 08:54:56 +01:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2015-08-19 10:10:41 +01:00
|
|
|
warnings.simplefilter('always') # always print
|
2015-08-13 08:54:56 +01:00
|
|
|
assert np.isfinite(np.exp(self._lim_val_exp))
|
|
|
|
|
assert np.isinf(np.exp(self._lim_val_exp + 1))
|
|
|
|
|
assert np.isfinite(GPy.util.misc.safe_exp(self._lim_val_exp + 1))
|
|
|
|
|
|
2015-09-07 15:18:45 +01:00
|
|
|
print(w)
|
|
|
|
|
print(len(w))
|
2015-08-13 08:54:56 +01:00
|
|
|
assert len(w)==1 # should have one overflow warning
|
2015-03-27 15:14:52 +00:00
|
|
|
|
|
|
|
|
def test_safe_exp_lower(self):
|
|
|
|
|
assert GPy.util.misc.safe_exp(1e-10) < np.inf
|