提交 c855e8d6 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #3030 from abergeron/flake8_temp

[MRG] Ignore E501 (lines too long) for the flake8 test.
......@@ -1417,8 +1417,7 @@ def _pickle_FunctionMaker(self):
accept_inplace=self.accept_inplace,
function_builder=self.function_builder,
profile=self.profile,
on_unused_input=self.on_unused_input,
)
on_unused_input=self.on_unused_input)
return (_constructor_FunctionMaker, (kwargs,))
......
......@@ -71,8 +71,7 @@ predefined_linkers = {
'vm': gof.vm.VM_Linker(use_cloop=False), # Use allow_gc Theano flag
'cvm': gof.vm.VM_Linker(use_cloop=True), # Use allow_gc Theano flag
'vm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=False),
'cvm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=True),
}
'cvm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=True)}
def register_linker(name, linker):
......@@ -115,8 +114,7 @@ predefined_optimizers = {
'fast_run': OPT_FAST_RUN,
'fast_run_stable': OPT_FAST_RUN_STABLE,
'fast_compile': OPT_FAST_COMPILE,
'stabilize': OPT_STABILIZE
}
'stabilize': OPT_STABILIZE}
def register_optimizer(name, opt):
......
......@@ -63,8 +63,7 @@ compiledir_format_dict = {
"theano_version": theano.__version__,
"numpy_version": numpy.__version__,
"gxx_version": gcc_version_str.replace(" ", "_"),
"hostname": socket.gethostname(),
}
"hostname": socket.gethostname()}
def short_platform(r=None, p=None):
......
......@@ -108,7 +108,7 @@ def _get_lock(lock_dir=None, **kw):
raise Exception("For some unknow reason, the lock was already "
"taken, but no start time was registered.")
now = time.time()
if now - get_lock.start_time > config.compile.timeout/2:
if now - get_lock.start_time > config.compile.timeout / 2:
lockpath = os.path.join(get_lock.lock_dir, 'lock')
_logger.info('Refreshing lock %s', str(lockpath))
refresh_lock(lockpath)
......
......@@ -312,7 +312,7 @@ class SequenceDB(DB):
positions = list(self.__position__.items())
def c(a, b):
return cmp(a[1], b[1])
return ((a[1] > b[1]) - (a[1] < b[1]))
positions.sort(c)
print(" position", positions, file=stream)
......
......@@ -46,7 +46,7 @@ class TestCallbacks(unittest.TestCase):
def test_callback_with_ifelse(self):
a, b, c = tensor.scalars('abc')
f = function([a, b, c], ifelse(a, 2*b, 2*c),
f = function([a, b, c], ifelse(a, 2 * b, 2 * c),
mode=Mode(
optimizer=None,
linker=vm.VM_Linker(callback=self.callback)))
......@@ -62,7 +62,7 @@ def test_c_thunks():
if theano.config.cxx:
cases.append(True)
for c_thunks in cases:
f = function([a, b, c], ifelse(a, a*b, b*c),
f = function([a, b, c], ifelse(a, a * b, b * c),
mode=Mode(
optimizer=None,
linker=vm.VM_Linker(c_thunks=c_thunks,
......@@ -86,7 +86,7 @@ def test_speed():
def numpy_version(x, depth):
z = x
for d in xrange(depth):
z = (z+z)
z = (z + z)
return z
def time_numpy():
......@@ -136,7 +136,7 @@ def test_speed():
print("%s takes %f s/Kop" % (
name,
(1000*(t_b-t_a) / (steps_b - steps_a))))
(1000 * (t_b - t_a) / (steps_b - steps_a))))
time_linker('c|py', OpWiseCLinker)
time_linker('vmLinker', vm.VM_Linker)
......@@ -185,7 +185,7 @@ def test_speed_lazy():
print("%s takes %f s/Kop" % (
name,
(1000*(t_b-t_a) / (steps_b - steps_a))))
(1000 * (t_b - t_a) / (steps_b - steps_a))))
time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False))
......@@ -230,6 +230,8 @@ if run_memory_usage_tests:
a = cuda.CudaNdarray(n)
a.sum()
assert c == sys.getrefcount(n)
# This is to confuse flake8
a = a
del a
if not i % 1000:
print('.', end=' ')
......
......@@ -282,11 +282,7 @@ class PureType(object):
'Cannot convert Type %(othertype)s '
'(of Variable %(other)s) into Type %(self)s. '
'You can try to manually convert %(other)s into a %(self)s.'
% dict(
othertype=other.type,
other=other,
self=self)
)
% dict(othertype=other.type, other=other, self=self))
return other
def is_valid_value(self, a):
......
......@@ -35,7 +35,7 @@ def ElemwiseOpTime(N, script=False, loops=1000):
x = T.vector('x')
np.random.seed(1235)
v = np.random.random(N).astype(theano.config.floatX)
f = theano.function([x], 2*x + x*x)
f = theano.function([x], 2 * x + x * x)
f1 = theano.function([x], T.tanh(x))
if not script:
if theano.config.openmp:
......
......@@ -194,7 +194,7 @@ class TestConv3dFFT(unittest.TestCase):
res_ref = f_ref()
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-05, atol=1e-05)
utt.assert_allclose(res_ref, res_fft, rtol=1e-05, atol=1e-05)
def run_conv_full(self, inputs_shape, filters_shape, pad=False):
inputs_val = numpy.random.random(inputs_shape).astype('float32')
......@@ -220,7 +220,7 @@ class TestConv3dFFT(unittest.TestCase):
res_ref = f_ref()
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
def test_valid(self):
self.run_conv_valid(inputs_shape=(16, 20, 32, 16, 1),
......@@ -299,7 +299,7 @@ class TestConv3dFFT(unittest.TestCase):
res_ref = f_ref()
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
def test_opt_convtransp3d_fft(self):
inputs_shape = (2, 9, 16, 12, 10)
......
import six.moves.cPickle as pickle
import os.path
import sys
from nose.tools import assert_raises
import numpy
......
......@@ -255,7 +255,7 @@ def local_gpu_elemwise(node):
scal_op = op.scalar_op
name = op.name
if name:
name = 'Gpu'+name
name = 'Gpu' + name
res = GpuElemwise(scal_op, name=name,
inplace_pattern=copy.copy(op.inplace_pattern),
nfunc_spec=op.nfunc_spec)
......@@ -349,7 +349,7 @@ def local_gpu_pdbbreakpoint_op(node):
nb_monitored_vars = len(node.outputs)
for i in range(nb_monitored_vars):
inp = old_inputs[i+1]
inp = old_inputs[i + 1]
out = old_outputs[i]
input_is_from_gpu = (inp.owner and
......
......@@ -25,12 +25,12 @@ def test_grad():
op = SymPyCCode([xs], xs**2)
zt = op(xt)
ztprime = theano.grad(zt, xt)
assert ztprime.owner.op.expr == 2*xs
assert ztprime.owner.op.expr == 2 * xs
def test_multivar_grad():
op = SymPyCCode([xs, ys], xs**2 + ys**3)
op = SymPyCCode([xs, ys], xs ** 2 + ys ** 3)
zt = op(xt, yt)
dzdx, dzdy = theano.grad(zt, [xt, yt])
assert dzdx.owner.op.expr == 2*xs
assert dzdy.owner.op.expr == 3*ys**2
assert dzdx.owner.op.expr == 2 * xs
assert dzdy.owner.op.expr == 3 * ys ** 2
差异被折叠。
......@@ -29,9 +29,6 @@ def _scal_inplace(symbol):
if not r.owner:
return False
op = r.owner.op
# print op, rval, r.owner and op == rval
# print op.inplace_pattern, rval.inplace_pattern, op.inplace_pattern == rval.inplace_pattern
# print op.scalar_op, rval.scalar_op, op.scalar_op == rval.scalar_op
return r.owner.op == rval
pprint.assign(chk, printing.FunctionPrinter(symbolname.replace('_inplace', '=')))
......@@ -348,17 +345,13 @@ def conj_inplace(a):
pprint.assign(add_inplace, printing.OperatorPrinter('+=', -2, 'either'))
pprint.assign(mul_inplace, printing.OperatorPrinter('*=', -1, 'either'))
pprint.assign(sub_inplace, printing.OperatorPrinter('-=', -2, 'left'))
pprint.assign(neg_inplace, printing.OperatorPrinter('-=', 0, 'either'))
pprint.assign(neg_inplace, printing.OperatorPrinter('-=', 0, 'either'))
pprint.assign(true_div_inplace, printing.OperatorPrinter('/=', -1, 'left'))
pprint.assign(int_div_inplace, printing.OperatorPrinter('//=', -1, 'left'))
pprint.assign(pow_inplace, printing.OperatorPrinter('**=', 1, 'right'))
def transpose_inplace(x, **kwargs):
"""Perform a transpose on a tensor without copying the underlying storage"""
"Perform a transpose on a tensor without copying the underlying storage"
dims = list(range(x.ndim - 1, -1, -1))
return elemwise.DimShuffle(x.broadcastable, dims, inplace=True)(x)
#pprint.assign(transpose_inplace, printing.MemberPrinter('T'))
......@@ -24,11 +24,11 @@ def randomstate_constructor(value, name=None, strict=False,
if not borrow:
value = copy.deepcopy(value)
return RandomStateSharedVariable(
type=raw_random.random_state_type,
value=value,
name=name,
strict=strict,
allow_downcast=allow_downcast)
type=raw_random.random_state_type,
value=value,
name=name,
strict=strict,
allow_downcast=allow_downcast)
class RandomStreams(raw_random.RandomStreamsBase):
......
......@@ -25,15 +25,14 @@ except ImportError:
imported_scipy = False
MATRIX_STRUCTURES = (
'general',
'symmetric',
'lower_triangular',
'upper_triangular',
'hermitian',
'banded',
'diagonal',
'toeplitz',
)
'general',
'symmetric',
'lower_triangular',
'upper_triangular',
'hermitian',
'banded',
'diagonal',
'toeplitz')
class Cholesky(Op):
......@@ -168,8 +167,8 @@ class Solve(Op):
assert A.ndim == 2
assert b.ndim in [1, 2]
otype = tensor.tensor(
broadcastable=b.broadcastable,
dtype=(A * b).dtype)
broadcastable=b.broadcastable,
dtype=(A * b).dtype)
return Apply(self, [A, b], [otype])
def perform(self, node, inputs, output_storage):
......@@ -294,7 +293,7 @@ class EigvalshGrad(Op):
(a, b, gw) = inputs
w, v = scipy.linalg.eigh(a, b, lower=self.lower)
gA = v.dot(numpy.diag(gw).dot(v.T))
gB = - v.dot(numpy.diag(gw*w).dot(v.T))
gB = - v.dot(numpy.diag(gw * w).dot(v.T))
# See EighGrad comments for an explanation of these lines
out1 = self.tri0(gA) + self.tri1(gA).T
......
......@@ -155,16 +155,16 @@ def get_canonical_form_slice(theslice, length):
1), 1)
stop_plus_len = stop + length
stop = switch(
lt(stop, 0),
# stop < 0
switch(
lt(stop_plus_len, 0),
# stop + len < 0
0,
# stop + len >= 0
stop_plus_len),
# stop >= 0: use min(stop, length)
switch(lt(stop, length), stop, length))
lt(stop, 0),
# stop < 0
switch(
lt(stop_plus_len, 0),
# stop + len < 0
0,
# stop + len >= 0
stop_plus_len),
# stop >= 0: use min(stop, length)
switch(lt(stop, length), stop, length))
return slice(0, stop, 1), 1
elif is_stop_length:
# start:length:1
......@@ -173,16 +173,16 @@ def get_canonical_form_slice(theslice, length):
length, 1), 1
start_plus_len = start + length
start = switch(
lt(start, 0),
# start < 0
switch(
lt(start_plus_len, 0),
# start + len < 0
0,
# start + len >= 0
start_plus_len),
# start >= 0: use min(start, length)
switch(lt(start, length), start, length))
lt(start, 0),
# start < 0
switch(
lt(start_plus_len, 0),
# start + len < 0
0,
# start + len >= 0
start_plus_len),
# start >= 0: use min(start, length)
switch(lt(start, length), start, length))
return slice(start, length, 1), 1
# This is the generic case.
......@@ -614,10 +614,8 @@ class Subtensor(Op):
helper_c_code
"""
return {
"c_prefix": "PyArray",
"strides_mul": 1,
}
return {"c_prefix": "PyArray",
"strides_mul": 1}
@staticmethod
def helper_c_code(node, name, inputs, outputs, sub, idx_list, view_ndim,
......
......@@ -389,17 +389,15 @@ class _tensor_py_operators:
axis = i
if advanced:
if (axis is not None
and all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[:axis])
and all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[axis + 1:])
and isinstance(args[axis], (
numpy.ndarray,
list,
TensorVariable,
TensorConstant,
theano.tensor.sharedvar.TensorSharedVariable))):
if (axis is not None and
all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[:axis]) and
all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[axis + 1:]) and
isinstance(args[axis],
(numpy.ndarray, list,
TensorVariable, TensorConstant,
theano.tensor.sharedvar.TensorSharedVariable))):
return self.take(args[axis], axis)
else:
return theano.tensor.subtensor.advanced_subtensor(self, *args)
......
......@@ -88,7 +88,7 @@ class PdbBreakpoint(Op):
for i in range(len(monitored_vars)):
# Every output i is a view of the input i+1 because of the input
# condition.
new_op.view_map[i] = [i+1]
new_op.view_map[i] = [i + 1]
new_op.inp_types.append(monitored_vars[i].type)
# Build the Apply node
......@@ -125,7 +125,7 @@ class PdbBreakpoint(Op):
else:
# Simply return views on the monitored variables
for i in range(len(output_storage)):
output_storage[i][0] = inputs[i+1]
output_storage[i][0] = inputs[i + 1]
def grad(self, inputs, output_gradients):
return ([DisconnectedType()()] + output_gradients)
......
......@@ -20,4 +20,4 @@ def disturb_mem():
ms = int(ms)
n = ms % 1000
m = ms // 1000
l = [[0]*m for i in xrange(n)]
l = [[0] * m for i in xrange(n)]
......@@ -12,8 +12,8 @@ class dictionary_output_checker(unittest.TestCase):
'''
x = T.scalar()
f = theano.function([x], outputs={'a': x, 'c': x*2,
'b': x*3, '1': x*4})
f = theano.function([x], outputs={'a': x, 'c': x * 2,
'b': x * 3, '1': x * 4})
outputs = f(10.0)
......
......@@ -6,7 +6,6 @@ from nose.plugins.skip import SkipTest
import os
from fnmatch import fnmatch
import theano
from theano.compat import PY3
try:
import flake8.engine
import flake8.main
......@@ -18,6 +17,10 @@ __authors__ = ("Saizheng Zhang")
__copyright__ = "(c) 2015, Universite de Montreal"
__contact__ = "Saizheng Zhang <saizhenglisa..at..gmail.com>"
# This corresponds to "line too long" and it's too much of a pain with
# all of the C code
ignore = ('E501',)
whitelist_flake8 = [
"compat/six.py", # This is bundled code that will be deleted, don't fix it
"__init__.py",
......@@ -74,7 +77,6 @@ whitelist_flake8 = [
"tensor/extra_ops.py",
"tensor/nlinalg.py",
"tensor/blas_c.py",
"tensor/io.py",
"tensor/elemwise_cgen.py",
"tensor/raw_random.py",
"tensor/blas_scipy.py",
......@@ -93,7 +95,6 @@ whitelist_flake8 = [
"tensor/tests/test_merge.py",
"tensor/tests/test_gc.py",
"tensor/tests/test_complex.py",
"tensor/tests/test_type_other.py",
"tensor/tests/test_io.py",
"tensor/tests/test_sharedvar.py",
"tensor/tests/test_fourier.py",
......@@ -160,8 +161,6 @@ whitelist_flake8 = [
"sandbox/cuda/opt.py",
"sandbox/cuda/blas.py",
"sandbox/cuda/blocksparse.py",
"sandbox/cuda/GpuConv3D.py",
"sandbox/cuda/extra_ops.py",
"sandbox/cuda/rng_curand.py",
"sandbox/cuda/fftconv.py",
"sandbox/cuda/kernel_codegen.py",
......@@ -172,7 +171,6 @@ whitelist_flake8 = [
"sandbox/cuda/tests/test_gradient.py",
"sandbox/cuda/tests/test_neighbours.py",
"sandbox/cuda/tests/test_conv_cuda_ndarray.py",
"sandbox/cuda/tests/test_type.py",
"sandbox/cuda/tests/test_var.py",
"sandbox/cuda/tests/test_opt.py",
"sandbox/cuda/tests/test_blas.py",
......@@ -235,7 +233,6 @@ whitelist_flake8 = [
"misc/pycuda_utils.py",
"misc/pycuda_example.py",
"misc/ordered_set.py",
"misc/windows.py",
"misc/strutil.py",
"misc/gnumpy_utils.py",
"misc/may_share_memory.py",
......@@ -250,7 +247,6 @@ whitelist_flake8 = [
"misc/tests/test_pycuda_example.py",
"misc/hooks/reindent.py",
"misc/hooks/check_whitespace.py",
"sparse/sharedvar.py",
"sparse/type.py",
"sparse/__init__.py",
"sparse/opt.py",
......@@ -308,15 +304,13 @@ def test_format_flake8():
"""
if not flake8_available:
raise SkipTest("flake8 is not installed")
if PY3:
raise SkipTest("not testing in python3 since 2to3 ran")
total_errors = 0
for path in list_files():
rel_path = os.path.relpath(path, theano.__path__[0])
if rel_path in whitelist_flake8:
continue
else:
error_num = flake8.main.check_file(path)
error_num = flake8.main.check_file(path, ignore=ignore)
total_errors += error_num
if total_errors > 0:
raise AssertionError("FLAKE8 Format not respected")
......@@ -332,7 +326,8 @@ def print_files_information_flake8():
non_infracting_files = []
for path in list_files():
rel_path = os.path.relpath(path, theano.__path__[0])
number_of_infractions = flake8.main.check_file(path)
number_of_infractions = flake8.main.check_file(path,
ignore=ignore)
if number_of_infractions > 0:
if rel_path not in whitelist_flake8:
infracting_files.append(rel_path)
......@@ -359,7 +354,8 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
for (dir, _, files) in os.walk(dir_path):
for f in files:
if fnmatch(f, pattern):
error_num = flake8.main.check_file(os.path.join(dir, f))
error_num = flake8.main.check_file(os.path.join(dir, f),
ignore=ignore)
if error_num > 0:
path = os.path.relpath(os.path.join(dir, f),
theano.__path__[0])
......
......@@ -495,17 +495,17 @@ def test_scan_debugprint3():
def test_scan_debugprint4():
def fn(a_m2, a_m1, b_m2, b_m1):
return a_m1+a_m2, b_m1+b_m2
return a_m1 + a_m2, b_m1 + b_m2
a0 = theano.shared(numpy.arange(2))
b0 = theano.shared(numpy.arange(2))
(a, b), _ = theano.scan(fn, outputs_info=[
{'initial': a0, 'taps': [-2, -1]},
{'initial': b0, 'taps': [-2, -1]}],
n_steps=5)
(a, b), _ = theano.scan(
fn, outputs_info=[{'initial': a0, 'taps': [-2, -1]},
{'initial': b0, 'taps': [-2, -1]}],
n_steps=5)
final_result = a+b
final_result = a + b
output_str = theano.printing.debugprint(final_result, file='str')
lines = []
for line in output_str.split('\n'):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论