提交 ad4163e1 authored 作者: David Warde-Farley's avatar David Warde-Farley

Change '== None'/'!= None' to use 'is'.

上级 4fe8381e
...@@ -1112,10 +1112,13 @@ class FunctionMaker(object): ...@@ -1112,10 +1112,13 @@ class FunctionMaker(object):
self.accept_inplace = accept_inplace self.accept_inplace = accept_inplace
self.function_builder = function_builder self.function_builder = function_builder
self.required = [(i.value == None) for i in self.inputs] self.required = [(i.value is None) for i in self.inputs]
self.refeed = [ self.refeed = [
(i.value != None and not isinstance(i.value, gof.Container) and i.update == None) (i.value is not None and
for i in self.inputs] not isinstance(i.value, gof.Container) and
i.update is None)
for i in self.inputs
]
def _check_unused_inputs(self, inputs, outputs, on_unused_input): def _check_unused_inputs(self, inputs, outputs, on_unused_input):
if on_unused_input is None: if on_unused_input is None:
......
...@@ -421,7 +421,7 @@ class T_module(unittest.TestCase): ...@@ -421,7 +421,7 @@ class T_module(unittest.TestCase):
m = M.make() m = M.make()
m.y = 77 m.y = 77
assert m.f(23) == 100 assert m.f(23) == 100
assert m.x == None assert m.x is None
m.x = 1000 m.x = 1000
assert m.g(23) == 977 assert m.g(23) == 977
assert m.y == 77 assert m.y == 77
......
...@@ -379,7 +379,7 @@ def computeR(W,b,d,H,Rshape = None): ...@@ -379,7 +379,7 @@ def computeR(W,b,d,H,Rshape = None):
videoWidth = (outputWidth-1) * dc + filterWidth videoWidth = (outputWidth-1) * dc + filterWidth
videoDur = (outputDur-1) * dt + filterDur videoDur = (outputDur-1) * dt + filterDur
if Rshape != None and Rshape[0] != -1: if Rshape is not None and Rshape[0] != -1:
if Rshape[0] < videoHeight: if Rshape[0] < videoHeight:
print (Rshape[0], videoHeight) print (Rshape[0], videoHeight)
assert False assert False
......
...@@ -59,7 +59,7 @@ def get_mode(use_gpu, check_isfinite=True): ...@@ -59,7 +59,7 @@ def get_mode(use_gpu, check_isfinite=True):
def print_mode(mode): def print_mode(mode):
if mode != None and isinstance(mode, (theano.compile.ProfileMode,)): if mode is not None and isinstance(mode, (theano.compile.ProfileMode,)):
mode.print_summary() mode.print_summary()
......
...@@ -62,7 +62,7 @@ class CudaNdarrayType(Type): ...@@ -62,7 +62,7 @@ class CudaNdarrayType(Type):
""" """
def __init__(self, broadcastable, name=None, dtype=None): def __init__(self, broadcastable, name=None, dtype=None):
if dtype != None and dtype != 'float32': if dtype is not None and dtype != 'float32':
raise TypeError('%s only supports dtype float32 for now. Tried ' raise TypeError('%s only supports dtype float32 for now. Tried '
'using dtype %s for variable %s' % 'using dtype %s for variable %s' %
(self.__class__.__name__, dtype, name)) (self.__class__.__name__, dtype, name))
......
...@@ -1293,7 +1293,7 @@ class Scan(PureOp): ...@@ -1293,7 +1293,7 @@ class Scan(PureOp):
## 8. Mask the outputs that are not differentiable ## 8. Mask the outputs that are not differentiable
# backwards pass # backwards pass
for i in xrange(len(inner_gfn_outs)): for i in xrange(len(inner_gfn_outs)):
if inner_gfn_outs[i] == None: if inner_gfn_outs[i] is None:
inner_gfn_outs[i] = tensor.zeros_like(diff_inputs[i]) inner_gfn_outs[i] = tensor.zeros_like(diff_inputs[i])
## 9. Mask the g_outs that are Nones : ## 9. Mask the g_outs that are Nones :
......
...@@ -501,7 +501,7 @@ class ScanSaveMem(gof.Optimizer): ...@@ -501,7 +501,7 @@ class ScanSaveMem(gof.Optimizer):
# 2.3.1 extract idx list of subtensor # 2.3.1 extract idx list of subtensor
this_slice = tensor.basic.get_idx_list(cl.inputs, this_slice = tensor.basic.get_idx_list(cl.inputs,
cl.op.idx_list) cl.op.idx_list)
if this_slice == None: if this_slice is None:
# if unable to extract idx_list # if unable to extract idx_list
#=> outputs needs all its intermediate values #=> outputs needs all its intermediate values
global_nsteps = None global_nsteps = None
...@@ -601,7 +601,7 @@ class ScanSaveMem(gof.Optimizer): ...@@ -601,7 +601,7 @@ class ScanSaveMem(gof.Optimizer):
else: else:
this_slice = tensor.basic.get_idx_list(cl.inputs, this_slice = tensor.basic.get_idx_list(cl.inputs,
cl.op.idx_list) cl.op.idx_list)
if this_slice == None: if this_slice is None:
store_steps[i] = 0 store_steps[i] = 0
break break
......
...@@ -3175,7 +3175,7 @@ class Mean(elemwise.CAReduce): ...@@ -3175,7 +3175,7 @@ class Mean(elemwise.CAReduce):
output[0] = numpy.mean(input, axis=self.axis) output[0] = numpy.mean(input, axis=self.axis)
def c_code(self, node, name, inames, onames, sub): def c_code(self, node, name, inames, onames, sub):
if self.axis != None: if self.axis is not None:
return super(Op, self).c_code(node, name, inames, onames, sub) return super(Op, self).c_code(node, name, inames, onames, sub)
ret = elemwise.CAReduce.c_code(self, node, name, inames, onames, sub) ret = elemwise.CAReduce.c_code(self, node, name, inames, onames, sub)
#TODO: c_code perform support only axis==None #TODO: c_code perform support only axis==None
......
...@@ -1312,7 +1312,7 @@ class CAReduce(Op): ...@@ -1312,7 +1312,7 @@ class CAReduce(Op):
fail = sub["fail"] fail = sub["fail"]
pattern = [0] * len(node.inputs[0].broadcastable) pattern = [0] * len(node.inputs[0].broadcastable)
axis = self.axis axis = self.axis
if axis == None: if axis is None:
axis = range(len(pattern)) axis = range(len(pattern))
for i in axis: for i in axis:
pattern[i] = 1 pattern[i] = 1
......
...@@ -163,7 +163,7 @@ class BinCountOp(theano.Op): ...@@ -163,7 +163,7 @@ class BinCountOp(theano.Op):
def infer_shape(self, node, ins_shapes): def infer_shape(self, node, ins_shapes):
x = node.inputs[0] x = node.inputs[0]
m = basic.max(x) + 1 m = basic.max(x) + 1
if self.minlength != None: if self.minlength is not None:
m = basic.maximum(m, self.minlength) m = basic.maximum(m, self.minlength)
return [[m]] return [[m]]
...@@ -286,7 +286,7 @@ class RepeatOp(theano.Op): ...@@ -286,7 +286,7 @@ class RepeatOp(theano.Op):
def make_node(self, x, repeats): def make_node(self, x, repeats):
x = basic.as_tensor_variable(x) x = basic.as_tensor_variable(x)
repeats = basic.as_tensor_variable(repeats) repeats = basic.as_tensor_variable(repeats)
if self.axis == None: if self.axis is None:
out_type = theano.tensor.TensorType(dtype=x.dtype, out_type = theano.tensor.TensorType(dtype=x.dtype,
broadcastable=[False]) broadcastable=[False])
else: else:
...@@ -326,7 +326,7 @@ class RepeatOp(theano.Op): ...@@ -326,7 +326,7 @@ class RepeatOp(theano.Op):
repeats = node.inputs[1] repeats = node.inputs[1]
out_shape = list(i0_shapes) out_shape = list(i0_shapes)
if self.axis == None: if self.axis is None:
if repeats.ndim == 0: if repeats.ndim == 0:
if len(i0_shapes) == 0: if len(i0_shapes) == 0:
out_shape = [repeats] out_shape = [repeats]
......
...@@ -361,7 +361,7 @@ class ConvOp(Op): ...@@ -361,7 +361,7 @@ class ConvOp(Op):
self.dy=dy self.dy=dy
self.verbose=verbose self.verbose=verbose
self.version=version self.version=version
if openmp == None: if openmp is None:
openmp = config.openmp openmp = config.openmp
self.openmp = openmp self.openmp = openmp
......
...@@ -1648,7 +1648,7 @@ class Prepend_scalar_constant_to_each_row(gof.Op): ...@@ -1648,7 +1648,7 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
mat, = inp mat, = inp
output, = out output, = out
new_shape = (mat.shape[0], mat.shape[1] + 1) new_shape = (mat.shape[0], mat.shape[1] + 1)
if output[0] == None: if output[0] is None:
output[0] = numpy.empty(new_shape, dtype=mat.dtype) output[0] = numpy.empty(new_shape, dtype=mat.dtype)
out = output[0] out = output[0]
else: else:
...@@ -1703,7 +1703,7 @@ class Prepend_scalar_to_each_row(gof.Op): ...@@ -1703,7 +1703,7 @@ class Prepend_scalar_to_each_row(gof.Op):
val, mat = inp val, mat = inp
output, = out output, = out
new_shape = (mat.shape[0], mat.shape[1] + 1) new_shape = (mat.shape[0], mat.shape[1] + 1)
if output[0] == None: if output[0] is None:
output[0] = numpy.empty(new_shape, dtype=mat.dtype) output[0] = numpy.empty(new_shape, dtype=mat.dtype)
out = output[0] out = output[0]
else: else:
......
...@@ -454,7 +454,7 @@ def normal(random_state, size=None, avg=0.0, std=1.0, ndim=None, dtype=None): ...@@ -454,7 +454,7 @@ def normal(random_state, size=None, avg=0.0, std=1.0, ndim=None, dtype=None):
""" """
avg = tensor.as_tensor_variable(avg) avg = tensor.as_tensor_variable(avg)
std = tensor.as_tensor_variable(std) std = tensor.as_tensor_variable(std)
if dtype == None: if dtype is None:
dtype = tensor.scal.upcast(theano.config.floatX, avg.dtype, std.dtype) dtype = tensor.scal.upcast(theano.config.floatX, avg.dtype, std.dtype)
ndim, size, bcast = _infer_ndim_bcast(ndim, size, avg, std) ndim, size, bcast = _infer_ndim_bcast(ndim, size, avg, std)
op = RandomFunction('normal', op = RandomFunction('normal',
......
...@@ -5888,7 +5888,7 @@ def test_transpose(): ...@@ -5888,7 +5888,7 @@ def test_transpose():
assert tensor.transpose(x1).name == 'x1.T' assert tensor.transpose(x1).name == 'x1.T'
assert tensor.transpose(x2).name == 'x2.T' assert tensor.transpose(x2).name == 'x2.T'
assert tensor.transpose(x3).name == 'x3.T' assert tensor.transpose(x3).name == 'x3.T'
assert tensor.transpose(tensor.dmatrix()).name == None assert tensor.transpose(tensor.dmatrix()).name is None
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -65,8 +65,8 @@ class TestCGer(TestCase, TestOptimizationMixin): ...@@ -65,8 +65,8 @@ class TestCGer(TestCase, TestOptimizationMixin):
self.assert_(CGer(False) != Ger(False)) self.assert_(CGer(False) != Ger(False))
# assert that eq works for non-CGer instances # assert that eq works for non-CGer instances
self.assert_(CGer(False) != None) self.assert_(CGer(False) is not None)
self.assert_(CGer(True) != None) self.assert_(CGer(True) is not None)
def test_hash(self): def test_hash(self):
self.assert_(hash(CGer(True)) == hash(CGer(True))) self.assert_(hash(CGer(True)) == hash(CGer(True)))
......
...@@ -909,7 +909,7 @@ class test_fusion(unittest.TestCase): ...@@ -909,7 +909,7 @@ class test_fusion(unittest.TestCase):
continue continue
print "new cases", id print "new cases", id
if shared_fn == None: if shared_fn is None:
assert gpu==False assert gpu==False
f = compile.function(list(sym_inputs), g,mode=mode) f = compile.function(list(sym_inputs), g,mode=mode)
for x in range(nb_repeat): for x in range(nb_repeat):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论