提交 29ea70d6 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Remove import of unittest_tools in basic.py. tensor.verify_grad now needs to be passed a valid rng.

上级 488246bf
...@@ -3548,7 +3548,7 @@ class numeric_grad: ...@@ -3548,7 +3548,7 @@ class numeric_grad:
def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast_to_output_type=False): def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast_to_output_type=False):
""" WRITEME """ WRITEME
Raises an Exception if the difference between the analytic gradient and Raises an Exception if the difference between the analytic gradient and
numerical gradient (computed through the Finite Difference Method) exceeds numerical gradient (computed through the Finite Difference Method) exceeds
the given tolerance. the given tolerance.
...@@ -3565,7 +3565,7 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast ...@@ -3565,7 +3565,7 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast
try to make it a SMALL graph. Often verify grad is run in try to make it a SMALL graph. Often verify grad is run in
debug mode, which can be very slow if it has to verify a lot debug mode, which can be very slow if it has to verify a lot
of intermediate computations. of intermediate computations.
""" """
pt = [numpy.array(p) for p in pt] pt = [numpy.array(p) for p in pt]
...@@ -3577,9 +3577,8 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast ...@@ -3577,9 +3577,8 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast
tol = __builtin__.max(_type_tol[str(p.dtype)] for p in pt) tol = __builtin__.max(_type_tol[str(p.dtype)] for p in pt)
if rng is None: if rng is None:
rng = numpy.random raise TypeError('rng should be a valid instance of numpy.random.RandomState.',
from theano import tests as theano_tests # TODO This is an ugly import. Fix? 'You may want to use theano.tests.unittest_tools.verify_grad instead of theano.tensor.verify_grad.')
theano_tests.unittest_tools.seed_rng()
def function(inputs, output): def function(inputs, output):
if mode is None: if mode is None:
...@@ -3591,9 +3590,9 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast ...@@ -3591,9 +3590,9 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast
for test_num in xrange(n_tests): for test_num in xrange(n_tests):
tensor_pt = [value(p.copy(), name='input %i'%i) for i,p in enumerate(pt)] tensor_pt = [value(p.copy(), name='input %i'%i) for i,p in enumerate(pt)]
#op can be either a function or an actual Op instance #op can be either a function or an actual Op instance
o_output = op(*tensor_pt) o_output = op(*tensor_pt)
if isinstance(o_output,list) > 1: if isinstance(o_output,list) > 1:
raise NotImplementedError('cant (yet) autotest gradient of op with multiple outputs') raise NotImplementedError('cant (yet) autotest gradient of op with multiple outputs')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论