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

Fix E261: at least two spaces before inline comment

上级 b34bc31d
......@@ -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:
......@@ -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 = \
......
......@@ -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)
......
......@@ -36,7 +36,7 @@ def checkfor(testcase, fn, E):
class T_function(unittest.TestCase):
def test_none(self):
fn = function([], None) #ok
fn = function([], None) # ok
rval = fn()
if rval == []:
raise KnownFailureTest('See #254: Using None as function output leads to [] return value')
......@@ -44,7 +44,7 @@ class T_function(unittest.TestCase):
assert rval is None
def test_empty(self):
fn = function([], []) #ok
fn = function([], []) # ok
self.assertTrue(fn() == [])
def test_extra_inputs(self):
......@@ -122,9 +122,9 @@ class T_function(unittest.TestCase):
self.assertTrue(f(s=2, x=1) == 0.5)
self.assertTrue(f(x=2, s=1) == 2.0)
self.assertTrue(f(2, s=1) == 2.0)
checkfor(self, lambda : f(2, x=2.0), TypeError) #got multiple values for keyword argument 'x'
checkfor(self, lambda : f(x=1), TypeError) #takes exactly 2 non-keyword arguments (1 given)
checkfor(self, lambda : f(s=1), TypeError) #takes exactly 2 non-keyword arguments (0 given)
checkfor(self, lambda : f(2, x=2.0), TypeError) # got multiple values for keyword argument 'x'
checkfor(self, lambda : f(x=1), TypeError) # takes exactly 2 non-keyword arguments (1 given)
checkfor(self, lambda : f(s=1), TypeError) # takes exactly 2 non-keyword arguments (0 given)
def test_naming_rule1(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
......@@ -133,8 +133,8 @@ class T_function(unittest.TestCase):
self.assertTrue(f(1, 2) == 0.5)
self.assertTrue(f(2, 1) == 2.0)
self.assertTrue(f(2, s=1) == 2.0)
checkfor(self, lambda: f(q=2, s=1), TypeError) #got unexpected keyword argument 'q'
checkfor(self, lambda: f(a=2, s=1), TypeError) #got unexpected keyword argument 'a'
checkfor(self, lambda: f(q=2, s=1), TypeError) # got unexpected keyword argument 'q'
checkfor(self, lambda: f(a=2, s=1), TypeError) # got unexpected keyword argument 'a'
def test_naming_rule2(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
......@@ -146,8 +146,8 @@ class T_function(unittest.TestCase):
self.assertTrue(f(9, 1, 2) == 0.5)
self.assertTrue(f(9, 2, 1) == 2.0)
self.assertTrue(f(9, 2, s=1) == 2.0)
checkfor(self, lambda: f(x=9, a=2, s=1), TypeError) #got unexpected keyword argument 'x'
checkfor(self, lambda: f(5.0, x=9), TypeError) #got unexpected keyword argument 'x'
checkfor(self, lambda: f(x=9, a=2, s=1), TypeError) # got unexpected keyword argument 'x'
checkfor(self, lambda: f(5.0, x=9), TypeError) # got unexpected keyword argument 'x'
def test_naming_rule3(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
......@@ -155,13 +155,13 @@ class T_function(unittest.TestCase):
# x's name is not ignored (as in test_naming_rule2) because a has a default value.
f = function([x, In(a, value=1.0), s], a/s+x)
self.assertTrue(f(9, 2, 4) == 9.5) #can specify all args in order
self.assertTrue(f(9, 2, 4) == 9.5) # can specify all args in order
self.assertTrue(f(9, 2, s=4) == 9.5) # can give s as kwarg
self.assertTrue(f(9, s=4) == 9.25) # can give s as kwarg, get default a
self.assertTrue(f(x=9, s=4) == 9.25) # can give s as kwarg, omit a, x as kw
checkfor(self, lambda: f(x=9, a=2, s=4), TypeError) #got unexpected keyword argument 'a'
checkfor(self, lambda: f(), TypeError) #takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda: f(x=9), TypeError) #takes exactly 3 non-keyword arguments (1 given)
checkfor(self, lambda: f(x=9, a=2, s=4), TypeError) # got unexpected keyword argument 'a'
checkfor(self, lambda: f(), TypeError) # takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda: f(x=9), TypeError) # takes exactly 3 non-keyword arguments (1 given)
def test_naming_rule4(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
......@@ -169,14 +169,14 @@ class T_function(unittest.TestCase):
f = function([x, In(a, value=1.0, name='a'), s], a/s+x)
self.assertTrue(f(9, 2, 4) == 9.5) #can specify all args in order
self.assertTrue(f(9, 2, 4) == 9.5) # can specify all args in order
self.assertTrue(f(9, 2, s=4) == 9.5) # can give s as kwarg
self.assertTrue(f(9, s=4) == 9.25) # can give s as kwarg, get default a
self.assertTrue(f(9, a=2, s=4) == 9.5) # can give s as kwarg, a as kwarg
self.assertTrue(f(x=9, a=2, s=4) == 9.5) # can give all kwargs
self.assertTrue(f(x=9, s=4) == 9.25) # can give all kwargs
checkfor(self, lambda: f(), TypeError) #takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda: f(5.0, x=9), TypeError) #got multiple values for keyword argument 'x'
checkfor(self, lambda: f(), TypeError) # takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda: f(5.0, x=9), TypeError) # got multiple values for keyword argument 'x'
def test_state_access(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
......@@ -188,14 +188,14 @@ class T_function(unittest.TestCase):
self.assertTrue(f[s] == 0.0)
self.assertTrue(f(3.0) == 3.0)
self.assertTrue(f(3.0, a=2.0) == 9.0) #3.0 + 2*3.0
self.assertTrue(f(3.0, a=2.0) == 9.0) # 3.0 + 2*3.0
self.assertTrue(f[a] == 1.0) #state hasn't changed permanently, we just overrode it last line
self.assertTrue(f[a] == 1.0) # state hasn't changed permanently, we just overrode it last line
self.assertTrue(f[s] == 9.0)
f[a] = 5.0
self.assertTrue(f[a] == 5.0)
self.assertTrue(f(3.0) == 24.0) #9 + 3*5
self.assertTrue(f(3.0) == 24.0) # 9 + 3*5
self.assertTrue(f[s] == 24.0)
def test_same_names(self):
......@@ -233,10 +233,10 @@ class T_function(unittest.TestCase):
self.assertFalse(g.value[s] is f.value[s]) # should have been copied because it is mutable.
self.assertFalse((g.value[s] != f.value[s]).any()) # its contents should be identical
self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
f(1, 2) # put them out of sync
self.assertFalse(f(1, 2) == g(1, 2)) #they should not be equal anymore.
self.assertFalse(f(1, 2) == g(1, 2)) # they should not be equal anymore.
def test_shared_state0(self):
a = T.scalar() # the a is for 'anonymous' (un-named).
......@@ -357,20 +357,20 @@ class T_function(unittest.TestCase):
a = T.dmatrix()
f = function([a], Out(a, borrow=False))
o = N.ones((3, 3))
assert o is not f(o) #function no longer permits aliasing outputs to inputs
assert o is not f(o) # function no longer permits aliasing outputs to inputs
f = function([a], Out(a*4, borrow=False))
o = N.ones((3, 3))
four = f(o)
assert numpy.all(four==4)
f(o+.1) #should not clobber the memory used to store four
f(o+.1) # should not clobber the memory used to store four
assert numpy.all(four==4)
f = function([a], Out(a*4, borrow=True), mode=theano.Mode('c|py_nogc', 'fast_run'))
o = N.ones((3, 3))
four = f(o)
assert numpy.all(four==4)
f(o+.1) #should clobber the memory used to store four
f(o+.1) # should clobber the memory used to store four
if theano.config.cxx:
assert not numpy.all(four==4)
else:
......@@ -456,10 +456,10 @@ class T_picklefunction(unittest.TestCase):
self.assertFalse(g.value[2] is f.value[2]) # should have been copied because it is mutable.
self.assertFalse((g.value[2] != f.value[2]).any()) # its contents should be identical
self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
f(1, 2) # put them out of sync
self.assertFalse(f(1, 2) == g(1, 2)) #they should not be equal anymore.
self.assertFalse(f(1, 2) == g(1, 2)) # they should not be equal anymore.
g(1, 2) # put them back in sync
self.assertTrue(f(3) == g(3)) # They should be in sync again.
......@@ -517,10 +517,10 @@ class T_picklefunction(unittest.TestCase):
self.assertFalse(g.value[2] is f.value[2]) # should have been copied because it is mutable.
self.assertFalse((g.value[2] != f.value[2]).any()) # its contents should be identical
self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
self.assertTrue(f(2, 1) == g(2)) # they should be in sync, default value should be copied.
f(1, 2) # put them out of sync
self.assertFalse(f(1, 2) == g(1, 2)) #they should not be equal anymore.
self.assertFalse(f(1, 2) == g(1, 2)) # they should not be equal anymore.
def test_optimizations_preserved(self):
a = T.dvector() # the a is for 'anonymous' (un-named).
......
......@@ -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,7 +325,7 @@ 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
......@@ -725,7 +725,7 @@ 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
......
......@@ -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
......
......@@ -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.
......
......@@ -55,7 +55,7 @@ for val in keys.values():
nbs_keys[val]+=1
nbs_mod = {} # nb seen -> how many key
nbs_mod_to_key = {} #nb seen -> keys
nbs_mod_to_key = {} # nb seen -> keys
more_than_one = 0
for mod, kk in mods.iteritems():
val = len(kk)
......
......@@ -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()
......
......@@ -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
......@@ -259,7 +259,7 @@ class Config(object):
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):
......
......@@ -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
......
......@@ -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
......
......@@ -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,7 +332,7 @@ 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:
......@@ -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)
......
......@@ -265,7 +265,7 @@ class TestSP(unittest.TestCase):
kshp = ((3, 3), (2, 2))
nkerns = (3, 6) # per output pixel
ssizes = (((1, 1), (2, 2)),)
convmodes = ('full',)#'valid',)
convmodes = ('full',) # 'valid',)
# symbolic stuff
kerns = [tensor.dmatrix(), tensor.dmatrix()]
......
......@@ -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,11 +197,11 @@ 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]
......@@ -209,10 +209,10 @@ def speed_multilayer_conv():
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.
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
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)
......
......@@ -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()
......
......@@ -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*
......
......@@ -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))
......
......@@ -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)
......
......@@ -776,7 +776,7 @@ class T_examples(unittest.TestCase):
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
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)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论