提交 77ad25de authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Fixed some typos + PEP8

上级 1cbe24c8
...@@ -28,13 +28,13 @@ def format_as(use_list, use_tuple, outputs): ...@@ -28,13 +28,13 @@ def format_as(use_list, use_tuple, outputs):
""" """
Formats the outputs according to the flags `use_list` and `use_tuple`. Formats the outputs according to the flags `use_list` and `use_tuple`.
If `use_list` is True, `outputs` is returned as a list (if `outputs` If `use_list` is True, `outputs` is returned as a list (if `outputs`
is not a list or a tuple then it is converted in a one element list) is not a list or a tuple then it is converted in a one element list).
If `use_tuple` is True, `outputs` is returned as a tuple (if `outputs` If `use_tuple` is True, `outputs` is returned as a tuple (if `outputs`
is not a list or a tuple then it is converted into a one element tuple) is not a list or a tuple then it is converted into a one element tuple).
Otherwise (if both flags are false), `outputs` is returned. Otherwise (if both flags are false), `outputs` is returned.
""" """
assert not (use_list and use_tuple), \ assert not (use_list and use_tuple), \
"Both flags can not be simultaneously True" "Both flags cannot be simultaneously True"
if (use_list or use_tuple) and not isinstance(outputs, (list, tuple)): if (use_list or use_tuple) and not isinstance(outputs, (list, tuple)):
if use_list: if use_list:
return [outputs] return [outputs]
...@@ -701,11 +701,12 @@ class GradientError(Exception): ...@@ -701,11 +701,12 @@ class GradientError(Exception):
def __str__(self): def __str__(self):
# args may have been inserted by e.g. makeTester # args may have been inserted by e.g. makeTester
args_msg = ", ".join(str(a) for a in self.args) args_msg = ", ".join(str(a) for a in self.args)
return """GradientError: numeric gradient and analytic gradient exceed tolerance: return """\
GradientError: numeric gradient and analytic gradient exceed tolerance:
At position %i of argument %i, At position %i of argument %i,
abs. error = %f, abs. tolerance = %f abs. error = %f, abs. tolerance = %f
rel. error = %f, rel. tolerance = %f\nException args: %s rel. error = %f, rel. tolerance = %f
""" %(self.err_pos, self.arg, Exception args: %s""" % (self.err_pos, self.arg,
self.abs_err, self.abs_tol, self.abs_err, self.abs_tol,
self.rel_err, self.rel_tol, self.rel_err, self.rel_tol,
args_msg) args_msg)
...@@ -789,8 +790,8 @@ def hessian(cost, wrt, consider_constant=None, warn_type=False, ...@@ -789,8 +790,8 @@ def hessian(cost, wrt, consider_constant=None, warn_type=False,
disconnected_inputs='raise'): disconnected_inputs='raise'):
""" """
:type cost: Scalar (0-dimensional) `Variable` :type cost: Scalar (0-dimensional) `Variable`
:type wrt: Vector (1-dimensional tensors) 'Variable' or list of :type wrt: Vector (1-dimensional tensor) 'Variable' or list of
vectors (1-dimensional tensors) `Variables`s vectors (1-dimensional tensors) `Variable`s
:param consider_constant: a list of expressions not to backpropagate :param consider_constant: a list of expressions not to backpropagate
through through
......
...@@ -94,7 +94,7 @@ def test002_jacobian_matrix(): ...@@ -94,7 +94,7 @@ def test002_jacobian_matrix():
evx[dx, dx, :] = vx[dx, :] evx[dx, dx, :] = vx[dx, :]
evz[dx, dx, :] = vz[dx, :] evz[dx, dx, :] = vz[dx, :]
assert numpy.allclose(vJs[0], evz) assert numpy.allclose(vJs[0], evz)
assert numpy.allclose(vJs[1 ], evx) assert numpy.allclose(vJs[1], evx)
def test003_jacobian_scalar(): def test003_jacobian_scalar():
...@@ -117,7 +117,7 @@ def test003_jacobian_scalar(): ...@@ -117,7 +117,7 @@ def test003_jacobian_scalar():
# test when the jacobian is called with a list as wrt # test when the jacobian is called with a list as wrt
Jx = tensor.jacobian(y, [x]) Jx = tensor.jacobian(y, [x])
assert isinstance(Jx,list) assert isinstance(Jx, list)
f = theano.function([x], Jx[0]) f = theano.function([x], Jx[0])
vx = numpy.cast[theano.config.floatX](rng.uniform()) vx = numpy.cast[theano.config.floatX](rng.uniform())
assert numpy.allclose(f(vx), 2) assert numpy.allclose(f(vx), 2)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论