提交 9986b9b6 authored 作者: Frederic Bastien's avatar Frederic Bastien

Move the helper class MockRandomState

上级 957eb06a
...@@ -79,29 +79,6 @@ utt.seed_rng() ...@@ -79,29 +79,6 @@ utt.seed_rng()
test_rng = numpy.random.RandomState(seed=utt.fetch_seed()) test_rng = numpy.random.RandomState(seed=utt.fetch_seed())
# A helpful class to check random values close to the boundaries
# when designing new tests
class MockRandomState:
def __init__(self, val):
self.val = val
def rand(self, *shape):
return numpy.zeros(shape, dtype='float64') + self.val
def randint(self, minval, maxval=None, size=1):
if maxval is None:
minval, maxval = 0, minval
out = numpy.zeros(size, dtype='int64')
if self.val == 0:
return out + minval
else:
return out + maxval - 1
# Examples of use:
# test_rng = MockRandomState(0)
# test_rng = MockRandomState(0.99999982)
# test_rng = MockRandomState(1)
if PY3: if PY3:
def L(i): def L(i):
return i return i
......
...@@ -103,6 +103,29 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs): ...@@ -103,6 +103,29 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
verify_grad.E_grad = T.verify_grad.E_grad verify_grad.E_grad = T.verify_grad.E_grad
# A helpful class to check random values close to the boundaries
# when designing new tests
class MockRandomState:
def __init__(self, val):
self.val = val
def rand(self, *shape):
return numpy.zeros(shape, dtype='float64') + self.val
def randint(self, minval, maxval=None, size=1):
if maxval is None:
minval, maxval = 0, minval
out = numpy.zeros(size, dtype='int64')
if self.val == 0:
return out + minval
else:
return out + maxval - 1
# Examples of use:
# test_rng = MockRandomState(0)
# test_rng = MockRandomState(0.99999982)
# test_rng = MockRandomState(1)
class TestOptimizationMixin(object): class TestOptimizationMixin(object):
def assertFunctionContains(self, f, op, min=1, max=sys.maxsize): def assertFunctionContains(self, f, op, min=1, max=sys.maxsize):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论