提交 9ed2de83 authored 作者: Frederic's avatar Frederic

pep8

上级 c4a93fe3
...@@ -64,6 +64,7 @@ def make_constant(args): ...@@ -64,6 +64,7 @@ def make_constant(args):
return a return a
return tuple(map(conv, args)) return tuple(map(conv, args))
def get_idx_list(inputs, idx_list): def get_idx_list(inputs, idx_list):
''' '''
Given a list of inputs to the subtensor and its idx_list reorders Given a list of inputs to the subtensor and its idx_list reorders
...@@ -395,6 +396,7 @@ class Subtensor(Op): ...@@ -395,6 +396,7 @@ class Subtensor(Op):
NotScalarConstantError: v NotScalarConstantError: v
""" """
real_idx = get_idx_list(inputs, self.idx_list) real_idx = get_idx_list(inputs, self.idx_list)
def conv(val): def conv(val):
if val is None: if val is None:
return None return None
...@@ -441,7 +443,8 @@ class Subtensor(Op): ...@@ -441,7 +443,8 @@ class Subtensor(Op):
raise exception raise exception
input_types = Subtensor.collapse(idx_list, input_types = Subtensor.collapse(idx_list,
lambda entry: isinstance(entry, gof.Type)) lambda entry: isinstance(entry,
gof.Type))
if len(inputs) != len(input_types): if len(inputs) != len(input_types):
raise IndexError( raise IndexError(
"Not enough inputs to fill in the Subtensor template.", "Not enough inputs to fill in the Subtensor template.",
...@@ -693,7 +696,7 @@ class Subtensor(Op): ...@@ -693,7 +696,7 @@ class Subtensor(Op):
npy_intp xview_dims[%(view_ndim)s]; npy_intp xview_dims[%(view_ndim)s];
npy_intp xview_strides[%(view_ndim)s]; npy_intp xview_strides[%(view_ndim)s];
"""% locals() """ % locals()
else: else:
rval = """ rval = """
// Argument of the view // Argument of the view
...@@ -987,7 +990,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False, ...@@ -987,7 +990,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
if y.ndim > x.ndim: if y.ndim > x.ndim:
raise TypeError(("Trying to increment a %d-dimensional " raise TypeError(("Trying to increment a %d-dimensional "
"subtensor with a %d-dimensional value.") % (x.ndim, y.ndim)) "subtensor with a %d-dimensional value.") % (x.ndim,
y.ndim))
for dim in range(y.ndim): for dim in range(y.ndim):
dim_offset = x.ndim - y.ndim dim_offset = x.ndim - y.ndim
...@@ -1042,7 +1046,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False, ...@@ -1042,7 +1046,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
# return something that has the same shape as x, not as x.T (inner_x). # return something that has the same shape as x, not as x.T (inner_x).
# So re-apply the outer dimshuffle on the new inc_subtensor, # So re-apply the outer dimshuffle on the new inc_subtensor,
# and return advanced_inc_subtensor1(x.T, i, y).T. # and return advanced_inc_subtensor1(x.T, i, y).T.
inner_incsubtensor = inc_subtensor(inner_x, y, inner_incsubtensor = inc_subtensor(
inner_x, y,
inplace=inplace, inplace=inplace,
set_instead_of_inc=set_instead_of_inc, set_instead_of_inc=set_instead_of_inc,
tolerate_inplace_aliasing=tolerate_inplace_aliasing) tolerate_inplace_aliasing=tolerate_inplace_aliasing)
...@@ -1052,7 +1057,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False, ...@@ -1052,7 +1057,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
# Try to apply inc_subtensor on inner_x. # Try to apply inc_subtensor on inner_x.
# If it works, there is no need to reshape, as the inc_subtensor # If it works, there is no need to reshape, as the inc_subtensor
# will have the same shape as inner_x, which is what we want. # will have the same shape as inner_x, which is what we want.
inner_incsubtensor = inc_subtensor(inner_x, y.flatten(), inner_incsubtensor = inc_subtensor(
inner_x, y.flatten(),
inplace=inplace, inplace=inplace,
set_instead_of_inc=set_instead_of_inc, set_instead_of_inc=set_instead_of_inc,
tolerate_inplace_aliasing=tolerate_inplace_aliasing) tolerate_inplace_aliasing=tolerate_inplace_aliasing)
...@@ -1138,8 +1144,8 @@ class IncSubtensor(Op): ...@@ -1138,8 +1144,8 @@ class IncSubtensor(Op):
x, y = map(theano.tensor.as_tensor_variable, [x, y]) x, y = map(theano.tensor.as_tensor_variable, [x, y])
if y.ndim > x.ndim: if y.ndim > x.ndim:
raise ValueError(("Trying to increment a %d-dimensional " raise ValueError(("Trying to increment a %d-dimensional "
"subtensor with a %d-dimensional value.") % (x.ndim, "subtensor with a %d-dimensional value.") % (
y.ndim)) x.ndim, y.ndim))
inputs = tuple(map(Subtensor.my_as_scalar, inputs)) inputs = tuple(map(Subtensor.my_as_scalar, inputs))
idx_list = list(self.idx_list) idx_list = list(self.idx_list)
...@@ -1151,7 +1157,8 @@ class IncSubtensor(Op): ...@@ -1151,7 +1157,8 @@ class IncSubtensor(Op):
exception.subtensor_invalid = True exception.subtensor_invalid = True
raise exception raise exception
input_types = Subtensor.collapse(idx_list, input_types = Subtensor.collapse(
idx_list,
lambda entry: isinstance(entry, gof.Type)) lambda entry: isinstance(entry, gof.Type))
if len(inputs) != len(input_types): if len(inputs) != len(input_types):
raise IndexError( raise IndexError(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论