提交 3089deda authored 作者: Bart van Merrienboer's avatar Bart van Merrienboer

Fix E261: at least two spaces before inline comment

上级 b34bc31d
......@@ -405,7 +405,7 @@ if sys.version_info[:2] < (2, 7):
for elem, count in iterable.iteritems():
self[elem] = self_get(elem, 0) + count
else:
dict.update(self, iterable) # fast path when counter is empty
dict.update(self, iterable) # fast path when counter is empty
else:
self_get = self.get
for elem in iterable:
......
......@@ -326,7 +326,7 @@ class BadDestroyMap(DebugModeError):
wasn't in the destroy_map"""
def __init__(self, node, idx, old_val, new_val, perform):
#super(BadDestroyMap, self).__init__()
DebugModeError.__init__(self)#to be compatible with python2.4
DebugModeError.__init__(self) # to be compatible with python2.4
self.node = node
self.idx = idx
self.old_val = old_val
......@@ -794,7 +794,7 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes,
# bad: there should only be one active node that destroys any variable
raise Exception('failure in topological ordering')
if clobber_dr_vals:
dr_vals[r] = (storage_map[r][0], node) #no copy, this is the last use of this variable
dr_vals[r] = (storage_map[r][0], node) # no copy, this is the last use of this variable
# make sure that dr_vals[r] doens't get used again
storage_map[r][0] = data_destroyed
else:
......@@ -887,7 +887,7 @@ def _check_strides_match(a, b, warn_err, op):
try:
strides_eq = a.strides == b.strides
except Exception:
return # no strides
return # no strides
if not strides_eq:
e = TypeError('Stride mismatch', (a.shape, b.shape, a.strides,
......@@ -1643,7 +1643,7 @@ class _Linker(gof.link.LocalLinker):
order_outputs.reverse()
order = graph.io_toposort(fgraph.inputs, order_outputs)
active_order = self.schedule(fgraph) # an ordering of just the active nodes
active_order = self.schedule(fgraph) # an ordering of just the active nodes
active_order_set = set(active_order)
# Disable no_recycling, in order to be able to use
......@@ -1999,7 +1999,7 @@ class _Linker(gof.link.LocalLinker):
raise InvalidValueError(r, storage_map[r][0], hint='c output')
if thunk_py:
assert r in r_vals #because we put it in during the thunk_py branch
assert r in r_vals # because we put it in during the thunk_py branch
# check for stride correctness (may raise exception)
_check_strides_match(r_vals[r],
storage_map[r][0],
......@@ -2032,7 +2032,7 @@ class _Linker(gof.link.LocalLinker):
#print >> sys.stderr, i, "DEBUGMODE storing reference output %x" % id(storage_map[r][0])
# retrieve each output from the storage_map
r_vals[r] = storage_map[r][0]
storage_map[r][0] = None #clear the storage_map for the thunk_c
storage_map[r][0] = None # clear the storage_map for the thunk_c
if self.maker.mode.check_preallocated_output:
prealloc_modes = \
......
......@@ -176,7 +176,7 @@ class AliasedMemoryError(Exception):
###
DUPLICATE = ['DUPLICATE'] # unique id object used as a placeholder for duplicate entries
DUPLICATE = ['DUPLICATE'] # unique id object used as a placeholder for duplicate entries
class Function(object):
"""
Type of the functions returned by theano.function or theano.FunctionMaker.create.
......@@ -320,7 +320,7 @@ class Function(object):
# Initialize the storage
# this loop works by modifying the elements (as variable c) of self.input_storage inplace.
for i, ((input, indices, sinputs), (required, refeed, value)) in enumerate(zip(self.indices, defaults)):
if indices is None: # this is true iff input is not a SymbolicInputKit
if indices is None: # this is true iff input is not a SymbolicInputKit
c = containers[0] #containers is being used as a stack. Here we pop off the next one.
c.strict = getattr(input, 'strict', False)
c.allow_downcast = getattr(input, 'allow_downcast', None)
......@@ -338,7 +338,7 @@ class Function(object):
c.value = value
c.required = required
c.implicit = input.implicit
c.provided = 0 # this is a count of how many times the input has been provided (reinitialized to 0 on __call__)
c.provided = 0 # this is a count of how many times the input has been provided (reinitialized to 0 on __call__)
finder[i] = c
finder[input.variable] = c
if input.name not in finder:
......@@ -726,7 +726,7 @@ def _pickle_Function(f):
# HACK to detect aliased storage.
# This is here because aliased relationships are not [currently] preserved across the pickle operation
if not (f.pickle_aliased_memory_strategy == 'ignore'):
all_data = input_storage + inputs_data # addition here means list append
all_data = input_storage + inputs_data # addition here means list append
for i, d_i in enumerate(all_data):
for j, d_j in enumerate(all_data):
if (i < j) and isinstance(d_i, numpy.ndarray) and isinstance(d_j, numpy.ndarray):
......
......@@ -402,7 +402,7 @@ class ProfileMode(Mode):
sop_time={}
sop_call={}
sop_op = {}
sop_cimpl={} #map each op class to Bool. True iff all applies were done in c.
sop_cimpl={} # map each op class to Bool. True iff all applies were done in c.
for a, t in op_time.items():
typ = type(a)
sop_time.setdefault(typ, 0)
......
......@@ -7,7 +7,7 @@ class CallCache(object):
self.filename = filename
try:
if filename is None:
raise IOError('bad filename') #just goes to except
raise IOError('bad filename') # just goes to except
f = open(filename, 'r')
self.cache = cPickle.load(f)
f.close()
......
......@@ -325,11 +325,11 @@ if 0:
fgraph.destroy_handler = self
self.fgraph = fgraph
self.destroyers = OrderedSet() #set of Apply instances with non-null destroy_map
self.destroyers = OrderedSet() # set of Apply instances with non-null destroy_map
self.view_i = {} # variable -> variable used in calculation
self.view_o = {} # variable -> set of variables that use this one as a direct input
# clients: how many times does an apply use a given variable
self.clients = {} # variable -> apply -> ninputs
self.clients = {} # variable -> apply -> ninputs
self.stale_droot = True
# IG: It's unclear if this is meant to be included in deployed code. It looks like
......@@ -725,11 +725,11 @@ class DestroyHandler(toolbox.Bookkeeper):
fgraph.destroy_handler = self
self.fgraph = fgraph
self.destroyers = OrderedSet() #set of Apply instances with non-null destroy_map
self.destroyers = OrderedSet() # set of Apply instances with non-null destroy_map
self.view_i = OrderedDict() # variable -> variable used in calculation
self.view_o = OrderedDict() # variable -> set of variables that use this one as a direct input
# clients: how many times does an apply use a given variable
self.clients = OrderedDict() # variable -> apply -> ninputs
self.clients = OrderedDict() # variable -> apply -> ninputs
self.stale_droot = True
self.debug_all_apps = OrderedSet()
......@@ -754,7 +754,7 @@ class DestroyHandler(toolbox.Bookkeeper):
if self.stale_droot:
droot = OrderedDict() # destroyed view + nonview variables -> foundation
impact = OrderedDict() # destroyed nonview variable -> it + all views of it
root_destroyer = OrderedDict() # root -> destroyer apply
root_destroyer = OrderedDict() # root -> destroyer apply
for app in self.destroyers:
for output_idx, input_idx_list in app.op.destroy_map.items():
......
......@@ -396,7 +396,7 @@ class FunctionGraph(utils.object2):
# then __prune__ is a no-op.
for output in node.outputs:
# Cannot prune an op which is an output or used somewhere
if self.clients(output) or output in self.outputs: #output in self.outputs or self.clients(output):
if self.clients(output) or output in self.outputs: # output in self.outputs or self.clients(output):
return
self.apply_nodes.remove(node)
self.variables.difference_update(node.outputs)
......
......@@ -685,7 +685,7 @@ class PerformLinker(LocalLinker):
f = streamline(fgraph, thunks, order, post_thunk_old_storage,
no_recycling=no_recycling)
f.allow_gc = self.allow_gc #HACK: this is a way of passing an arg to Function.__call__
f.allow_gc = self.allow_gc # HACK: this is a way of passing an arg to Function.__call__
add_clear_storage(f, computed, storage_map)
f.storage_map = storage_map
......
......@@ -142,10 +142,10 @@ class TestClone(X):
node = MyOp.make_node(r1, r2)
node2 = MyOp.make_node(node.outputs[0], r5)
_, new = clone([r1, r2, r5], node2.outputs, False)
assert node2.outputs[0].type == new[0].type and node2.outputs[0] is not new[0] # the new output is like the old one but not the same object
assert node2 is not new[0].owner # the new output has a new owner
assert new[0].owner.inputs[1] is r5 # the inputs are not copied
assert new[0].owner.inputs[0].type == node.outputs[0].type and new[0].owner.inputs[0] is not node.outputs[0] # check that we copied deeper too
assert node2.outputs[0].type == new[0].type and node2.outputs[0] is not new[0] # the new output is like the old one but not the same object
assert node2 is not new[0].owner # the new output has a new owner
assert new[0].owner.inputs[1] is r5 # the inputs are not copied
assert new[0].owner.inputs[0].type == node.outputs[0].type and new[0].owner.inputs[0] is not node.outputs[0] # check that we copied deeper too
def test_not_destructive(self):
# Checks that manipulating a cloned graph leaves the original unchanged.
......
......@@ -109,18 +109,18 @@ class TestPatternOptimizer:
def test_unification_1(self):
x, y, z = inputs()
e = op1(op2(x, x), z) # the arguments to op2 are the same
e = op1(op2(x, x), z) # the arguments to op2 are the same
g = Env([x, y, z], [e])
PatternOptimizer((op1, (op2, '1', '1'), '2'), # they are the same in the pattern
PatternOptimizer((op1, (op2, '1', '1'), '2'), # they are the same in the pattern
(op4, '2', '1')).optimize(g)
# So the replacement should occur
assert str(g) == "[Op4(z, x)]"
def test_unification_2(self):
x, y, z = inputs()
e = op1(op2(x, y), z) # the arguments to op2 are different
e = op1(op2(x, y), z) # the arguments to op2 are different
g = Env([x, y, z], [e])
PatternOptimizer((op1, (op2, '1', '1'), '2'), # they are the same in the pattern
PatternOptimizer((op1, (op2, '1', '1'), '2'), # they are the same in the pattern
(op4, '2', '1')).optimize(g)
# The replacement should NOT occur
assert str(g) == "[Op1(Op2(x, y), z)]"
......@@ -403,7 +403,7 @@ class TestEquilibrium(object):
PatternSub((op4, 'x', 'y'), (op1, 'x', 'y')),
PatternSub((op3, (op2, 'x', 'y')), (op4, 'x', 'y'))
],
max_use_ratio=1. / len(g.apply_nodes)) # each opt can only be applied once
max_use_ratio=1. / len(g.apply_nodes)) # each opt can only be applied once
opt.optimize(g)
finally:
_logger.setLevel(oldlevel)
......
......@@ -226,8 +226,8 @@ class PureType(object):
"""
Variable = graph.Variable #the type that will be created by call to make_variable.
Constant = graph.Constant #the type that will be created by call to make_constant
Variable = graph.Variable # the type that will be created by call to make_variable.
Constant = graph.Constant # the type that will be created by call to make_constant
def filter(self, data, strict=False, allow_downcast=None):
"""Required: Return data or an appropriately wrapped/converted data.
......
......@@ -71,7 +71,7 @@ class NotVariable(Variable):
self.name = name
self.not_options = not_options
class VariableInList: # not a subclass of Variable
class VariableInList: # not a subclass of Variable
"""
This special kind of variable is matched against a list and unifies
an inner Variable to an OrVariable of the values in the list. For
......@@ -341,9 +341,9 @@ def unify_walk(v, o, U):
"""
best_v = U[v]
if v is not best_v:
return unify_walk(o, best_v, U) # reverse argument order so if o is a Variable this block of code is run again
return unify_walk(o, best_v, U) # reverse argument order so if o is a Variable this block of code is run again
else:
return FALL_THROUGH # call the next version of unify_walk that matches the type signature
return FALL_THROUGH # call the next version of unify_walk that matches the type signature
################################
......@@ -415,9 +415,9 @@ def unify_merge(v, o, U):
"""
best_v = U[v]
if v is not best_v:
return unify_merge(o, best_v, U) # reverse argument order so if o is a Variable this block of code is run again
return unify_merge(o, best_v, U) # reverse argument order so if o is a Variable this block of code is run again
else:
return FALL_THROUGH # call the next version of unify_walk that matches the type signature
return FALL_THROUGH # call the next version of unify_walk that matches the type signature
################################
......
......@@ -13,7 +13,7 @@ if len(sys.argv)>1:
else:
dirs = os.listdir(theano.config.compiledir)
dirs = [os.path.join(theano.config.compiledir, d) for d in dirs]
keys = {} # key -> nb seen
keys = {} # key -> nb seen
mods = {}
for dir in dirs:
......@@ -49,13 +49,13 @@ if DISPLAY_DUPLICATE_KEYS:
if v > 1:
print "Duplicate key (%i copies): %s" % (v, cPickle.loads(k))
nbs_keys = {} # nb seen -> now many key
nbs_keys = {} # nb seen -> now many key
for val in keys.values():
nbs_keys.setdefault(val, 0)
nbs_keys[val]+=1
nbs_mod = {} # nb seen -> how many key
nbs_mod_to_key = {} #nb seen -> keys
nbs_mod = {} # nb seen -> how many key
nbs_mod_to_key = {} # nb seen -> keys
more_than_one = 0
for mod, kk in mods.iteritems():
val = len(kk)
......
......@@ -71,7 +71,7 @@ try:
cm_mat.on_host = 0
cm_mat.on_device = 1
cm_mat.is_trans = 0
cm_mat.owns_data = 0 # <-- note: cm_mat dosen't owe the data; x does. So x will delete it.
cm_mat.owns_data = 0 # <-- note: cm_mat dosen't owe the data; x does. So x will delete it.
# x.gpudata is a long. We need a pointer to a float. cast.
......@@ -80,12 +80,12 @@ try:
px = cudamat.CUDAMatrix(cm_mat)
px._base = x # x won't be __del__'ed as long as px is around.
px._base = x # x won't be __del__'ed as long as px is around.
px.mat_on_host = False # let cudamat know that we don't have a numpy
px.mat_on_host = False # let cudamat know that we don't have a numpy
# array attached.
return px
......
......@@ -63,7 +63,7 @@ try:
cm_mat.on_host = 0
cm_mat.on_device = 1
cm_mat.is_trans = 0
cm_mat.owns_data = 0 # <-- note: cm_mat dosen't owe the data; x does. So x will delete it.
cm_mat.owns_data = 0 # <-- note: cm_mat dosen't owe the data; x does. So x will delete it.
# x.gpudata is a long. We need a pointer to a float. cast.
......@@ -72,12 +72,12 @@ try:
px = cudamat.CUDAMatrix(cm_mat)
px._base = x # x won't be freed if the cudamat object isn't freed.
px._base = x # x won't be freed if the cudamat object isn't freed.
px.mat_on_host = False # let cudamat know that we don't have a numpy
px.mat_on_host = False # let cudamat know that we don't have a numpy
# array attached.
# Note how gnumpy tracks its cudamat objects: it moves things to the
......
......@@ -112,7 +112,7 @@ def run_mercurial_command(hg_command):
def parse_stdout_filelist(hg_out_filelist):
files = hg_out_filelist.split()
files = [f.strip(string.whitespace + "'") for f in files]
files = filter(operator.truth, files) # get rid of empty entries
files = filter(operator.truth, files) # get rid of empty entries
return files
def changed_files():
......@@ -221,14 +221,14 @@ def main(argv=None):
else:
# parsing succeeded, it is safe to check indentation
if not args.no_indentation:
was_clean = None # unknown
was_clean = None # unknown
# only calculate was_clean if it will matter to us
if args.incremental or args.incremental_with_patch:
if filename in changed_filenames:
old_file_contents = get_file_contents(filename, revision=parent_commit())
was_clean = get_correct_indentation_diff(old_file_contents, "") is None
else:
was_clean = True # by default -- it was newly added and thus had no prior problems
was_clean = True # by default -- it was newly added and thus had no prior problems
check_indentation = was_clean or not args.incremental
if check_indentation:
......
......@@ -60,6 +60,6 @@ def to_cudandarray(x):
for i in x.shape[::-1][:-1]:
strides.append(strides[-1]*i)
strides = tuple(strides[::-1])
ptr = int(x.gpudata) # in pycuda trunk, y.ptr also works, which is a little cleaner
ptr = int(x.gpudata) # in pycuda trunk, y.ptr also works, which is a little cleaner
z = cuda.from_gpu_pointer(ptr, x.shape, strides, x)
return z
......@@ -12,7 +12,7 @@ from theano.compat.six import StringIO
from theano.gradient import grad_undefined
from theano.scalar import Scalar
scal = scalar # somewhere scalar gets reassigned to be a function
scal = scalar # somewhere scalar gets reassigned to be a function
from theano.compat.python2x import all, any
......@@ -3415,7 +3415,7 @@ class GpuAlloc(GpuAllocEmpty):
# If the output is a constant, it will have to be deepcopied
# each time the function is called. So we do not fold.
return False
elif (#The following ops work inplace of their input id 0.
elif ( # The following ops work inplace of their input id 0.
client[1] == 0 and
isinstance(client[0].op, (
# Ops that will work inplace on the Alloc. So if they
......
......@@ -260,7 +260,7 @@ class NaiveAlgo(object):
, nodename + '_scalar_'
, get_str_list_logical_scalar(node, value_str='value0[%i]')
, ['ii_o%i_data[0]'%ipos for ipos, i in enumerate(node.outputs)]
, sub=dict(fail='return;')) #TODO: set a failure code somehow!!!
, sub=dict(fail='return;')) # TODO: set a failure code somehow!!!
print >> sio, " ", task_code
print >> sio, " }" * nd
......@@ -398,7 +398,7 @@ class NaiveAlgo(object):
, nodename + '_scalar_'
, ['i%i_data_%i[0]'%(ipos, d) for ipos, i in enumerate(node.inputs)]
, ['o%i_data_%i[0]'%(ipos, d) for ipos, i in enumerate(node.outputs)]
, sub=dict(fail='return;')) #TODO: set a failure code somehow!!!
, sub=dict(fail='return;')) # TODO: set a failure code somehow!!!
if nd == 4:
decl_shared_stride(n_in, n_out, nd)
......@@ -473,7 +473,7 @@ class NaiveAlgo(object):
#, ['i%i_data[i]'%ipos for ipos, i in enumerate(node.inputs)]
, get_str_list_logical_scalar(node, data_str='i%i_data[i]')
, ['o%i_data[i]'%ipos for ipos, i in enumerate(node.outputs)]
, sub=dict(fail='return;')) #TODO: set a failure code somehow!!!
, sub=dict(fail='return;')) # TODO: set a failure code somehow!!!
print >> sio, " ", task_code
print >> sio, " }"
print >> sio, "}"
......@@ -844,9 +844,9 @@ nd_collapse_[i]=0;
launch_General(nodename, scalar_op, i, self.sync)
print >> sio, " } break;"
print >> sio, "}"#end case
print >> sio, "}" # end case
print >> sio, "return -2;" # should not get to this point
print >> sio, "}"#end fct
print >> sio, "}" # end fct
# N.B. cudaGetLastError is called by c_code
return sio.getvalue()
......
......@@ -93,7 +93,7 @@ class Kouh2008(object):
p_unbounded = shared_uniform(low=-0.1, high=0.1, size=(n_out,), name='p')
q_unbounded = shared_uniform(low=-0.1, high=0.1, size=(n_out,), name='q')
r_unbounded = shared_uniform(low=-0.1, high=0.1, size=(n_out,), name='r')
k_unbounded = shared_uniform(low=-0.2, high=0.2, size=(n_out,), name='k') # biases
k_unbounded = shared_uniform(low=-0.2, high=0.2, size=(n_out,), name='k') # biases
p = tensor.nnet.sigmoid(p_unbounded) * e_range_mag + e_range_low
q = tensor.nnet.sigmoid(q_unbounded) * e_range_mag + e_range_low
......@@ -171,7 +171,7 @@ class Kouh2008(object):
rval = cls.new_expbounds(rng, x_list, n_out, dtype=dtype, params=f_list + b_list,
exponent_range=exponent_range)
rval.f_list = f_list
rval.input = input #add the input to the returned object
rval.input = input # add the input to the returned object
rval.filter_l1 = sum(abs(fi).sum() for fi in f_list)
rval.filter_l2_sqr = sum((fi**2).sum() for fi in f_list)
return rval
......@@ -210,18 +210,18 @@ class Kouh2008(object):
out_c_high = out_c_low + filter_shape[1]
out_tile = out_array[out_r_low:out_r_high, out_c_low:out_c_high, :]
if c % 3 == 0: # linear filter
if c % 3 == 0: # linear filter
if w_col < w.shape[1]:
out_tile[...] = pixel_range(w[:, w_col]).reshape(filter_shape+(1,))
w_col += 1
if c % 3 == 1: # E filters
if c % 3 == 1: # E filters
if w_col < w.shape[1]:
# filters after the 3rd do not get rendered, but are skipped over.
# there are only 3 colour channels.
for i in xrange(min(self.n_E_quadratic, 3)):
out_tile[:, :, i] = pixel_range(w[:, w_col+i]).reshape(filter_shape)
w_col += self.n_E_quadratic
if c % 3 == 2: # S filters
if c % 3 == 2: # S filters
if w_col < w.shape[1]:
# filters after the 3rd do not get rendered, but are skipped over.
# there are only 3 colour channels.
......@@ -244,7 +244,7 @@ class Config(object):
n_terms = 4
ft_lr_t0 = 3e-3
ft_t_decay = 0 # 50 * 5000 # (units of minibatches) by this N'th pass through the training set
ft_t_decay = 0 # 50 * 5000 # (units of minibatches) by this N'th pass through the training set
ft_lr_t_decay = 1e-3 # we will have this learning rate
ft_cost_classif_l1 = 0
ft_cost_classif_l2 = 0
......@@ -255,11 +255,11 @@ class Config(object):
ft_cost_in_l1_w = 0
ft_cost_in_l2_w = 0
ft_limit_iters = -1
ft_limit_walltime = 0 # in seconds 60*60*1 #1 hour
ft_limit_walltime = 0 # in seconds 60*60*1 #1 hour
ft_batchsize = 30
ft_epoch_len = 50000
ft_status_interval = 50 #property( lambda s:s.ft_epoch_len/s.ft_batchsize)
ft_status_interval = 50 # property( lambda s:s.ft_epoch_len/s.ft_batchsize)
ft_validation_interval = property( lambda s: s.ft_epoch_len/s.ft_batchsize)
ft_ntrain_limit = 0
ft_test_lag1 = True
......
......@@ -89,7 +89,7 @@ class CudaNdarraySharedVariable(_operators, SharedVariable):
return self.container.value
else:
return copy.deepcopy(self.container.value)
else: #return an ndarray
else: # return an ndarray
return numpy.asarray(self.container.value)
def set_value(self, value, borrow=False):
......@@ -129,7 +129,7 @@ class CudaNdarraySharedVariable(_operators, SharedVariable):
if not isinstance(value, numpy.ndarray):
# in case this is a cuda_ndarray, we copy it
value = copy.deepcopy(value)
self.container.value = value # this will copy a numpy ndarray
self.container.value = value # this will copy a numpy ndarray
def __getitem__(self, *args):
# Defined to explicitly use the implementation from `_operators`, since
......
......@@ -106,7 +106,7 @@ class DebugLinker(gof.WrapLinker):
fgraph = f.fgraph
for r in fgraph.variables:
if r.owner is None:
r.step = "value" # this will be overwritten if r is an input
r.step = "value" # this will be overwritten if r is an input
else:
r.step = None
r.value = None
......
......@@ -696,7 +696,7 @@ class GpuAlloc(HideC, Alloc):
# If the output is a constant, it will have to be deepcopied
# each time the function is called. So we do not fold.
return False
elif (#The following ops work inplace of their input id 0.
elif ( # The following ops work inplace of their input id 0.
client[1] == 0 and
isinstance(client[0].op, (
# Ops that will work inplace on the Alloc. So if they
......
......@@ -1048,7 +1048,7 @@ class GpuCAReduceCuda(HideC, CAReduceDtype):
else:
assert isinstance(self.scalar_op, (scal.Maximum,
scal.Minimum))
if self.pre_scalar_op: # TODO, multi_dtype!
if self.pre_scalar_op: # TODO, multi_dtype!
#dtype = node.inputs[0].dtype
dtype = 'float32'
......
......@@ -124,39 +124,39 @@ class test_GpuCAReduceCuda(test_GpuCAReduceCPY):
((1, 2), (1,)),
((100, 3, 1300), [1]),
((0,), [0]), ((5,), [0]),
((0, 0), [0, 1]), ((1, 0), [0, 1]), ((5, 4), [0, 1]), ((33, 31), [0, 1]), ((5, 4), [1]), ((5, 4), [0]),#need something bigger then 32 for some opt test.
((0, 0), [0, 1]), ((1, 0), [0, 1]), ((5, 4), [0, 1]), ((33, 31), [0, 1]), ((5, 4), [1]), ((5, 4), [0]), # need something bigger then 32 for some opt test.
((5, 4, 3), [0]), ((5, 4, 3), [1]), ((5, 4, 3), [0, 1]), ((5, 4, 3), [2]), ((5, 4, 3), [1, 2]), ((5, 4, 3), [0, 1, 2]),
((0, 0, 0, 0), [0, 1, 2, 3]),
((5, 4, 3, 20), [2, 3]), ((5, 4, 3, 2), [0, 1, 2, 3]), ((5, 4, 3, 2), [0, 2, 3]), ((5, 4, 3, 2), [1, 2, 3]),
# test shape bigger then 4096 on each dimension to make sure that we work correctly when we don't have enough thread/block in each dimensions
((4100, 3), [0]), ((3, 4101), [0]),#10
((1024, 33), [0]), ((33, 1024), [0]),#10
((1025, 33), [0]), ((33, 1025), [0]),#10
((4100, 3), [1]), ((3, 4101), [1]),#01
((1024, 33), [1]), ((33, 1024), [1]),#01
((1025, 33), [1]), ((33, 1025), [1]),#01
((4100, 3), [0, 1]), ((3, 4101), [0, 1]),#11
((1024, 33), [0, 1]), ((33, 1024), [0, 1]),#01
((1025, 33), [0, 1]), ((33, 1025), [0, 1]),#01
((4100, 4, 3), [0]), ((5, 4100, 3), [0]), ((5, 4, 4100), [0]), ((3, 65536, 1), [0]),#100
((4100, 4, 3), [1]), ((5, 4100, 3), [1]), ((5, 4, 4100), [1]),#010
((4100, 4, 3), [2]), ((5, 4100, 3), [2]), ((5, 4, 4100), [2]),#001
((4100, 4, 3), [0, 1]), ((5, 4100, 3), [0, 1]), ((5, 4, 4100), [0, 1]),#110
((4100, 4, 3), [1, 2]), ((5, 4100, 3), [1, 2]), ((5, 4, 4100), [1, 2]),#011
((4100, 3), [0]), ((3, 4101), [0]), # 10
((1024, 33), [0]), ((33, 1024), [0]), # 10
((1025, 33), [0]), ((33, 1025), [0]), # 10
((4100, 3), [1]), ((3, 4101), [1]), # 01
((1024, 33), [1]), ((33, 1024), [1]), # 01
((1025, 33), [1]), ((33, 1025), [1]), # 01
((4100, 3), [0, 1]), ((3, 4101), [0, 1]), # 11
((1024, 33), [0, 1]), ((33, 1024), [0, 1]), # 01
((1025, 33), [0, 1]), ((33, 1025), [0, 1]), # 01
((4100, 4, 3), [0]), ((5, 4100, 3), [0]), ((5, 4, 4100), [0]), ((3, 65536, 1), [0]), # 100
((4100, 4, 3), [1]), ((5, 4100, 3), [1]), ((5, 4, 4100), [1]), # 010
((4100, 4, 3), [2]), ((5, 4100, 3), [2]), ((5, 4, 4100), [2]), # 001
((4100, 4, 3), [0, 1]), ((5, 4100, 3), [0, 1]), ((5, 4, 4100), [0, 1]), # 110
((4100, 4, 3), [1, 2]), ((5, 4100, 3), [1, 2]), ((5, 4, 4100), [1, 2]), # 011
#((4100,4,3),[0,2]),((5,4100,3),[0,2]),((5,4,4100),[0,2]),#101 ##not implemented
((4100, 4, 3), [0, 1, 2]), ((5, 4100, 3), [0, 1, 2]), ((5, 4, 4100), [0, 1, 2]),#111
((65, 4, 3), [0, 1, 2]), ((5, 65, 3), [0, 1, 2]), ((5, 4, 65), [0, 1, 2]),#111
((4100, 4, 3, 2), [2, 3]), ((4, 4100, 3, 2), [2, 3]), ((4, 3, 4100, 2), [2, 3]), ((4, 3, 2, 4100), [2, 3]),#0011
((4100, 4, 3, 2), [1, 3]), ((4, 4100, 3, 2), [1, 3]), ((4, 3, 4100, 2), [1, 3]), ((4, 3, 2, 4100), [1, 3]),#0101
((4100, 4, 3, 2), [0, 2, 3]), ((4, 4100, 3, 2), [0, 2, 3]), ((4, 3, 4100, 2), [0, 2, 3]),#((4,3,2,4100),[0,2,3]),#1011
((4100, 4, 3, 2), [1, 2, 3]), ((4, 4100, 3, 2), [1, 2, 3]), ((4, 3, 4100, 2), [1, 2, 3]), ((4, 3, 2, 4100), [1, 2, 3]),#0111
((65, 4, 3, 2), [1, 2, 3]), ((4, 65, 3, 2), [1, 2, 3]), ((4, 3, 65, 2), [1, 2, 3]), ((4, 3, 2, 65), [1, 2, 3]),#0111
((4100, 2, 3, 4), [0, 1, 2, 3]), ((2, 4100, 3, 4), [0, 1, 2, 3]), ((2, 3, 4100, 4), [0, 1, 2, 3]), ((2, 3, 4, 4100), [0, 1, 2, 3]), ((128, 1, 2, 3), [0, 1, 2, 3]),#1111
((4100, 4, 3), [0, 1, 2]), ((5, 4100, 3), [0, 1, 2]), ((5, 4, 4100), [0, 1, 2]), # 111
((65, 4, 3), [0, 1, 2]), ((5, 65, 3), [0, 1, 2]), ((5, 4, 65), [0, 1, 2]), # 111
((4100, 4, 3, 2), [2, 3]), ((4, 4100, 3, 2), [2, 3]), ((4, 3, 4100, 2), [2, 3]), ((4, 3, 2, 4100), [2, 3]), # 0011
((4100, 4, 3, 2), [1, 3]), ((4, 4100, 3, 2), [1, 3]), ((4, 3, 4100, 2), [1, 3]), ((4, 3, 2, 4100), [1, 3]), # 0101
((4100, 4, 3, 2), [0, 2, 3]), ((4, 4100, 3, 2), [0, 2, 3]), ((4, 3, 4100, 2), [0, 2, 3]), # ((4,3,2,4100),[0,2,3]),#1011
((4100, 4, 3, 2), [1, 2, 3]), ((4, 4100, 3, 2), [1, 2, 3]), ((4, 3, 4100, 2), [1, 2, 3]), ((4, 3, 2, 4100), [1, 2, 3]), # 0111
((65, 4, 3, 2), [1, 2, 3]), ((4, 65, 3, 2), [1, 2, 3]), ((4, 3, 65, 2), [1, 2, 3]), ((4, 3, 2, 65), [1, 2, 3]), # 0111
((4100, 2, 3, 4), [0, 1, 2, 3]), ((2, 4100, 3, 4), [0, 1, 2, 3]), ((2, 3, 4100, 4), [0, 1, 2, 3]), ((2, 3, 4, 4100), [0, 1, 2, 3]), ((128, 1, 2, 3), [0, 1, 2, 3]), # 1111
# test pattern implemented by reshape
# Skip them as this test the op directly, not the optimization with reshape
......
......@@ -324,7 +324,7 @@ def no_transpose_symmetric(node):
@register_stabilize
@local_optimizer(None) # XXX: solve is defined later and can't be used here
@local_optimizer(None) # XXX: solve is defined later and can't be used here
def psd_solve_with_chol(node):
if node.op == solve:
A, b = node.inputs # result is solution Ax=b
......@@ -340,7 +340,7 @@ def psd_solve_with_chol(node):
@register_stabilize
@register_specialize
@local_optimizer(None) # XXX: det is defined later and can't be used here
@local_optimizer(None) # XXX: det is defined later and can't be used here
def local_det_chol(node):
"""
If we have det(X) and there is already an L=cholesky(X)
......
......@@ -184,7 +184,7 @@ def compile(smod, initial_values=None):
print p
reflected[thing] = p
else:
reflected[thing] = None #TODO: how to reflect derived resuls?
reflected[thing] = None # TODO: how to reflect derived resuls?
elif issymbolicmethod(thing):
reflected[thing] = compiled_functions[thing]
else :
......@@ -332,12 +332,12 @@ if 0:
x=T.dmatrix(), #our points, one point per row
w=T.dmatrix(), #first layer weights
b=T.dvector(), #first layer bias
**kwargs #other things from logistic_regression
**kwargs # other things from logistic_regression
):
hid = T.tanh(T.dot(x, w) + b)
if top_part:
print 'top_part', top_part, 'kwargs', kwargs
top = top_part(x=hid, **kwargs) # SymbolicModule
top = top_part(x=hid, **kwargs) # SymbolicModule
def params(): return top.params() + [w, b]
else:
def params(): return [w, b]
......@@ -353,7 +353,7 @@ if 0:
if 0:
class SymbolicModule(object):
name = "__no_name__" #name of this module
name = "__no_name__" # name of this module
variable_table = {} #map strings (names) to Variables
method_table = {} #map strings to compilable functions
......@@ -385,8 +385,8 @@ if 0:
b=T.dvector(), #first layer bias
v=T.dmatrix(), #second layer weights
c=T.dvector(), #second layer bias
step=T.dscalar(), #step size for gradient descent
l2_coef=T.dscalar() #l2 regularization amount
step=T.dscalar(), # step size for gradient descent
l2_coef=T.dscalar() # l2 regularization amount
):
"""Idea A:
"""
......
......@@ -19,7 +19,7 @@ class MyModule(TheanoObject):
super(MyModule, self).__init__()
self.a = self.symbolic_member(2)
self.b = self.symbolic_member(3)
self.c = 100 #a constant
self.c = 100 # a constant
self.d = [self.symbolic_member(5), self.symbolic_member(6)]
self.e = ['a', self.symbolic_member(6)]
......@@ -46,11 +46,11 @@ def test_outputs():
assert MM.add(5) == 12
assert MM.b.get() == 4
MM.sub(3)
assert MM.b.get() == 1 #test get()
assert MM.add(5) == 9 #test that b's container is shared between add and sub
MM.b.set(2) #test set
assert MM.b.get() == 2 #test get()
assert MM.add(5) == 10 #test that b's container is shared between add and sub
assert MM.b.get() == 1 # test get()
assert MM.add(5) == 9 # test that b's container is shared between add and sub
MM.b.set(2) # test set
assert MM.b.get() == 2 # test get()
assert MM.add(5) == 10 # test that b's container is shared between add and sub
@run(True)
def test_submodule():
......@@ -59,7 +59,7 @@ def test_submodule():
assert MM.add(5) == 8
MM.submodule.sub(7)
assert MM.submodule.b.get() == -3
assert MM.use_submodule(0) == -2 #self.a is 1 + self.submodule.b is -3
assert MM.use_submodule(0) == -2 # self.a is 1 + self.submodule.b is -3
@run(False)
......
......@@ -3162,7 +3162,7 @@ class Composite(ScalarOp):
res = theano.compile.rebuild_collect_shared(
inputs=inputs,
outputs=outputs[0].owner.inputs,
copy_inputs_over=False) # Clone also the inputs
copy_inputs_over=False) # Clone also the inputs
# 2. We continue this partial clone with the graph in
# the inner Composite
res2 = theano.compile.rebuild_collect_shared(
......
......@@ -1506,7 +1506,7 @@ class Scan(PureOp):
"""
output = []
outer_inp_idx = 1 # First outer input is timestep index, skip it
outer_inp_idx = 1 # First outer input is timestep index, skip it
# Handle sequences inputs
for i in range(self.info['n_seqs']):
......
......@@ -692,7 +692,7 @@ class PushOutScanOutput(gof.Optimizer):
outer_dot_inputs = [outer_vector_input,
outer_matrix_input.transpose()]
outer_dot_output = theano.tensor.dot(*outer_dot_inputs)
else: # idx_matrix_input == 1
else: # idx_matrix_input == 1
outer_dot_inputs = [outer_vector_input,
outer_matrix_input]
outer_dot_output = theano.tensor.dot(*outer_dot_inputs)
......@@ -725,7 +725,7 @@ class PushOutScanOutput(gof.Optimizer):
sitsot_in_idx = nd.inputs.index(args.inner_in_sit_sot[sitsot_idx])
dot_in_idx = 1 - sitsot_in_idx # 0 if sitsot_in_idx==1,
dot_in_idx = 1 - sitsot_in_idx # 0 if sitsot_in_idx==1,
# 1 if sitsot_in_idx==0
dot_input = nd.inputs[dot_in_idx]
......
......@@ -140,7 +140,7 @@ class TestSP(unittest.TestCase):
bsize = 10 # batch size
imshp = (8, 8)
kshp = (5, 5)
nkern = 1 # per output pixel
nkern = 1 # per output pixel
ssizes = ((1, 1), (2, 2))
convmodes = ('full', 'valid',)
......@@ -182,7 +182,7 @@ class TestSP(unittest.TestCase):
patch = numpy.zeros((kshp[0], kshp[1]))
for b in xrange(bsize):
for k in xrange(nkern):
pixi = 0 # pixel index in raster order
pixi = 0 # pixel index in raster order
for j in xrange(outshp[1]):
for i in xrange(outshp[2]):
n = j * ss[0]
......@@ -225,7 +225,7 @@ class TestSP(unittest.TestCase):
bsize = 10 # batch size
imshp = (5, 5)
kshp = ((3, 3), (2, 2))
nkerns = (10, 20) # per output pixel
nkerns = (10, 20) # per output pixel
ssizes = ((1, 1), (2, 2))
convmodes = ('full', 'valid',)
......@@ -263,9 +263,9 @@ class TestSP(unittest.TestCase):
bsize = 10 # batch size
imshp = (5, 5)
kshp = ((3, 3), (2, 2))
nkerns = (3, 6) # per output pixel
nkerns = (3, 6) # per output pixel
ssizes = (((1, 1), (2, 2)),)
convmodes = ('full',)#'valid',)
convmodes = ('full',) # 'valid',)
# symbolic stuff
kerns = [tensor.dmatrix(), tensor.dmatrix()]
......@@ -338,7 +338,7 @@ class TestSP(unittest.TestCase):
def test_CSMGrad(self):
imshp = (3, 3)
nkern = 1 # per output pixel
nkern = 1 # per output pixel
kshp = (2, 2)
#ssizes = ((1,1),(2,2))
ssizes = ((1, 1),)
......
......@@ -8,7 +8,7 @@ def make_declare(loop_orders, dtypes, sub):
decl = ""
for i, (loop_order, dtype) in enumerate(zip(loop_orders, dtypes)):
var = sub['lv%i' % i] # input name corresponding to ith loop variable
var = sub['lv%i' % i] # input name corresponding to ith loop variable
# we declare an iteration variable
# and an integer for the number of dimensions
decl += """
......@@ -229,7 +229,7 @@ def make_loop(loop_orders, dtypes, loop_tasks, sub, openmp=None):
preloops.setdefault(j, "")
preloops[j] += ("%%(lv%(i)s)s_iter = (%(dtype)s*)(PyArray_DATA(%%(lv%(i)s)s));\n" % locals()) % sub
break
else: # all broadcastable
else: # all broadcastable
preloops.setdefault(0, "")
preloops[0] += ("%%(lv%(i)s)s_iter = (%(dtype)s*)(PyArray_DATA(%%(lv%(i)s)s));\n" % locals()) % sub
......@@ -512,7 +512,7 @@ def make_loop_careduce(loop_orders, dtypes, loop_tasks, sub):
preloops.setdefault(j, "")
preloops[j] += ("%%(lv%(i)s)s_iter = (%(dtype)s*)(PyArray_DATA(%%(lv%(i)s)s));\n" % locals()) % sub
break
else: # all broadcastable
else: # all broadcastable
preloops.setdefault(0, "")
preloops[0] += ("%%(lv%(i)s)s_iter = (%(dtype)s*)(PyArray_DATA(%%(lv%(i)s)s));\n" % locals()) % sub
......
......@@ -89,9 +89,9 @@ def exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp, kshps, nkerns,
from scipy.signal.signaltools import _valfrommode, _bvalfromboundary
val = _valfrommode(conv_mode)
bval = _bvalfromboundary('fill')
for b in range(bsize): # loop over batches
for n in range(nkern): # loop over filters
for i in range(imshp[0]): # loop over input feature maps
for b in range(bsize): # loop over batches
for n in range(nkern): # loop over filters
for i in range(imshp[0]): # loop over input feature maps
outval[b, n, ...] += _convolve2d(\
imgval[b, i, ...], w_flip[n, i, ...], 1, val, bval, 0)[0::ss[0], 0::ss[1]]
ntot += time.time() - time1
......@@ -111,14 +111,14 @@ def exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp, kshps, nkerns,
time1 = time.time()
for i in range(repeat):
hidval2_ = propup2(imgval, w_flip)
hidval2 = hidval2_#[:,:,0::ss[0],0::ss[1]]
hidval2 = hidval2_ # [:,:,0::ss[0],0::ss[1]]
tctot += time.time() - time1
if conv_op_py:
time1 = time.time()
for i in range(repeat):
hidval3_ = propup3(imgval, w_flip)
hidval3 = hidval3_#[:,:,0::ss[0],0::ss[1]]
hidval3 = hidval3_ # [:,:,0::ss[0],0::ss[1]]
tpytot += time.time() - time1
assert (N.abs(hidval2-hidval3)<1e-5).all()
else:
......@@ -183,7 +183,7 @@ def exec_multilayer_conv_nnet(conv_mode, ss, bsize, imshp, kshps, nkerns,
time1 = time.time()
for i in range(repeat):
hidval2_ = propup2(imgval, w_flip)
hidval2 = hidval2_#[:,:,0::ss[0],0::ss[1]]
hidval2 = hidval2_ # [:,:,0::ss[0],0::ss[1]]
tctot += time.time() - time1
imshp = tuple(outshp)
......@@ -197,22 +197,22 @@ def speed_multilayer_conv():
# calculate the speed up of different combination of unroll
# put the paramter to the same you will try.
validate=False# we don't validate the result to have it much faster!
validate=False # we don't validate the result to have it much faster!
repeat = 3
verbose=1
unroll_batch = [1, 2, 3, 4, 5, 6, 10]#15, 30, 60 always much slower
unroll_kern = [1, 2, 3, 4, 5, 6, 10]#15, 30, 60 always much slower
unroll_batch = [1, 2, 3, 4, 5, 6, 10] # 15, 30, 60 always much slower
unroll_kern = [1, 2, 3, 4, 5, 6, 10] # 15, 30, 60 always much slower
#unroll_batch = [1,4,5]
#unroll_kern = [1,4,5]
#unroll_batch = [1,4]
#unroll_kern = [1,4]
unroll_patch = [True, False]
bsize = 60 # batch size
imshp_start = (1, 48, 48)#un square shape to test more corner case.
kshps = ([11, 12],)#un square shape to test more corner case.
nkerns = [60] # per output pixel
ssizes = [(1, 1), ]#(1,1)]#(2,2) bugged
bsize = 60 # batch size
imshp_start = (1, 48, 48) # un square shape to test more corner case.
kshps = ([11, 12],) # un square shape to test more corner case.
nkerns = [60] # per output pixel
ssizes = [(1, 1), ] # (1,1)]#(2,2) bugged
convmodes = ['valid', 'full']
do_convolve2=False
a=T.dmatrix()
......@@ -246,9 +246,9 @@ def speed_multilayer_conv():
if unroll_b==1 and unroll_k==1:
# print "unroll 1/1",tctot
worst=tctot
timing[n_b, n_k]=[tctot, tpytot, ntot]#[sum(tctot), sum(tpytot), sum(ntot)]
timing[n_b, n_k]=[tctot, tpytot, ntot] # [sum(tctot), sum(tpytot), sum(ntot)]
if not t_:
t=timing[:, :, 0, :]#We select only the c timing.
t=timing[:, :, 0, :] # We select only the c timing.
else:
t=t_
t=N.asarray(t)
......
......@@ -1137,7 +1137,7 @@ def test_argmax_pushdown():
# print 'AFTER'
# for node in fgraph.toposort():
# print node.op
assert len(fgraph.toposort()) == 4 # an output_guard is second
assert len(fgraph.toposort()) == 4 # an output_guard is second
assert isinstance(fgraph.toposort()[0].op, tensor.Elemwise)
assert isinstance(fgraph.toposort()[1].op, Softmax)
assert isinstance(fgraph.toposort()[2].op, tensor.CAReduce)
......
......@@ -245,8 +245,8 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
stridesizes = [(2, 2), (2, 2), (1, 1), (1, 2), (2, 2)]
paddingsizes = [(2, 2), (1, 2), (2, 1), (0, 0), (1, 1)]
imgsizes = [(5, 5), (5, 5), (5, 6), (6, 5), (5, 5)]
m = 4 # minibatch
c = 10 # channel size
m = 4 # minibatch
c = 10 # channel size
images = tensor.dtensor4()
for indx in numpy.arange(len(maxpoolsizes)):
imgsize = imgsizes[indx]
......
......@@ -269,7 +269,7 @@ def test_mlp():
# allocate symbolic variables for the data
index = T.lscalar() # index to a [mini]batch
x = T.matrix('x') # the data is presented as rasterized images
y = T.ivector('y') # the labels are presented as 1D vector of
y = T.ivector('y') # the labels are presented as 1D vector of
# [int] labels
rng = numpy.random.RandomState(1234)
......
......@@ -43,19 +43,19 @@ class TestScipyGer(TestCase, TestOptimizationMixin):
f = self.function([self.A, self.x, self.y],
self.A + tensor.outer(self.x, self.y))
self.assertFunctionContains(f, ScipyGer(destructive=False))
self.run_f(f) #DebugMode tests correctness
self.run_f(f) # DebugMode tests correctness
def test_A_plus_scaled_outer(self):
f = self.function([self.A, self.x, self.y],
self.A + 0.1 * tensor.outer(self.x, self.y))
self.assertFunctionContains(f, ScipyGer(destructive=False))
self.run_f(f) #DebugMode tests correctness
self.run_f(f) # DebugMode tests correctness
def test_scaled_A_plus_scaled_outer(self):
f = self.function([self.A, self.x, self.y],
0.2 * self.A + 0.1 * tensor.outer(self.x, self.y))
self.assertFunctionContains(f, gemm_no_inplace)
self.run_f(f) #DebugMode tests correctness
self.run_f(f) # DebugMode tests correctness
class TestBlasStridesScipy(TestBlasStrides):
mode = theano.compile.get_default_mode()
......
......@@ -53,8 +53,8 @@ def test_mpi_send_wait_cmp():
waitnode = y.owner
sendnode = y.owner.inputs[0].owner
addnode = z.owner
assert mpi_send_wait_cmp(sendnode, addnode) < 0 # send happens first
assert mpi_send_wait_cmp(waitnode, addnode) > 0 # wait happens last
assert mpi_send_wait_cmp(sendnode, addnode) < 0 # send happens first
assert mpi_send_wait_cmp(waitnode, addnode) > 0 # wait happens last
def test_mpi_tag_ordering():
x = recv((2, 2), 'float32', 1, 12)
......
......@@ -983,12 +983,12 @@ class test_fusion(unittest.TestCase):
(fx-theano.tensor.true_div(fy, fz), (fx, fy, fz), (fxv,
fyv, fzv), 1, fxv-(fyv/fzv), 'float32'),
(fx-theano.tensor.int_div(ix*100, iy*1000), (fx, ix,
iy), (fxv, ixv, iyv), 1, fxv-((ixv*100)//(iyv*1000)), {'custom': 'float64', 'numpy+floatX': config.floatX, 'numpy': 'float64'}), #40
iy), (fxv, ixv, iyv), 1, fxv-((ixv*100)//(iyv*1000)), {'custom': 'float64', 'numpy+floatX': config.floatX, 'numpy': 'float64'}), # 40
(fx-(fy/2), (fx, fy), (fxv, fyv), 1, fxv-(fyv/2), 'float32'),
(fx-(fy%fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(fyv%fzv), 'float32'),
(fx-(fy>fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(fyv>fzv), 'float32'),
(fx-(fy>=fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(fyv>=fzv), 'float32'),
(fx-(fy<fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(fyv<fzv), 'float32'),#45
(fx-(fy<fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(fyv<fzv), 'float32'), # 45
(fx-(fy<=fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(fyv<=fzv), 'float32'),
(fx-T.eq(fy, fz), (fx, fy, fz), (fxv, fyv, fzv), 1, fxv-(
fyv==fzv), 'float32'),
......@@ -997,7 +997,7 @@ class test_fusion(unittest.TestCase):
(fx-fy+tensor.tan(fz), (fx, fy, fz), (fxv, fyv, fzv), 1,
fxv-fyv+numpy.tan(fzv), 'float32'),
(fx-fy+tensor.tanh(fz), (fx, fy, fz), (fxv, fyv, fzv), 1,
fxv-fyv+numpy.tanh(fzv), 'float32'),#50
fxv-fyv+numpy.tanh(fzv), 'float32'), # 50
(fx-fy+tensor.sin(fz), (fx, fy, fz), (fxv, fyv, fzv), 1,
fxv-fyv+numpy.sin(fzv), 'float32'),
(fx-fy+tensor.sinh(fz), (fx, fy, fz), (fxv, fyv, fzv), 1,
......@@ -1007,7 +1007,7 @@ class test_fusion(unittest.TestCase):
(fx-fy+theano.tensor.sqrt(fz), (fx, fy, fz), (fxv, fyv,
fzv), 1, fxv-fyv+numpy.sqrt(fzv), 'float32'),
(fx-fy+theano.tensor.inv(fz), (fx, fy, fz), (fxv, fyv,
fzv), 1, fxv-fyv+(1/fzv), 'float32'),#55
fzv), 1, fxv-fyv+(1/fzv), 'float32'), # 55
(fx-fy+theano.tensor.neg(fz), (fx, fy, fz), (fxv, fyv,
fzv), 1, fxv-fyv+(-fzv), 'float32'),
(fx-fy+theano.tensor.round(fz), (fx, fy, fz), (fxv, fyv,
......@@ -1018,7 +1018,7 @@ class test_fusion(unittest.TestCase):
(fx-theano.tensor.or_(iy, iz), (fx, iy, iz), (fxv, iyv,
izv), 1, fxv-(iyv|izv), {'custom': 'float64', 'numpy+floatX': config.floatX, 'numpy': 'float64'}),
(fx-theano.tensor.xor(iy, iz), (fx, iy, iz), (fxv, iyv,
izv), 1, fxv-(iyv^izv), {'custom': 'float64', 'numpy+floatX': config.floatX, 'numpy': 'float64'}),#60
izv), 1, fxv-(iyv^izv), {'custom': 'float64', 'numpy+floatX': config.floatX, 'numpy': 'float64'}), # 60
(fx-theano.tensor.and_(iy, iz), (fx, iy, iz), (fxv, iyv,
izv), 1, fxv-(iyv&izv), {'custom': 'float64', 'numpy+floatX': config.floatX, 'numpy': 'float64'}),
(fx-theano.tensor.invert(iy), (fx, iy), (fxv, iyv), 1,
......@@ -1029,9 +1029,9 @@ class test_fusion(unittest.TestCase):
(theano.tensor.pow(fx*fy+fz, fx*fy), (fx, fy, fz), (fxv,
fyv, fzv), 1, numpy.power(fxv*fyv+fzv, fxv*fyv), 'float32'),
(fv+fy**fz, (fv, fy, fz), (fvv, fyv, fzv), 2, fvv+fyv**fzv,
'float32'),#fused with a dimshuffle #65
'float32'), # fused with a dimshuffle #65
(fv-fy+tensor.tanh(fz), (fv, fy, fz), (fvv, fyv, fzv), 2,
fvv-fyv+numpy.tanh(fzv), 'float32'),#fused with a dimshuffle
fvv-fyv+numpy.tanh(fzv), 'float32'), # fused with a dimshuffle
# Cases where the same input is reused many times.
(theano.tensor.mul(fx, fx, fx, fx), (fx,), (fxv,), 1, fxv*
......@@ -1041,7 +1041,7 @@ class test_fusion(unittest.TestCase):
(theano.tensor.mul(fx, ftanx, ftanx, fx), (fx,), (fxv,),
1, fxv*numpy.tan(fxv)*numpy.tan(fxv)*fxv, 'float32'),
(theano.tensor.mul(ftanx, ftanx, fx+fy), (fx, fy), (fxv,
fyv), 1, numpy.tan(fxv)*numpy.tan(fxv)*(fxv+fyv), 'float32'), # 70
fyv), 1, numpy.tan(fxv)*numpy.tan(fxv)*(fxv+fyv), 'float32'), # 70
# Cases with different broadcast pattern. They should not
# be merged as this would duplicate computation
......
......@@ -43,7 +43,7 @@ class T_SharedRandomStreams(unittest.TestCase):
gn_val0 = gn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
# print fn_val0
numpy_val0 = rng.uniform(size=(2, 2))
......@@ -86,7 +86,7 @@ class T_SharedRandomStreams(unittest.TestCase):
random.seed(utt.fetch_seed())
rng = numpy.random.RandomState()
rng.set_state(random[out.rng].get_state()) #tests getitem
rng.set_state(random[out.rng].get_state()) # tests getitem
fn_val0 = fn()
fn_val1 = fn()
......@@ -143,7 +143,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
numpy_val0 = rng.uniform(-1, 1, size=(2, 2))
numpy_val1 = rng.uniform(-1, 1, size=(2, 2))
......@@ -160,7 +160,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
numpy_val0 = rng.normal(-1, 2, size=(2, 2))
numpy_val1 = rng.normal(-1, 2, size=(2, 2))
......@@ -176,7 +176,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
numpy_val0 = rng.random_integers(-5, 5, size=(20, 20))
numpy_val1 = rng.random_integers(-5, 5, size=(20, 20))
......@@ -198,7 +198,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
numpy_val0 = rng.choice(10, (11, 8), True, None)
numpy_val1 = rng.choice(10, (11, 8), True, None)
......@@ -215,7 +215,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
numpy_val0 = rng.poisson(lam=5, size=(11, 8))
numpy_val1 = rng.poisson(lam=5, size=(11, 8))
......@@ -232,7 +232,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
# rng.permutation outputs one vector at a time, so we iterate.
numpy_val0 = numpy.asarray([rng.permutation(10) for i in range(20)])
......@@ -251,7 +251,7 @@ class T_SharedRandomStreams(unittest.TestCase):
fn_val1 = fn()
rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
rng = numpy.random.RandomState(int(rng_seed)) # int() is for 32bit
numpy_val0 = rng.multinomial(1, [0.1]*10, size=(4, 4))
numpy_val1 = rng.multinomial(1, [0.1]*10, size=(4, 4))
......@@ -419,7 +419,7 @@ class T_SharedRandomStreams(unittest.TestCase):
assert numpy.allclose(val0, numpy_val0)
assert numpy.allclose(val1, numpy_val1)
for i in range(10): # every test has 50% chance of passing even with non-matching random states
for i in range(10): # every test has 50% chance of passing even with non-matching random states
val2 = g()
numpy_val2 = multinomial_rng.multinomial(n=1, pvals=[.5, .5])
assert numpy.all(val2 == numpy_val2)
......
......@@ -97,7 +97,7 @@ def makeSharedTester(shared_constructor_,
values_to_div = .5
if self.op_by_matrix:
values_to_div = self.internal_type(numpy.ones(x.shape, dtype=dtype)/2)#supported for cudandarray, but not ndarray.
values_to_div = self.internal_type(numpy.ones(x.shape, dtype=dtype)/2) # supported for cudandarray, but not ndarray.
assert self.test_internal_type(values_to_div)
x /= values_to_div
total_val_2 = total_func()
......@@ -193,7 +193,7 @@ def makeSharedTester(shared_constructor_,
# supported for cudandarray, but not ndarray.
values_to_div = self.internal_type(
numpy.ones(x.shape, dtype=dtype)/2)
x /= values_to_div#supported by ndarray and CudaNdarray
x /= values_to_div # supported by ndarray and CudaNdarray
# this is not required by the contract but it is a feature we can
# implement for some type of SharedVariable.
......@@ -202,7 +202,7 @@ def makeSharedTester(shared_constructor_,
x = x_shared.get_value(borrow=False, return_internal_type=True)
assert self.test_internal_type(x)
assert x is not x_shared.container.value
x /= values_to_div#supported by ndarray and CudaNdarray
x /= values_to_div # supported by ndarray and CudaNdarray
# this is required by the contract
assert not numpy.allclose(self.ref_fct(x), total_func())
......@@ -251,7 +251,7 @@ def makeSharedTester(shared_constructor_,
# test if that theano shared variable optimize set_value(borrow=True)
get_x = x_shared.get_value(borrow=True)
assert get_x is not x_orig#borrow=False to shared_constructor
assert get_x is not x_orig # borrow=False to shared_constructor
get_x /= values_to_div
x_shared.set_value(get_x, borrow=True)
x = x_shared.get_value(borrow=True)
......@@ -263,10 +263,10 @@ def makeSharedTester(shared_constructor_,
# test optimized get set value on the gpu(don't pass data to the cpu)
get_x = x_shared.get_value(borrow=True, return_internal_type=True)
assert get_x is not x_orig#borrow=False to shared_constructor
assert get_x is not x_orig # borrow=False to shared_constructor
assert self.test_internal_type(get_x)
get_x /= values_to_div#supported by ndarray and CudaNdarray
get_x /= values_to_div # supported by ndarray and CudaNdarray
assert self.test_internal_type(get_x)
x_shared.set_value(get_x, borrow=True)
x = x_shared.get_value(borrow=True, return_internal_type=True)
......@@ -316,7 +316,7 @@ def makeSharedTester(shared_constructor_,
if dtype is None:
dtype = theano.config.floatX
shp = (100/4, 1024)#100KB
shp = (100/4, 1024) # 100KB
x = numpy.zeros(shp, dtype=dtype)
x = self.cast_value(x)
......
......@@ -461,7 +461,7 @@ class T_extending(unittest.TestCase):
# This should be needed for the EquilibriumOptimizer
# but it isn't now
# TODO: do this and explain it
return [] # that's not what you should do
return [] # that's not what you should do
local_simplify = LocalSimplify()
......@@ -775,8 +775,8 @@ class T_examples(unittest.TestCase):
# Construct Theano expression graph
p_1 = 1 / (1 + T.exp(-T.dot(x, w) - b)) # Probability that target = 1
prediction = p_1 > 0.5 # The prediction thresholded
xent = -y * T.log(p_1) - (1-y) * T.log(1-p_1) # Cross-entropy loss function
cost = xent.mean() + 0.01 * (w ** 2).sum()# The cost to minimize
xent = -y * T.log(p_1) - (1-y) * T.log(1-p_1) # Cross-entropy loss function
cost = xent.mean() + 0.01 * (w ** 2).sum() # The cost to minimize
gw, gb = T.grad(cost, [w, b]) # Compute the gradient of the cost
# (we shall return to this in a
# following section of this tutorial)
......@@ -817,7 +817,7 @@ class T_aliasing(unittest.TestCase):
s_false = theano.shared(np_array, borrow=False)
s_true = theano.shared(np_array, borrow=True)
np_array += 1 # now it is an array of 2.0 s
np_array += 1 # now it is an array of 2.0 s
assert numpy.all(s_default.get_value() == array([1.0, 1.0]))
assert numpy.all(s_false.get_value() == array([1.0, 1.0]))
......@@ -831,7 +831,7 @@ class T_aliasing(unittest.TestCase):
s = theano.shared(np_array)
v_false = s.get_value(borrow=False) # N.B. borrow default is False
v_false = s.get_value(borrow=False) # N.B. borrow default is False
v_true = s.get_value(borrow=True)
v_internal = s.get_value(borrow=True, return_internal_type=True)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论