提交 b295b284 authored 作者: nouiz's avatar nouiz

Merge pull request #365 from delallea/minor

Minor stuff (PEP8 and typos mostly)
......@@ -468,17 +468,17 @@ class PureOp(object):
returns: a list of n elements
rval[i] should be Rop(f = f_i(inputs),
wrt = inputs,
eval_points = eval_points)
rval[i] should be Rop(f=f_i(inputs),
wrt=inputs,
eval_points=eval_points)
"""
raise NotImplementedError(str(self)+' of type '+str(self.__class__.__name__)
+" does not "
raise NotImplementedError(
"%s of class %s does not "
"implement R_op. If this is a theano op, write to the "
"theano-dev mailing list for assistance. If it is your "
"own op, implement the R_op method.")
"own op, implement the R_op method." %
(self, self.__class__.__name__))
def perform(self, node, inputs, output_storage):
......@@ -649,7 +649,7 @@ def debug_error_message(msg):
warnings.warn(msg, stacklevel=2)
def debug_assert(condition, msg = None):
def debug_assert(condition, msg=None):
if msg is None:
msg = 'debug_assert failed'
if not condition:
......
......@@ -317,7 +317,7 @@ def ifelse(condition, then_branch, else_branch, name=None):
# we will store them in these new_... lists.
new_then_branch = []
new_else_branch = []
for then_branch_elem, else_branch_elem in zip(then_branch, else_branch):
for then_branch_elem, else_branch_elem in izip(then_branch, else_branch):
if not isinstance(then_branch_elem, theano.Variable):
then_branch_elem = theano.tensor.as_tensor_variable(then_branch_elem)
if not isinstance(else_branch_elem, theano.Variable):
......@@ -341,12 +341,12 @@ def ifelse(condition, then_branch, else_branch, name=None):
if then_branch_elem.type != else_branch_elem.type:
# If the types still don't match, there is a problem.
raise ValueError(
('The two branches should have identical types, '
' but they are '+str(then_branch_elem.type)+' and '+
str(else_branch_elem.type)+' respectively. '
'This error could be raised if for example '
' you provided a one element list on the then '
' branch but a tensor on the else branch'))
'The two branches should have identical types, but '
'they are %s and %s respectively. This error could be '
'raised if for example you provided a one element '
'list on the `then` branch but a tensor on the `else` '
'branch.' %
(then_branch_elem.type, else_branch_elem.type))
new_then_branch.append(then_branch_elem)
new_else_branch.append(else_branch_elem)
......
......@@ -944,7 +944,7 @@ def min_informative_str(obj, indent_level=0,
obj: the name to convert to a string
indent_level: the number of tabs the tree should start printing at
(nested levels of the tree will get more tabs)
_prev_obs: should only be used to by min_informative_str
_prev_obs: should only be used by min_informative_str
a dictionary mapping previously converted
objects to short tags
......
......@@ -1298,11 +1298,12 @@ class Scan(PureOp):
else:
dim_offset = 0
if maxtap == mintap and maxtap != 0:
nw_seq =seq[:abs(maxtap)]
nw_seq = seq[:abs(maxtap)]
elif maxtap -k != 0 :
nw_seq = seq[dim_offset +k -mintap - 1: -(maxtap -k + 1)][::-1]
tmp = seq[dim_offset + k - mintap - 1:-(maxtap -k + 1)]
nw_seq = tmp[::-1]
else:
nw_seq = seq[dim_offset +k -mintap - 1: -1 ][::-1]
nw_seq = seq[dim_offset + k - mintap - 1: -1][::-1]
if getattr(seq,'name', None) is not None:
nw_seq.name = seq.name + '[%d:]'%k
scan_seqs.append(nw_seq)
......@@ -1593,7 +1594,7 @@ class Scan(PureOp):
# Outputs
n_mit_mot_outs = int(numpy.sum([len(x) for x in
self.mit_mot_out_slices]))
info['n_mit_mot_outs'] = n_mit_mot_outs*2
info['n_mit_mot_outs'] = n_mit_mot_outs * 2
b = 0
e = n_mit_mot_outs
inner_out_mit_mot = self_outputs[b:e] + rop_outs[b:e]
......
......@@ -687,16 +687,17 @@ class Elemwise(Op):
msg2 += [str(d)]
msg.append('(%s)' % ", ".join(msg2))
base_exc_str = 'Dimension mismatch; shapes are %s' % (', '.join(msg))
base_exc_str = 'Dimension mismatch; shapes are %s' % (
', '.join(msg))
if config.exception_verbosity == 'high':
msg_chunks = [ base_exc_str ]
msg_chunks = [base_exc_str]
for i, ipt in enumerate(node.inputs):
msg_chunks.append('input %d: %s' % (i, min_informative_str(ipt)))
msg_chunks.append('input %d: %s' %
(i, min_informative_str(ipt)))
raise ValueError('\n'.join(msg_chunks))
else:
raise ValueError(base_exc_str)
#', '.join('(%s)' % ', '.join(msg)))
#backport
#raise ValueError('Dimension mismatch; shapes are %s' %
# ', '.join('(%s)' % ', '.join('*' if b else str(d)
......
......@@ -28,13 +28,13 @@ def format_as(use_list, use_tuple, outputs):
"""
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`
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`
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.
"""
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:
return [outputs]
......@@ -94,8 +94,8 @@ def Rop(f, wrt, eval_points):
assert len(wrt) == len(eval_points)
#check that each element of wrt corresponds to an element
#of eval_points with the same dimensionality
# Check that each element of wrt corresponds to an element
# of eval_points with the same dimensionality.
for pack in enumerate(zip(wrt, eval_points)):
i = pack[0]
wrt_elem, eval_point = pack[1]
......@@ -701,14 +701,15 @@ class GradientError(Exception):
def __str__(self):
# args may have been inserted by e.g. makeTester
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,
abs. error = %f, abs. tolerance = %f
rel. error = %f, rel. tolerance = %f\nException args: %s
""" %(self.err_pos, self.arg,
self.abs_err, self.abs_tol,
self.rel_err, self.rel_tol,
args_msg)
rel. error = %f, rel. tolerance = %f
Exception args: %s""" % (self.err_pos, self.arg,
self.abs_err, self.abs_tol,
self.rel_err, self.rel_tol,
args_msg)
verify_grad.E_grad = GradientError
......@@ -789,8 +790,8 @@ def hessian(cost, wrt, consider_constant=None, warn_type=False,
disconnected_inputs='raise'):
"""
:type cost: Scalar (0-dimensional) `Variable`
:type wrt: Vector (1-dimensional tensors) 'Variable' or list of
vectors (1-dimensional tensors) `Variables`s
:type wrt: Vector (1-dimensional tensor) 'Variable' or list of
vectors (1-dimensional tensors) `Variable`s
:param consider_constant: a list of expressions not to backpropagate
through
......
......@@ -94,7 +94,7 @@ def test002_jacobian_matrix():
evx[dx, dx, :] = vx[dx, :]
evz[dx, dx, :] = vz[dx, :]
assert numpy.allclose(vJs[0], evz)
assert numpy.allclose(vJs[1 ], evx)
assert numpy.allclose(vJs[1], evx)
def test003_jacobian_scalar():
......@@ -117,7 +117,7 @@ def test003_jacobian_scalar():
# test when the jacobian is called with a list as wrt
Jx = tensor.jacobian(y, [x])
assert isinstance(Jx,list)
assert isinstance(Jx, list)
f = theano.function([x], Jx[0])
vx = numpy.cast[theano.config.floatX](rng.uniform())
assert numpy.allclose(f(vx), 2)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论