提交 f4e3b36f authored 作者: Frederic's avatar Frederic 提交者: Yann N. Dauphin

some pep8

上级 8babd051
......@@ -42,7 +42,7 @@ def multMatVect(v, A, m1, B, m2):
Note: The parameters of dot_modulo are passed implicitly because passing
them explicitly takes more time then running the function's C-code.
"""
if multMatVect.dot_modulo == None:
if multMatVect.dot_modulo is None:
A_sym = tensor.lmatrix('A')
s_sym = tensor.ivector('s')
m_sym = tensor.iscalar('m')
......@@ -187,42 +187,41 @@ def mrg_next_value(rstate, new_rstate):
x11, x12, x13, x21, x22, x23 = rstate
assert type(x11) == numpy.int32
#i0, i7, i9, i15, i16, i22, i24 = [numpy.int32(i) for i in (0, 7, 9, 15, 16, 22, 24)]
i0, i7, i9, i15, i16, i22, i24 = np_int32_vals
#first component
y1 = (((x12 & MASK12) << i22) + (x12 >> i9) +
((x13 & MASK13) << i7) + (x13 >> i24))
assert type(y1) == numpy.int32
if (y1 < 0 or y1 >= M1): #must also check overflow
y1 -= M1;
y1 += x13;
if (y1 < 0 or y1 >= M1): # must also check overflow
y1 -= M1
y1 += x13
if (y1 < 0 or y1 >= M1):
y1 -= M1;
y1 -= M1
x13 = x12;
x12 = x11;
x11 = y1;
x13 = x12
x12 = x11
x11 = y1
#second component
y1 = ((x21 & MASK2) << i15) + (MULT2 * (x21 >> i16));
y1 = ((x21 & MASK2) << i15) + (MULT2 * (x21 >> i16))
assert type(y1) == numpy.int32
if (y1 < 0 or y1 >= M2):
y1 -= M2;
y2 = ((x23 & MASK2) << i15) + (MULT2 * (x23 >> i16));
y1 -= M2
y2 = ((x23 & MASK2) << i15) + (MULT2 * (x23 >> i16))
assert type(y2) == numpy.int32
if (y2 < 0 or y2 >= M2):
y2 -= M2;
y2 += x23;
y2 -= M2
y2 += x23
if (y2 < 0 or y2 >= M2):
y2 -= M2;
y2 += y1;
y2 -= M2
y2 += y1
if (y2 < 0 or y2 >= M2):
y2 -= M2;
y2 -= M2
x23 = x22;
x22 = x21;
x21 = y2;
x23 = x22
x22 = x21
x21 = y2
# Must never return either 0 or M1+1
new_rstate[...] = [x11, x12, x13, x21, x22, x23]
......@@ -237,9 +236,9 @@ class mrg_uniform_base(Op):
def __init__(self, output_type, inplace=False):
Op.__init__(self)
self.output_type = output_type
self.inplace=inplace
self.inplace = inplace
if inplace:
self.destroy_map = {0:[0]}
self.destroy_map = {0: [0]}
self.warned_numpy_version = False
def __eq__(self, other):
......@@ -291,8 +290,12 @@ class mrg_uniform(mrg_uniform_base):
rstate, size = inp
o_rstate, o_sample = out
numpy_version = numpy.__version__.split('.')
if not self.warned_numpy_version and int(numpy_version[0]) <= 1 and int(numpy_version[1]) <3 :
print "Warning: you must use numpy version 1.3.0 or higher with the python version of this op. Otherwise numpy leak memory."
if (not self.warned_numpy_version and
int(numpy_version[0]) <= 1 and
int(numpy_version[1]) < 3):
print "Warning: you must use numpy version 1.3.0 or higher with the python version of this op. Otherwise numpy leak memory. and numpy"
self.warned_numpy_version = True
n_elements = 1
......@@ -317,8 +320,9 @@ class mrg_uniform(mrg_uniform_base):
finally:
numpy.seterr(**err_orig)
o_rstate[0] = node.outputs[0].type.filter(rstate) # send to GPU if necessary
o_sample[0] = node.outputs[1].type.filter(rval.reshape(size)) # send to GPU if necessary
# send to GPU if necessary
o_rstate[0] = node.outputs[0].type.filter(rstate)
o_sample[0] = node.outputs[1].type.filter(rval.reshape(size))
def c_code(self, node, name, inp, out, sub):
rstate, size = inp
......@@ -1083,7 +1087,8 @@ class MRG_RandomStreams(object):
msg = "size must be a tuple of int or a Theano variable"
assert all([isinstance(i, (numpy.integer, int, Variable))
for i in size]), msg
if any([isinstance(i, (numpy.integer, int)) and i <= 0 for i in size]):
if any([isinstance(i, (numpy.integer, int)) and i <= 0
for i in size]):
raise ValueError(
"The specified size contains a dimension with value <= 0",
size)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论