提交 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): ...@@ -1417,8 +1417,7 @@ def _pickle_FunctionMaker(self):
accept_inplace=self.accept_inplace, accept_inplace=self.accept_inplace,
function_builder=self.function_builder, function_builder=self.function_builder,
profile=self.profile, profile=self.profile,
on_unused_input=self.on_unused_input, on_unused_input=self.on_unused_input)
)
return (_constructor_FunctionMaker, (kwargs,)) return (_constructor_FunctionMaker, (kwargs,))
......
...@@ -71,8 +71,7 @@ predefined_linkers = { ...@@ -71,8 +71,7 @@ predefined_linkers = {
'vm': gof.vm.VM_Linker(use_cloop=False), # Use allow_gc Theano flag '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 '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), '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): def register_linker(name, linker):
...@@ -115,8 +114,7 @@ predefined_optimizers = { ...@@ -115,8 +114,7 @@ predefined_optimizers = {
'fast_run': OPT_FAST_RUN, 'fast_run': OPT_FAST_RUN,
'fast_run_stable': OPT_FAST_RUN_STABLE, 'fast_run_stable': OPT_FAST_RUN_STABLE,
'fast_compile': OPT_FAST_COMPILE, 'fast_compile': OPT_FAST_COMPILE,
'stabilize': OPT_STABILIZE 'stabilize': OPT_STABILIZE}
}
def register_optimizer(name, opt): def register_optimizer(name, opt):
......
...@@ -378,22 +378,22 @@ class ProfileMode(Mode): ...@@ -378,22 +378,22 @@ class ProfileMode(Mode):
print() print()
print('Time since import %.3fs' % (total_time)) print('Time since import %.3fs' % (total_time))
print('Theano compile time: %.3fs (%.1f%% since import)' % print('Theano compile time: %.3fs (%.1f%% since import)' %
(compile_time, compile_time/total_time*100)) (compile_time, compile_time / total_time * 100))
print(' Optimization time: %.3fs' % (other_time['optimizer_time'])) print(' Optimization time: %.3fs' % (other_time['optimizer_time']))
print(' Linker time: %.3fs' % (other_time['linker_time'])) print(' Linker time: %.3fs' % (other_time['linker_time']))
print('Theano fct call %.3fs (%.1f%% since import)' % print('Theano fct call %.3fs (%.1f%% since import)' %
(total_fct_time, total_fct_time/total_time*100)) (total_fct_time, total_fct_time / total_time * 100))
print(' Theano Op time %.3fs %.1f%%(since import) %.1f%%' print(' Theano Op time %.3fs %.1f%%(since import) %.1f%%'
'(of fct call)' % (local_time, local_time/total_time*100, '(of fct call)' % (local_time, local_time / total_time * 100,
time_pr_in_fct)) time_pr_in_fct))
print(' Theano function overhead in ProfileMode %.3fs %.1f%%' print(' Theano function overhead in ProfileMode %.3fs %.1f%%'
'(since import) %.1f%%(of fct call)' % ( '(since import) %.1f%%(of fct call)' % (
overhead_time, overhead_time/total_time*100, overhead_time, overhead_time / total_time * 100,
overhead_time_pourcent_fct_time)) overhead_time_pourcent_fct_time))
print('%i Theano fct call, %.3fs per call' % print('%i Theano fct call, %.3fs per call' %
(total_fct_call, time_per_call)) (total_fct_call, time_per_call))
print('Rest of the time since import %.3fs %.1f%%' % print('Rest of the time since import %.3fs %.1f%%' %
(unknown_time, unknown_time/total_time*100)) (unknown_time, unknown_time / total_time * 100))
print() print()
print('Theano fct summary:') print('Theano fct summary:')
...@@ -402,9 +402,9 @@ class ProfileMode(Mode): ...@@ -402,9 +402,9 @@ class ProfileMode(Mode):
for key in fct_call: for key in fct_call:
if fct_call[key] > 0: if fct_call[key] > 0:
print(' %4.1f%% %.3fs %.2es %d %s' % print(' %4.1f%% %.3fs %.2es %d %s' %
(fct_call_time[key]/total_fct_time*100, (fct_call_time[key] / total_fct_time * 100,
fct_call_time[key], fct_call_time[key],
fct_call_time[key]/fct_call[key], fct_call_time[key] / fct_call[key],
fct_call[key], fct_call[key],
key.name)) key.name))
else: else:
...@@ -448,7 +448,7 @@ class ProfileMode(Mode): ...@@ -448,7 +448,7 @@ class ProfileMode(Mode):
sop_op[typ] += 1 sop_op[typ] += 1
sop_cimpl.setdefault(typ, True) sop_cimpl.setdefault(typ, True)
sop_cimpl[typ] = sop_cimpl[typ] and op_cimpl.get(a, False) sop_cimpl[typ] = sop_cimpl[typ] and op_cimpl.get(a, False)
sop_call[typ] = sop_call.get(typ, 0)+op_call[a] sop_call[typ] = sop_call.get(typ, 0) + op_call[a]
# Print the summary per op class. # Print the summary per op class.
print() print()
...@@ -456,7 +456,7 @@ class ProfileMode(Mode): ...@@ -456,7 +456,7 @@ class ProfileMode(Mode):
print('<% of local_time spent on this kind of Op> <cumulative %> ' print('<% of local_time spent on this kind of Op> <cumulative %> '
'<self seconds> <cumulative seconds> <time per call> [*] ' '<self seconds> <cumulative seconds> <time per call> [*] '
'<nb_call> <nb_op> <nb_apply> <Op name>') '<nb_call> <nb_op> <nb_apply> <Op name>')
sotimes = [(t*100/local_time, t, a, sop_cimpl[a], sop_call[a], sotimes = [(t * 100 / local_time, t, a, sop_cimpl[a], sop_call[a],
sop_op[a], sop_apply[a]) for a, t in iteritems(sop_time)] sop_op[a], sop_apply[a]) for a, t in iteritems(sop_time)]
sotimes.sort() sotimes.sort()
sotimes.reverse() sotimes.reverse()
...@@ -466,17 +466,17 @@ class ProfileMode(Mode): ...@@ -466,17 +466,17 @@ class ProfileMode(Mode):
assert t == 0 assert t == 0
continue continue
tot += t tot += t
ftot = tot*100/local_time ftot = tot * 100 / local_time
if ci: if ci:
msg = '*' msg = '*'
else: else:
msg = ' ' msg = ' '
print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %5d %2d ' print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %5d %2d '
'%2d %s' % (f, ftot, t, tot, t/nb_call, msg, nb_call, '%2d %s' % (f, ftot, t, tot, t / nb_call, msg, nb_call,
nb_op, nb_apply, a)) nb_op, nb_apply, a))
print(' ... (remaining %i single Op account for %.2f%%(%.2fs) of ' print(' ... (remaining %i single Op account for %.2f%%(%.2fs) of '
'the runtime)' % 'the runtime)' %
(max(0, len(sotimes)-n_ops_to_print), (max(0, len(sotimes) - n_ops_to_print),
sum(soinfo[0] for soinfo in sotimes[n_ops_to_print:]), sum(soinfo[0] for soinfo in sotimes[n_ops_to_print:]),
sum(soinfo[1] for soinfo in sotimes[n_ops_to_print:]))) sum(soinfo[1] for soinfo in sotimes[n_ops_to_print:])))
...@@ -486,7 +486,7 @@ class ProfileMode(Mode): ...@@ -486,7 +486,7 @@ class ProfileMode(Mode):
op_flops = {} op_flops = {}
for a, t in iteritems(op_time): for a, t in iteritems(op_time):
if hasattr(a, 'flops'): if hasattr(a, 'flops'):
op_flops[a] = a.flops*op_call[a]/t/1e6 op_flops[a] = a.flops * op_call[a] / t / 1e6
flops_msg = '' flops_msg = ''
if op_flops: if op_flops:
flops_msg = ' <MFlops/s>' flops_msg = ' <MFlops/s>'
...@@ -500,7 +500,7 @@ class ProfileMode(Mode): ...@@ -500,7 +500,7 @@ class ProfileMode(Mode):
'<self seconds> <cumulative seconds> <time per call> [*] %s ' '<self seconds> <cumulative seconds> <time per call> [*] %s '
'<nb_call> <nb apply> <Op name>' % (flops_msg)) '<nb_call> <nb apply> <Op name>' % (flops_msg))
otimes = [(t*100/local_time, t, a, op_cimpl.get(a, 0), otimes = [(t * 100 / local_time, t, a, op_cimpl.get(a, 0),
op_call.get(a, 0), op_apply.get(a, 0)) op_call.get(a, 0), op_apply.get(a, 0))
for a, t in iteritems(op_time)] for a, t in iteritems(op_time)]
otimes.sort() otimes.sort()
...@@ -511,23 +511,23 @@ class ProfileMode(Mode): ...@@ -511,23 +511,23 @@ class ProfileMode(Mode):
assert t == 0 assert t == 0
continue continue
tot += t tot += t
ftot = tot*100/local_time ftot = tot * 100 / local_time
if ci: if ci:
msg = '*' msg = '*'
else: else:
msg = ' ' msg = ' '
if op_flops: if op_flops:
print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %7.1f ' print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %7.1f '
'%5d %2d %s' % (f, ftot, t, tot, t/nb_call, msg, '%5d %2d %s' % (f, ftot, t, tot, t / nb_call, msg,
op_flops.get(a, -1), nb_call, nb_apply, op_flops.get(a, -1), nb_call, nb_apply,
a)) a))
else: else:
print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %5d %2d ' print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %5d %2d '
'%s' % (f, ftot, t, tot, t/nb_call, msg, nb_call, '%s' % (f, ftot, t, tot, t / nb_call, msg, nb_call,
nb_apply, a)) nb_apply, a))
print(' ... (remaining %i Op account for %6.2f%%(%.2fs) of the ' print(' ... (remaining %i Op account for %6.2f%%(%.2fs) of the '
'runtime)' % 'runtime)' %
(max(0, len(otimes)-n_ops_to_print), (max(0, len(otimes) - n_ops_to_print),
sum(f for f, t, a, ci, nb_call, nb_op in sum(f for f, t, a, ci, nb_call, nb_op in
otimes[n_ops_to_print:]), otimes[n_ops_to_print:]),
sum(t for f, t, a, ci, nb_call, nb_op in sum(t for f, t, a, ci, nb_call, nb_op in
...@@ -540,7 +540,7 @@ class ProfileMode(Mode): ...@@ -540,7 +540,7 @@ class ProfileMode(Mode):
print('<% of local_time spent at this position> <cumulative %%> ' print('<% of local_time spent at this position> <cumulative %%> '
'<apply time> <cumulative seconds> <time per call> [*] ' '<apply time> <cumulative seconds> <time per call> [*] '
'<nb_call> <Apply position> <Apply Op name>') '<nb_call> <Apply position> <Apply Op name>')
atimes = [(t*100/local_time, t, a, atimes = [(t * 100 / local_time, t, a,
[v for k, v in iteritems(fct_call) [v for k, v in iteritems(fct_call)
if k.maker.fgraph is a[1].fgraph][0]) if k.maker.fgraph is a[1].fgraph][0])
for a, t in iteritems(apply_time)] for a, t in iteritems(apply_time)]
...@@ -549,7 +549,7 @@ class ProfileMode(Mode): ...@@ -549,7 +549,7 @@ class ProfileMode(Mode):
tot = 0 tot = 0
for f, t, a, nb_call in atimes[:n_apply_to_print]: for f, t, a, nb_call in atimes[:n_apply_to_print]:
tot += t tot += t
ftot = tot*100/local_time ftot = tot * 100 / local_time
if nb_call == 0: if nb_call == 0:
continue continue
if apply_cimpl.get(a[1], False): if apply_cimpl.get(a[1], False):
...@@ -558,11 +558,11 @@ class ProfileMode(Mode): ...@@ -558,11 +558,11 @@ class ProfileMode(Mode):
msg = ' ' msg = ' '
print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %i ' print(' %4.1f%% %5.1f%% %5.3fs %5.3fs %.2es %s %i '
'%2i %s' % '%2i %s' %
(f, ftot, t, tot, t/nb_call, msg, nb_call, a[0], (f, ftot, t, tot, t / nb_call, msg, nb_call, a[0],
str(a[1]))) str(a[1])))
print(' ... (remaining %i Apply instances account for ' print(' ... (remaining %i Apply instances account for '
'%.2f%%(%.2fs) of the runtime)' % '%.2f%%(%.2fs) of the runtime)' %
(max(0, len(atimes)-n_apply_to_print), (max(0, len(atimes) - n_apply_to_print),
sum(f for f, t, a, nb_call in atimes[n_apply_to_print:]), sum(f for f, t, a, nb_call in atimes[n_apply_to_print:]),
sum(t for f, t, a, nb_call in atimes[n_apply_to_print:]))) sum(t for f, t, a, nb_call in atimes[n_apply_to_print:])))
print('(*) Op is running a c implementation') print('(*) Op is running a c implementation')
...@@ -603,7 +603,7 @@ Test them first, as they are not guaranteed to always provide a speedup.""") ...@@ -603,7 +603,7 @@ Test them first, as they are not guaranteed to always provide a speedup.""")
scal.RoundHalfAwayFromZero, scal.Log, scal.RoundHalfAwayFromZero, scal.Log,
scal.Log2, scal.Log10, scal.Log1p, scal.Log2, scal.Log10, scal.Log1p,
scal.Exp, scal.Sqrt, scal.Abs, scal.Cos, scal.Exp, scal.Sqrt, scal.Abs, scal.Cos,
scal.Sin, scal.Tan, scal.Tanh, scal.Sin, scal.Tan, scal.Tanh,
scal.Cosh, scal.Sinh, scal.Cosh, scal.Sinh,
T.nnet.sigm.ScalarSigmoid, T.nnet.sigm.ScalarSigmoid,
T.nnet.sigm.ScalarSoftplus] T.nnet.sigm.ScalarSoftplus]
...@@ -661,9 +661,9 @@ Test them first, as they are not guaranteed to always provide a speedup.""") ...@@ -661,9 +661,9 @@ Test them first, as they are not guaranteed to always provide a speedup.""")
if not config.lib.amdlibm and any([exp_float32_op(a.op) and if not config.lib.amdlibm and any([exp_float32_op(a.op) and
a.inputs[0].dtype == 'float32' a.inputs[0].dtype == 'float32'
for i, a in apply_time]): for i, a in apply_time]):
print (" - With the default gcc libm, exp in float32 is slower " print(" - With the default gcc libm, exp in float32 is slower "
"than in float64! Try Theano flag floatX=float64, or " "than in float64! Try Theano flag floatX=float64, or "
"install amdlibm and set the theano flags lib.amdlibm=True") "install amdlibm and set the theano flags lib.amdlibm=True")
printed_tip = True printed_tip = True
# tip 4 # tip 4
...@@ -672,11 +672,11 @@ Test them first, as they are not guaranteed to always provide a speedup.""") ...@@ -672,11 +672,11 @@ Test them first, as they are not guaranteed to always provide a speedup.""")
if (isinstance(node.op, T.Dot) and if (isinstance(node.op, T.Dot) and
all([len(i.type.broadcastable) == 2 all([len(i.type.broadcastable) == 2
for i in node.inputs])): for i in node.inputs])):
print((" - You have a dot operation that was not optimized to" print(" - You have a dot operation that was not optimized to"
" dot22 (which is faster). Make sure the inputs are " " dot22 (which is faster). Make sure the inputs are "
"float32 or float64, and are the same for both inputs. " "float32 or float64, and are the same for both inputs. "
"Currently they are: %s" % "Currently they are: %s" %
[i.type for i in node.inputs])) [i.type for i in node.inputs])
printed_tip = True printed_tip = True
# tip 5 # tip 5
...@@ -684,13 +684,13 @@ Test them first, as they are not guaranteed to always provide a speedup.""") ...@@ -684,13 +684,13 @@ Test them first, as they are not guaranteed to always provide a speedup.""")
node = a[1] node = a[1]
if isinstance(node.op, RandomFunction): if isinstance(node.op, RandomFunction):
printed_tip = True printed_tip = True
print (" - Replace the default random number generator by " print(" - Replace the default random number generator by "
"'from theano.sandbox.rng_mrg import MRG_RandomStreams " "'from theano.sandbox.rng_mrg import MRG_RandomStreams "
"as RandomStreams', as this is is faster. It is still " "as RandomStreams', as this is is faster. It is still "
"experimental, but seems to work correctly.") "experimental, but seems to work correctly.")
if config.device.startswith("gpu"): if config.device.startswith("gpu"):
print (" - MRG_RandomStreams is the only random number" print(" - MRG_RandomStreams is the only random number"
" generator supported on the GPU.") " generator supported on the GPU.")
break break
if not printed_tip: if not printed_tip:
......
...@@ -63,8 +63,7 @@ compiledir_format_dict = { ...@@ -63,8 +63,7 @@ compiledir_format_dict = {
"theano_version": theano.__version__, "theano_version": theano.__version__,
"numpy_version": numpy.__version__, "numpy_version": numpy.__version__,
"gxx_version": gcc_version_str.replace(" ", "_"), "gxx_version": gcc_version_str.replace(" ", "_"),
"hostname": socket.gethostname(), "hostname": socket.gethostname()}
}
def short_platform(r=None, p=None): def short_platform(r=None, p=None):
......
...@@ -108,7 +108,7 @@ def _get_lock(lock_dir=None, **kw): ...@@ -108,7 +108,7 @@ def _get_lock(lock_dir=None, **kw):
raise Exception("For some unknow reason, the lock was already " raise Exception("For some unknow reason, the lock was already "
"taken, but no start time was registered.") "taken, but no start time was registered.")
now = time.time() 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') lockpath = os.path.join(get_lock.lock_dir, 'lock')
_logger.info('Refreshing lock %s', str(lockpath)) _logger.info('Refreshing lock %s', str(lockpath))
refresh_lock(lockpath) refresh_lock(lockpath)
......
...@@ -312,7 +312,7 @@ class SequenceDB(DB): ...@@ -312,7 +312,7 @@ class SequenceDB(DB):
positions = list(self.__position__.items()) positions = list(self.__position__.items())
def c(a, b): def c(a, b):
return cmp(a[1], b[1]) return ((a[1] > b[1]) - (a[1] < b[1]))
positions.sort(c) positions.sort(c)
print(" position", positions, file=stream) print(" position", positions, file=stream)
......
...@@ -46,7 +46,7 @@ class TestCallbacks(unittest.TestCase): ...@@ -46,7 +46,7 @@ class TestCallbacks(unittest.TestCase):
def test_callback_with_ifelse(self): def test_callback_with_ifelse(self):
a, b, c = tensor.scalars('abc') 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( mode=Mode(
optimizer=None, optimizer=None,
linker=vm.VM_Linker(callback=self.callback))) linker=vm.VM_Linker(callback=self.callback)))
...@@ -62,7 +62,7 @@ def test_c_thunks(): ...@@ -62,7 +62,7 @@ def test_c_thunks():
if theano.config.cxx: if theano.config.cxx:
cases.append(True) cases.append(True)
for c_thunks in cases: 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( mode=Mode(
optimizer=None, optimizer=None,
linker=vm.VM_Linker(c_thunks=c_thunks, linker=vm.VM_Linker(c_thunks=c_thunks,
...@@ -86,7 +86,7 @@ def test_speed(): ...@@ -86,7 +86,7 @@ def test_speed():
def numpy_version(x, depth): def numpy_version(x, depth):
z = x z = x
for d in xrange(depth): for d in xrange(depth):
z = (z+z) z = (z + z)
return z return z
def time_numpy(): def time_numpy():
...@@ -136,7 +136,7 @@ def test_speed(): ...@@ -136,7 +136,7 @@ def test_speed():
print("%s takes %f s/Kop" % ( print("%s takes %f s/Kop" % (
name, 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('c|py', OpWiseCLinker)
time_linker('vmLinker', vm.VM_Linker) time_linker('vmLinker', vm.VM_Linker)
...@@ -185,7 +185,7 @@ def test_speed_lazy(): ...@@ -185,7 +185,7 @@ def test_speed_lazy():
print("%s takes %f s/Kop" % ( print("%s takes %f s/Kop" % (
name, 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', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False)) time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False))
...@@ -230,6 +230,8 @@ if run_memory_usage_tests: ...@@ -230,6 +230,8 @@ if run_memory_usage_tests:
a = cuda.CudaNdarray(n) a = cuda.CudaNdarray(n)
a.sum() a.sum()
assert c == sys.getrefcount(n) assert c == sys.getrefcount(n)
# This is to confuse flake8
a = a
del a del a
if not i % 1000: if not i % 1000:
print('.', end=' ') print('.', end=' ')
......
...@@ -282,11 +282,7 @@ class PureType(object): ...@@ -282,11 +282,7 @@ class PureType(object):
'Cannot convert Type %(othertype)s ' 'Cannot convert Type %(othertype)s '
'(of Variable %(other)s) into Type %(self)s. ' '(of Variable %(other)s) into Type %(self)s. '
'You can try to manually convert %(other)s into a %(self)s.' 'You can try to manually convert %(other)s into a %(self)s.'
% dict( % dict(othertype=other.type, other=other, self=self))
othertype=other.type,
other=other,
self=self)
)
return other return other
def is_valid_value(self, a): def is_valid_value(self, a):
......
...@@ -35,7 +35,7 @@ def ElemwiseOpTime(N, script=False, loops=1000): ...@@ -35,7 +35,7 @@ def ElemwiseOpTime(N, script=False, loops=1000):
x = T.vector('x') x = T.vector('x')
np.random.seed(1235) np.random.seed(1235)
v = np.random.random(N).astype(theano.config.floatX) 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)) f1 = theano.function([x], T.tanh(x))
if not script: if not script:
if theano.config.openmp: if theano.config.openmp:
......
...@@ -194,7 +194,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -194,7 +194,7 @@ class TestConv3dFFT(unittest.TestCase):
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() 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): def run_conv_full(self, inputs_shape, filters_shape, pad=False):
inputs_val = numpy.random.random(inputs_shape).astype('float32') inputs_val = numpy.random.random(inputs_shape).astype('float32')
...@@ -220,7 +220,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -220,7 +220,7 @@ class TestConv3dFFT(unittest.TestCase):
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() 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): def test_valid(self):
self.run_conv_valid(inputs_shape=(16, 20, 32, 16, 1), self.run_conv_valid(inputs_shape=(16, 20, 32, 16, 1),
...@@ -299,7 +299,7 @@ class TestConv3dFFT(unittest.TestCase): ...@@ -299,7 +299,7 @@ class TestConv3dFFT(unittest.TestCase):
res_ref = f_ref() res_ref = f_ref()
res_fft = f_fft() 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): def test_opt_convtransp3d_fft(self):
inputs_shape = (2, 9, 16, 12, 10) inputs_shape = (2, 9, 16, 12, 10)
......
import six.moves.cPickle as pickle
import os.path import os.path
import sys
from nose.tools import assert_raises from nose.tools import assert_raises
import numpy import numpy
......
...@@ -255,7 +255,7 @@ def local_gpu_elemwise(node): ...@@ -255,7 +255,7 @@ def local_gpu_elemwise(node):
scal_op = op.scalar_op scal_op = op.scalar_op
name = op.name name = op.name
if name: if name:
name = 'Gpu'+name name = 'Gpu' + name
res = GpuElemwise(scal_op, name=name, res = GpuElemwise(scal_op, name=name,
inplace_pattern=copy.copy(op.inplace_pattern), inplace_pattern=copy.copy(op.inplace_pattern),
nfunc_spec=op.nfunc_spec) nfunc_spec=op.nfunc_spec)
...@@ -349,7 +349,7 @@ def local_gpu_pdbbreakpoint_op(node): ...@@ -349,7 +349,7 @@ def local_gpu_pdbbreakpoint_op(node):
nb_monitored_vars = len(node.outputs) nb_monitored_vars = len(node.outputs)
for i in range(nb_monitored_vars): for i in range(nb_monitored_vars):
inp = old_inputs[i+1] inp = old_inputs[i + 1]
out = old_outputs[i] out = old_outputs[i]
input_is_from_gpu = (inp.owner and input_is_from_gpu = (inp.owner and
......
...@@ -25,12 +25,12 @@ def test_grad(): ...@@ -25,12 +25,12 @@ def test_grad():
op = SymPyCCode([xs], xs**2) op = SymPyCCode([xs], xs**2)
zt = op(xt) zt = op(xt)
ztprime = theano.grad(zt, xt) ztprime = theano.grad(zt, xt)
assert ztprime.owner.op.expr == 2*xs assert ztprime.owner.op.expr == 2 * xs
def test_multivar_grad(): def test_multivar_grad():
op = SymPyCCode([xs, ys], xs**2 + ys**3) op = SymPyCCode([xs, ys], xs ** 2 + ys ** 3)
zt = op(xt, yt) zt = op(xt, yt)
dzdx, dzdy = theano.grad(zt, [xt, yt]) dzdx, dzdy = theano.grad(zt, [xt, yt])
assert dzdx.owner.op.expr == 2*xs assert dzdx.owner.op.expr == 2 * xs
assert dzdy.owner.op.expr == 3*ys**2 assert dzdy.owner.op.expr == 3 * ys ** 2
...@@ -136,16 +136,15 @@ class DimShuffle(Op): ...@@ -136,16 +136,15 @@ class DimShuffle(Op):
# returning False for numpy integers. # returning False for numpy integers.
# See <http://projects.scipy.org/numpy/ticket/2235>. # See <http://projects.scipy.org/numpy/ticket/2235>.
if not isinstance(j, (int, numpy.integer)): if not isinstance(j, (int, numpy.integer)):
raise TypeError( raise TypeError("DimShuffle indices must be python ints.")
"DimShuffle indices must be python ints.")
if j >= len(input_broadcastable): if j >= len(input_broadcastable):
raise ValueError(("new_order[%d] is %d, but the input " raise ValueError(("new_order[%d] is %d, but the input "
"only has %d axes.") % "only has %d axes.") %
(i, j, len(input_broadcastable))) (i, j, len(input_broadcastable)))
if j in new_order[(i + 1):]: if j in new_order[(i + 1):]:
raise ValueError(( raise ValueError("The same input dimension may not appear "
"The same input dimension may not appear twice in the " "twice in the list of output dimensions",
"list of output dimensions", (new_order))) new_order)
# list of dimensions of the input to drop # list of dimensions of the input to drop
self.drop = [] self.drop = []
...@@ -158,8 +157,8 @@ class DimShuffle(Op): ...@@ -158,8 +157,8 @@ class DimShuffle(Op):
else: else:
# we cannot drop non-broadcastable dimensions # we cannot drop non-broadcastable dimensions
raise ValueError( raise ValueError(
"You cannot drop a non-broadcastable dimension.", "You cannot drop a non-broadcastable dimension.",
(input_broadcastable, new_order)) (input_broadcastable, new_order))
# this is the list of the original dimensions that we keep # this is the list of the original dimensions that we keep
self.shuffle = [x for x in new_order if x != 'x'] self.shuffle = [x for x in new_order if x != 'x']
...@@ -246,7 +245,7 @@ class DimShuffle(Op): ...@@ -246,7 +245,7 @@ class DimShuffle(Op):
raise TypeError(res) raise TypeError(res)
# transpose # transpose
res = res.transpose(self.shuffle+self.drop) res = res.transpose(self.shuffle + self.drop)
# augment # augment
shape = list(res.shape[:len(self.shuffle)]) shape = list(res.shape[:len(self.shuffle)])
...@@ -339,26 +338,27 @@ class DimShuffle(Op): ...@@ -339,26 +338,27 @@ class DimShuffle(Op):
# npy_intp* strides, void* data, int itemsize, int flags, PyObject* obj) # npy_intp* strides, void* data, int itemsize, int flags, PyObject* obj)
# #
close_bracket = [ close_bracket = [
# create a new array, # create a new array,
('%(res)s = (PyArrayObject*)PyArray_New(&PyArray_Type, ' ('%(res)s = (PyArrayObject*)PyArray_New(&PyArray_Type, '
'' + str(nd_out) + ', dimensions, ' '' + str(nd_out) + ', dimensions, '
'PyArray_TYPE(%(basename)s), strides, ' 'PyArray_TYPE(%(basename)s), strides, '
'PyArray_DATA(%(basename)s), PyArray_ITEMSIZE(%(basename)s), ' 'PyArray_DATA(%(basename)s), PyArray_ITEMSIZE(%(basename)s), '
# borrow only the writable flag from the base # borrow only the writable flag from the base
# the NPY_OWNDATA flag will default to 0. # the NPY_OWNDATA flag will default to 0.
'(NPY_ARRAY_WRITEABLE*PyArray_ISWRITEABLE(%(basename)s)), NULL)'), '(NPY_ARRAY_WRITEABLE*PyArray_ISWRITEABLE(%(basename)s)), '
'if (%(res)s == NULL) %(fail)s;', 'NULL)'),
# recalculate flags: CONTIGUOUS, FORTRAN, ALIGNED 'if (%(res)s == NULL) %(fail)s;',
'PyArray_UpdateFlags(%(res)s, NPY_ARRAY_UPDATE_ALL)', # recalculate flags: CONTIGUOUS, FORTRAN, ALIGNED
# we are making a view in both inplace and non-inplace cases 'PyArray_UpdateFlags(%(res)s, NPY_ARRAY_UPDATE_ALL)',
""" # we are making a view in both inplace and non-inplace cases
"""
#if NPY_API_VERSION < 0x00000007 #if NPY_API_VERSION < 0x00000007
PyArray_BASE(%(res)s) = (PyObject*)%(basename)s; PyArray_BASE(%(res)s) = (PyObject*)%(basename)s;
#else #else
PyArray_SetBaseObject(%(res)s, (PyObject*)%(basename)s); PyArray_SetBaseObject(%(res)s, (PyObject*)%(basename)s);
#endif #endif
""" """
'}'] '}']
full_code = statements(check_input_nd full_code = statements(check_input_nd
+ clear_output + clear_output
...@@ -529,8 +529,8 @@ class Elemwise(OpenMPOp): ...@@ -529,8 +529,8 @@ class Elemwise(OpenMPOp):
""" """
inputs = list(map(as_tensor_variable, inputs)) inputs = list(map(as_tensor_variable, inputs))
shadow = self.scalar_op.make_node( shadow = self.scalar_op.make_node(
*[get_scalar_type(dtype=i.type.dtype).make_variable() *[get_scalar_type(dtype=i.type.dtype).make_variable()
for i in inputs]) for i in inputs])
target_length = max([input.type.ndim for input in inputs]) target_length = max([input.type.ndim for input in inputs])
...@@ -567,9 +567,9 @@ class Elemwise(OpenMPOp): ...@@ -567,9 +567,9 @@ class Elemwise(OpenMPOp):
for ob, ib in izip(out_broadcastables[overwriter], for ob, ib in izip(out_broadcastables[overwriter],
inputs[overwritten].type.broadcastable): inputs[overwritten].type.broadcastable):
if ib and not ob: if ib and not ob:
raise ValueError(( raise ValueError(
"Operation cannot be done inplace on an input " "Operation cannot be done inplace on an input "
"with broadcasted dimensions.")) "with broadcasted dimensions.")
out_dtypes = [o.type.dtype for o in shadow.outputs] out_dtypes = [o.type.dtype for o in shadow.outputs]
if any(inputs[i].type.dtype != out_dtypes[o] if any(inputs[i].type.dtype != out_dtypes[o]
...@@ -767,7 +767,7 @@ class Elemwise(OpenMPOp): ...@@ -767,7 +767,7 @@ class Elemwise(OpenMPOp):
res = theano.tensor.constant(numpy.asarray(r.data), dtype=r.type.dtype) res = theano.tensor.constant(numpy.asarray(r.data), dtype=r.type.dtype)
return DimShuffle((), ['x'] * nd, inplace=False)(res) return DimShuffle((), ['x'] * nd, inplace=False)(res)
new_r = Elemwise(node.op, {})( new_r = Elemwise(node.op, {})(
*[transform(ipt) for ipt in node.inputs]) *[transform(ipt) for ipt in node.inputs])
return new_r return new_r
ret = [] ret = []
for scalar_igrad, ipt in izip(scalar_igrads, inputs): for scalar_igrad, ipt in izip(scalar_igrads, inputs):
...@@ -1041,15 +1041,15 @@ class Elemwise(OpenMPOp): ...@@ -1041,15 +1041,15 @@ class Elemwise(OpenMPOp):
# We generate the C code of the inner loop using the scalar op # We generate the C code of the inner loop using the scalar op
task_code = self.scalar_op.c_code( task_code = self.scalar_op.c_code(
Apply(self.scalar_op, Apply(self.scalar_op,
[get_scalar_type(dtype=input.type.dtype).make_variable() [get_scalar_type(dtype=input.type.dtype).make_variable()
for input in node.inputs], for input in node.inputs],
[get_scalar_type(dtype=output.type.dtype).make_variable() [get_scalar_type(dtype=output.type.dtype).make_variable()
for output in node.outputs]), for output in node.outputs]),
nodename + '_scalar_', nodename + '_scalar_',
["%s_i" % s for s in _inames], ["%s_i" % s for s in _inames],
["%s_i" % s for s in onames], ["%s_i" % s for s in onames],
sub) sub)
code = """ code = """
{ {
%(defines)s %(defines)s
...@@ -1379,7 +1379,7 @@ class CAReduce(Op): ...@@ -1379,7 +1379,7 @@ class CAReduce(Op):
def __str__(self): def __str__(self):
if self.axis is not None: if self.axis is not None:
return "Reduce{%s}{%s}" % ( return "Reduce{%s}{%s}" % (
self.scalar_op, ", ".join(str(x) for x in self.axis)) self.scalar_op, ", ".join(str(x) for x in self.axis))
else: else:
return "Reduce{%s}" % self.scalar_op return "Reduce{%s}" % self.scalar_op
...@@ -1462,8 +1462,8 @@ class CAReduce(Op): ...@@ -1462,8 +1462,8 @@ class CAReduce(Op):
if hasattr(self, 'acc_dtype') and self.acc_dtype is not None: if hasattr(self, 'acc_dtype') and self.acc_dtype is not None:
acc_type = TensorType( acc_type = TensorType(
broadcastable=node.outputs[0].broadcastable, broadcastable=node.outputs[0].broadcastable,
dtype=self.acc_dtype) dtype=self.acc_dtype)
adtype = acc_type.dtype_specs()[1] adtype = acc_type.dtype_specs()[1]
else: else:
adtype = odtype adtype = odtype
...@@ -1510,12 +1510,12 @@ class CAReduce(Op): ...@@ -1510,12 +1510,12 @@ class CAReduce(Op):
# Allocate output buffer # Allocate output buffer
alloc += cgen.make_declare( alloc += cgen.make_declare(
[list(range(nnested)) + ['x'] * len(axis)], [list(range(nnested)) + ['x'] * len(axis)],
[odtype], dict(sub, lv0=oname)) [odtype], dict(sub, lv0=oname))
alloc += cgen.make_alloc([order1], odtype, sub) alloc += cgen.make_alloc([order1], odtype, sub)
alloc += cgen.make_checks( alloc += cgen.make_checks(
[list(range(nnested)) + ['x'] * len(axis)], [list(range(nnested)) + ['x'] * len(axis)],
[odtype], dict(sub, lv0=oname)) [odtype], dict(sub, lv0=oname))
if adtype != odtype: if adtype != odtype:
# Allocate accumulation buffer # Allocate accumulation buffer
...@@ -1523,12 +1523,12 @@ class CAReduce(Op): ...@@ -1523,12 +1523,12 @@ class CAReduce(Op):
sub['olv'] = aname sub['olv'] = aname
alloc += cgen.make_declare( alloc += cgen.make_declare(
[list(range(nnested)) + ['x'] * len(axis)], [list(range(nnested)) + ['x'] * len(axis)],
[adtype], dict(sub, lv0=aname)) [adtype], dict(sub, lv0=aname))
alloc += cgen.make_alloc([order1], adtype, sub) alloc += cgen.make_alloc([order1], adtype, sub)
alloc += cgen.make_checks( alloc += cgen.make_checks(
[list(range(nnested)) + ['x'] * len(axis)], [list(range(nnested)) + ['x'] * len(axis)],
[adtype], dict(sub, lv0=aname)) [adtype], dict(sub, lv0=aname))
if hasattr(self.scalar_op, 'identity'): if hasattr(self.scalar_op, 'identity'):
identity = self.scalar_op.identity identity = self.scalar_op.identity
...@@ -1608,8 +1608,8 @@ for(int i=0;i<PyArray_NDIM(%(iname)s);i++){ ...@@ -1608,8 +1608,8 @@ for(int i=0;i<PyArray_NDIM(%(iname)s);i++){
else: else:
all_code = [task0_decl + code1] all_code = [task0_decl + code1]
loop = cgen.make_loop_careduce( loop = cgen.make_loop_careduce(
[order, list(range(nnested)) + ['x'] * len(axis)], [order, list(range(nnested)) + ['x'] * len(axis)],
[idtype, adtype], all_code, sub) [idtype, adtype], all_code, sub)
end = "" end = ""
if adtype != odtype: if adtype != odtype:
...@@ -1789,19 +1789,16 @@ class CAReduceDtype(CAReduce): ...@@ -1789,19 +1789,16 @@ class CAReduceDtype(CAReduce):
int32='int64', int32='int64',
uint8='uint32', uint8='uint32',
uint16='uint32', uint16='uint32',
uint32='uint64', uint32='uint64').get(idtype, idtype)
).get(idtype, idtype)
if dtype is None: if dtype is None:
# If input has a discrete dtype, upcast it to 64 # If input has a discrete dtype, upcast it to 64
return dict( return dict(
int8='int64', int8='int64',
int16='int64', int16='int64',
int32='int64', int32='int64',
uint8='uint64', uint8='uint64',
uint16='uint64', uint16='uint64',
uint32='uint64', uint32='uint64').get(idtype, idtype)
).get(idtype, idtype)
else: else:
# The important is that the accumulator dtype does not # The important is that the accumulator dtype does not
# lose precision. Then, the result can be downcasted. # lose precision. Then, the result can be downcasted.
...@@ -1811,16 +1808,15 @@ class CAReduceDtype(CAReduce): ...@@ -1811,16 +1808,15 @@ class CAReduceDtype(CAReduce):
acc_dtype = self.acc_dtype acc_dtype = self.acc_dtype
if acc_dtype is None: if acc_dtype is None:
return dict( return dict(
int8='int64', int8='int64',
int16='int64', int16='int64',
int32='int64', int32='int64',
uint8='uint64', uint8='uint64',
uint16='uint64', uint16='uint64',
uint32='uint64', uint32='uint64',
float16='float32', float16='float32',
float32='float64', float32='float64',
complex64='complex128', complex64='complex128').get(idtype, idtype)
).get(idtype, idtype)
elif (acc_dtype in theano.tensor.continuous_dtypes and elif (acc_dtype in theano.tensor.continuous_dtypes and
idtype in theano.tensor.discrete_dtypes): idtype in theano.tensor.discrete_dtypes):
# Specifying a continuous accumulator for discrete input is OK # Specifying a continuous accumulator for discrete input is OK
...@@ -1830,17 +1826,17 @@ class CAReduceDtype(CAReduce): ...@@ -1830,17 +1826,17 @@ class CAReduceDtype(CAReduce):
upcasted_dtype = scalar.upcast(idtype, acc_dtype) upcasted_dtype = scalar.upcast(idtype, acc_dtype)
if acc_dtype != upcasted_dtype: if acc_dtype != upcasted_dtype:
raise TypeError( raise TypeError(
'Cannot build %s node with input dtype %s ' 'Cannot build %s node with input dtype %s '
'and acc_dtype %s, as precision would be lost. ' 'and acc_dtype %s, as precision would be lost. '
'To correct this error, you can:\n' 'To correct this error, you can:\n'
' - not specify acc_dtype, or\n' ' - not specify acc_dtype, or\n'
' - use an acc_dtype at least as precise as %s.\n' ' - use an acc_dtype at least as precise as %s.\n'
' - specify "dtype" instead of "acc_dtype", so ' ' - specify "dtype" instead of "acc_dtype", so '
'the reduction will be precise, but the result will ' 'the reduction will be precise, but the result will '
'be casted into "dtype" at the end.\n' 'be casted into "dtype" at the end.\n'
'If you are expecting the precision loss, you can ' 'If you are expecting the precision loss, you can '
'use tensor.cast(..., dtype="%s"), on your input.' 'use tensor.cast(..., dtype="%s"), on your input.'
% (self, idtype, acc_dtype, upcasted_dtype, acc_dtype)) % (self, idtype, acc_dtype, upcasted_dtype, acc_dtype))
return acc_dtype return acc_dtype
def make_node(self, input): def make_node(self, input):
...@@ -2071,7 +2067,7 @@ class Prod(CAReduceDtype): ...@@ -2071,7 +2067,7 @@ class Prod(CAReduceDtype):
where_zeros = T.eq(prod_in, 0.0) where_zeros = T.eq(prod_in, 0.0)
sum_where_zeros = T.sum(where_zeros, axis=self.axis) sum_where_zeros = T.sum(where_zeros, axis=self.axis)
groups_with_single_zero = T.eq(sum_where_zeros, 1).dimshuffle( groups_with_single_zero = T.eq(sum_where_zeros, 1).dimshuffle(
new_dims) new_dims)
# tensor with 0 everywhere except for those places where # tensor with 0 everywhere except for those places where
# a 0 part of a group with a single zero was to be found # a 0 part of a group with a single zero was to be found
where_single_zero = groups_with_single_zero * where_zeros where_single_zero = groups_with_single_zero * where_zeros
...@@ -2081,7 +2077,7 @@ class Prod(CAReduceDtype): ...@@ -2081,7 +2077,7 @@ class Prod(CAReduceDtype):
# only take ProdWithoutZeros for the groups with single zeros # only take ProdWithoutZeros for the groups with single zeros
# with non-null incoming gradient # with non-null incoming gradient
where_to_take_prod_without_zeros = ( where_to_take_prod_without_zeros = (
groups_with_single_zero * where_gz_not_zero) groups_with_single_zero * where_gz_not_zero)
# preprocess the original input so that we set 0 everywhere # preprocess the original input so that we set 0 everywhere
# except for groups that contain a single zero, to avoid computing # except for groups that contain a single zero, to avoid computing
# multiplications on other groups # multiplications on other groups
...@@ -2090,16 +2086,16 @@ class Prod(CAReduceDtype): ...@@ -2090,16 +2086,16 @@ class Prod(CAReduceDtype):
# this is pretty efficient already (no multiplication if 0), but # this is pretty efficient already (no multiplication if 0), but
# it'd be even better if we had a lazy if per element # it'd be even better if we had a lazy if per element
prod_without_zeros = ProdWithoutZeros(axis=self.axis)( prod_without_zeros = ProdWithoutZeros(axis=self.axis)(
prod_without_zeros_in) prod_without_zeros_in)
prod_without_zeros = prod_without_zeros.dimshuffle(new_dims) prod_without_zeros = prod_without_zeros.dimshuffle(new_dims)
groups_without_zeros = T.eq(sum_where_zeros, 0).dimshuffle( groups_without_zeros = T.eq(sum_where_zeros, 0).dimshuffle(
new_dims) new_dims)
final_grad = T.switch( final_grad = T.switch(
groups_without_zeros, groups_without_zeros,
grad_case_without_zeros, grad_case_without_zeros,
T.switch(where_single_zero, prod_without_zeros, 0.0) * gz) T.switch(where_single_zero, prod_without_zeros, 0.0) * gz)
return [final_grad] return [final_grad]
......
...@@ -29,9 +29,6 @@ def _scal_inplace(symbol): ...@@ -29,9 +29,6 @@ def _scal_inplace(symbol):
if not r.owner: if not r.owner:
return False return False
op = r.owner.op 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 return r.owner.op == rval
pprint.assign(chk, printing.FunctionPrinter(symbolname.replace('_inplace', '='))) pprint.assign(chk, printing.FunctionPrinter(symbolname.replace('_inplace', '=')))
...@@ -348,17 +345,13 @@ def conj_inplace(a): ...@@ -348,17 +345,13 @@ def conj_inplace(a):
pprint.assign(add_inplace, printing.OperatorPrinter('+=', -2, 'either')) pprint.assign(add_inplace, printing.OperatorPrinter('+=', -2, 'either'))
pprint.assign(mul_inplace, printing.OperatorPrinter('*=', -1, 'either')) pprint.assign(mul_inplace, printing.OperatorPrinter('*=', -1, 'either'))
pprint.assign(sub_inplace, printing.OperatorPrinter('-=', -2, 'left')) 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(true_div_inplace, printing.OperatorPrinter('/=', -1, 'left'))
pprint.assign(int_div_inplace, printing.OperatorPrinter('//=', -1, 'left')) pprint.assign(int_div_inplace, printing.OperatorPrinter('//=', -1, 'left'))
pprint.assign(pow_inplace, printing.OperatorPrinter('**=', 1, 'right')) pprint.assign(pow_inplace, printing.OperatorPrinter('**=', 1, 'right'))
def transpose_inplace(x, **kwargs): 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)) dims = list(range(x.ndim - 1, -1, -1))
return elemwise.DimShuffle(x.broadcastable, dims, inplace=True)(x) 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, ...@@ -24,11 +24,11 @@ def randomstate_constructor(value, name=None, strict=False,
if not borrow: if not borrow:
value = copy.deepcopy(value) value = copy.deepcopy(value)
return RandomStateSharedVariable( return RandomStateSharedVariable(
type=raw_random.random_state_type, type=raw_random.random_state_type,
value=value, value=value,
name=name, name=name,
strict=strict, strict=strict,
allow_downcast=allow_downcast) allow_downcast=allow_downcast)
class RandomStreams(raw_random.RandomStreamsBase): class RandomStreams(raw_random.RandomStreamsBase):
......
...@@ -25,15 +25,14 @@ except ImportError: ...@@ -25,15 +25,14 @@ except ImportError:
imported_scipy = False imported_scipy = False
MATRIX_STRUCTURES = ( MATRIX_STRUCTURES = (
'general', 'general',
'symmetric', 'symmetric',
'lower_triangular', 'lower_triangular',
'upper_triangular', 'upper_triangular',
'hermitian', 'hermitian',
'banded', 'banded',
'diagonal', 'diagonal',
'toeplitz', 'toeplitz')
)
class Cholesky(Op): class Cholesky(Op):
...@@ -168,8 +167,8 @@ class Solve(Op): ...@@ -168,8 +167,8 @@ class Solve(Op):
assert A.ndim == 2 assert A.ndim == 2
assert b.ndim in [1, 2] assert b.ndim in [1, 2]
otype = tensor.tensor( otype = tensor.tensor(
broadcastable=b.broadcastable, broadcastable=b.broadcastable,
dtype=(A * b).dtype) dtype=(A * b).dtype)
return Apply(self, [A, b], [otype]) return Apply(self, [A, b], [otype])
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
...@@ -294,7 +293,7 @@ class EigvalshGrad(Op): ...@@ -294,7 +293,7 @@ class EigvalshGrad(Op):
(a, b, gw) = inputs (a, b, gw) = inputs
w, v = scipy.linalg.eigh(a, b, lower=self.lower) w, v = scipy.linalg.eigh(a, b, lower=self.lower)
gA = v.dot(numpy.diag(gw).dot(v.T)) 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 # See EighGrad comments for an explanation of these lines
out1 = self.tri0(gA) + self.tri1(gA).T out1 = self.tri0(gA) + self.tri1(gA).T
......
...@@ -155,16 +155,16 @@ def get_canonical_form_slice(theslice, length): ...@@ -155,16 +155,16 @@ def get_canonical_form_slice(theslice, length):
1), 1) 1), 1)
stop_plus_len = stop + length stop_plus_len = stop + length
stop = switch( stop = switch(
lt(stop, 0), lt(stop, 0),
# stop < 0 # stop < 0
switch( switch(
lt(stop_plus_len, 0), lt(stop_plus_len, 0),
# stop + len < 0 # stop + len < 0
0, 0,
# stop + len >= 0 # stop + len >= 0
stop_plus_len), stop_plus_len),
# stop >= 0: use min(stop, length) # stop >= 0: use min(stop, length)
switch(lt(stop, length), stop, length)) switch(lt(stop, length), stop, length))
return slice(0, stop, 1), 1 return slice(0, stop, 1), 1
elif is_stop_length: elif is_stop_length:
# start:length:1 # start:length:1
...@@ -173,16 +173,16 @@ def get_canonical_form_slice(theslice, length): ...@@ -173,16 +173,16 @@ def get_canonical_form_slice(theslice, length):
length, 1), 1 length, 1), 1
start_plus_len = start + length start_plus_len = start + length
start = switch( start = switch(
lt(start, 0), lt(start, 0),
# start < 0 # start < 0
switch( switch(
lt(start_plus_len, 0), lt(start_plus_len, 0),
# start + len < 0 # start + len < 0
0, 0,
# start + len >= 0 # start + len >= 0
start_plus_len), start_plus_len),
# start >= 0: use min(start, length) # start >= 0: use min(start, length)
switch(lt(start, length), start, length)) switch(lt(start, length), start, length))
return slice(start, length, 1), 1 return slice(start, length, 1), 1
# This is the generic case. # This is the generic case.
...@@ -614,10 +614,8 @@ class Subtensor(Op): ...@@ -614,10 +614,8 @@ class Subtensor(Op):
helper_c_code helper_c_code
""" """
return { return {"c_prefix": "PyArray",
"c_prefix": "PyArray", "strides_mul": 1}
"strides_mul": 1,
}
@staticmethod @staticmethod
def helper_c_code(node, name, inputs, outputs, sub, idx_list, view_ndim, def helper_c_code(node, name, inputs, outputs, sub, idx_list, view_ndim,
......
...@@ -389,17 +389,15 @@ class _tensor_py_operators: ...@@ -389,17 +389,15 @@ class _tensor_py_operators:
axis = i axis = i
if advanced: if advanced:
if (axis is not None if (axis is not None and
and all(isinstance(a, slice) and all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[:axis]) equal_slices(a, slice(None)) for a in args[:axis]) and
and all(isinstance(a, slice) and all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[axis + 1:]) equal_slices(a, slice(None)) for a in args[axis + 1:]) and
and isinstance(args[axis], ( isinstance(args[axis],
numpy.ndarray, (numpy.ndarray, list,
list, TensorVariable, TensorConstant,
TensorVariable, theano.tensor.sharedvar.TensorSharedVariable))):
TensorConstant,
theano.tensor.sharedvar.TensorSharedVariable))):
return self.take(args[axis], axis) return self.take(args[axis], axis)
else: else:
return theano.tensor.subtensor.advanced_subtensor(self, *args) return theano.tensor.subtensor.advanced_subtensor(self, *args)
......
...@@ -88,7 +88,7 @@ class PdbBreakpoint(Op): ...@@ -88,7 +88,7 @@ class PdbBreakpoint(Op):
for i in range(len(monitored_vars)): for i in range(len(monitored_vars)):
# Every output i is a view of the input i+1 because of the input # Every output i is a view of the input i+1 because of the input
# condition. # condition.
new_op.view_map[i] = [i+1] new_op.view_map[i] = [i + 1]
new_op.inp_types.append(monitored_vars[i].type) new_op.inp_types.append(monitored_vars[i].type)
# Build the Apply node # Build the Apply node
...@@ -125,7 +125,7 @@ class PdbBreakpoint(Op): ...@@ -125,7 +125,7 @@ class PdbBreakpoint(Op):
else: else:
# Simply return views on the monitored variables # Simply return views on the monitored variables
for i in range(len(output_storage)): 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): def grad(self, inputs, output_gradients):
return ([DisconnectedType()()] + output_gradients) return ([DisconnectedType()()] + output_gradients)
......
...@@ -20,4 +20,4 @@ def disturb_mem(): ...@@ -20,4 +20,4 @@ def disturb_mem():
ms = int(ms) ms = int(ms)
n = ms % 1000 n = ms % 1000
m = 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): ...@@ -12,8 +12,8 @@ class dictionary_output_checker(unittest.TestCase):
''' '''
x = T.scalar() x = T.scalar()
f = theano.function([x], outputs={'a': x, 'c': x*2, f = theano.function([x], outputs={'a': x, 'c': x * 2,
'b': x*3, '1': x*4}) 'b': x * 3, '1': x * 4})
outputs = f(10.0) outputs = f(10.0)
......
...@@ -6,7 +6,6 @@ from nose.plugins.skip import SkipTest ...@@ -6,7 +6,6 @@ from nose.plugins.skip import SkipTest
import os import os
from fnmatch import fnmatch from fnmatch import fnmatch
import theano import theano
from theano.compat import PY3
try: try:
import flake8.engine import flake8.engine
import flake8.main import flake8.main
...@@ -18,6 +17,10 @@ __authors__ = ("Saizheng Zhang") ...@@ -18,6 +17,10 @@ __authors__ = ("Saizheng Zhang")
__copyright__ = "(c) 2015, Universite de Montreal" __copyright__ = "(c) 2015, Universite de Montreal"
__contact__ = "Saizheng Zhang <saizhenglisa..at..gmail.com>" __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 = [ whitelist_flake8 = [
"compat/six.py", # This is bundled code that will be deleted, don't fix it "compat/six.py", # This is bundled code that will be deleted, don't fix it
"__init__.py", "__init__.py",
...@@ -74,7 +77,6 @@ whitelist_flake8 = [ ...@@ -74,7 +77,6 @@ whitelist_flake8 = [
"tensor/extra_ops.py", "tensor/extra_ops.py",
"tensor/nlinalg.py", "tensor/nlinalg.py",
"tensor/blas_c.py", "tensor/blas_c.py",
"tensor/io.py",
"tensor/elemwise_cgen.py", "tensor/elemwise_cgen.py",
"tensor/raw_random.py", "tensor/raw_random.py",
"tensor/blas_scipy.py", "tensor/blas_scipy.py",
...@@ -93,7 +95,6 @@ whitelist_flake8 = [ ...@@ -93,7 +95,6 @@ whitelist_flake8 = [
"tensor/tests/test_merge.py", "tensor/tests/test_merge.py",
"tensor/tests/test_gc.py", "tensor/tests/test_gc.py",
"tensor/tests/test_complex.py", "tensor/tests/test_complex.py",
"tensor/tests/test_type_other.py",
"tensor/tests/test_io.py", "tensor/tests/test_io.py",
"tensor/tests/test_sharedvar.py", "tensor/tests/test_sharedvar.py",
"tensor/tests/test_fourier.py", "tensor/tests/test_fourier.py",
...@@ -160,8 +161,6 @@ whitelist_flake8 = [ ...@@ -160,8 +161,6 @@ whitelist_flake8 = [
"sandbox/cuda/opt.py", "sandbox/cuda/opt.py",
"sandbox/cuda/blas.py", "sandbox/cuda/blas.py",
"sandbox/cuda/blocksparse.py", "sandbox/cuda/blocksparse.py",
"sandbox/cuda/GpuConv3D.py",
"sandbox/cuda/extra_ops.py",
"sandbox/cuda/rng_curand.py", "sandbox/cuda/rng_curand.py",
"sandbox/cuda/fftconv.py", "sandbox/cuda/fftconv.py",
"sandbox/cuda/kernel_codegen.py", "sandbox/cuda/kernel_codegen.py",
...@@ -172,7 +171,6 @@ whitelist_flake8 = [ ...@@ -172,7 +171,6 @@ whitelist_flake8 = [
"sandbox/cuda/tests/test_gradient.py", "sandbox/cuda/tests/test_gradient.py",
"sandbox/cuda/tests/test_neighbours.py", "sandbox/cuda/tests/test_neighbours.py",
"sandbox/cuda/tests/test_conv_cuda_ndarray.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_var.py",
"sandbox/cuda/tests/test_opt.py", "sandbox/cuda/tests/test_opt.py",
"sandbox/cuda/tests/test_blas.py", "sandbox/cuda/tests/test_blas.py",
...@@ -235,7 +233,6 @@ whitelist_flake8 = [ ...@@ -235,7 +233,6 @@ whitelist_flake8 = [
"misc/pycuda_utils.py", "misc/pycuda_utils.py",
"misc/pycuda_example.py", "misc/pycuda_example.py",
"misc/ordered_set.py", "misc/ordered_set.py",
"misc/windows.py",
"misc/strutil.py", "misc/strutil.py",
"misc/gnumpy_utils.py", "misc/gnumpy_utils.py",
"misc/may_share_memory.py", "misc/may_share_memory.py",
...@@ -250,7 +247,6 @@ whitelist_flake8 = [ ...@@ -250,7 +247,6 @@ whitelist_flake8 = [
"misc/tests/test_pycuda_example.py", "misc/tests/test_pycuda_example.py",
"misc/hooks/reindent.py", "misc/hooks/reindent.py",
"misc/hooks/check_whitespace.py", "misc/hooks/check_whitespace.py",
"sparse/sharedvar.py",
"sparse/type.py", "sparse/type.py",
"sparse/__init__.py", "sparse/__init__.py",
"sparse/opt.py", "sparse/opt.py",
...@@ -308,15 +304,13 @@ def test_format_flake8(): ...@@ -308,15 +304,13 @@ def test_format_flake8():
""" """
if not flake8_available: if not flake8_available:
raise SkipTest("flake8 is not installed") raise SkipTest("flake8 is not installed")
if PY3:
raise SkipTest("not testing in python3 since 2to3 ran")
total_errors = 0 total_errors = 0
for path in list_files(): for path in list_files():
rel_path = os.path.relpath(path, theano.__path__[0]) rel_path = os.path.relpath(path, theano.__path__[0])
if rel_path in whitelist_flake8: if rel_path in whitelist_flake8:
continue continue
else: else:
error_num = flake8.main.check_file(path) error_num = flake8.main.check_file(path, ignore=ignore)
total_errors += error_num total_errors += error_num
if total_errors > 0: if total_errors > 0:
raise AssertionError("FLAKE8 Format not respected") raise AssertionError("FLAKE8 Format not respected")
...@@ -332,7 +326,8 @@ def print_files_information_flake8(): ...@@ -332,7 +326,8 @@ def print_files_information_flake8():
non_infracting_files = [] non_infracting_files = []
for path in list_files(): for path in list_files():
rel_path = os.path.relpath(path, theano.__path__[0]) 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 number_of_infractions > 0:
if rel_path not in whitelist_flake8: if rel_path not in whitelist_flake8:
infracting_files.append(rel_path) infracting_files.append(rel_path)
...@@ -359,7 +354,8 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'): ...@@ -359,7 +354,8 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
for (dir, _, files) in os.walk(dir_path): for (dir, _, files) in os.walk(dir_path):
for f in files: for f in files:
if fnmatch(f, pattern): 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: if error_num > 0:
path = os.path.relpath(os.path.join(dir, f), path = os.path.relpath(os.path.join(dir, f),
theano.__path__[0]) theano.__path__[0])
......
...@@ -495,17 +495,17 @@ def test_scan_debugprint3(): ...@@ -495,17 +495,17 @@ def test_scan_debugprint3():
def test_scan_debugprint4(): def test_scan_debugprint4():
def fn(a_m2, a_m1, b_m2, b_m1): 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)) a0 = theano.shared(numpy.arange(2))
b0 = theano.shared(numpy.arange(2)) b0 = theano.shared(numpy.arange(2))
(a, b), _ = theano.scan(fn, outputs_info=[ (a, b), _ = theano.scan(
{'initial': a0, 'taps': [-2, -1]}, fn, outputs_info=[{'initial': a0, 'taps': [-2, -1]},
{'initial': b0, 'taps': [-2, -1]}], {'initial': b0, 'taps': [-2, -1]}],
n_steps=5) n_steps=5)
final_result = a+b final_result = a + b
output_str = theano.printing.debugprint(final_result, file='str') output_str = theano.printing.debugprint(final_result, file='str')
lines = [] lines = []
for line in output_str.split('\n'): for line in output_str.split('\n'):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论