提交 0761b0b8 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Make sure we are clean with the versions used on travis.

上级 65d88e32
......@@ -5,13 +5,12 @@
"""
from __future__ import print_function
__docformat__ = "restructuredtext en"
import copy
import sys
import copy_reg
import gc
from itertools import izip
import logging
import numpy
......@@ -31,6 +30,8 @@ from theano.compile.function_module import (
from theano.compile.mode import Mode, register_mode
from theano.compile.ops import OutputGuard
__docformat__ = "restructuredtext en"
AddConfigVar('DebugMode.patience',
"Optimize graph this many times to detect inconsistency",
IntParam(10, lambda i: i > 0),
......@@ -96,7 +97,6 @@ AddConfigVar('DebugMode.check_preallocated_output_ndim',
IntParam(4, lambda i: i > 0),
in_c_key=False)
import logging
_logger = logging.getLogger("theano.compile.debugmode")
......@@ -303,9 +303,9 @@ class BadOptimization(DebugModeError):
# N.B. the maximum(..., 1e-8) protects against div by 0 when
# nv == ov == 0
reldiff = (abs_diff
/ numpy.maximum(numpy.absolute(nv) + numpy.absolute(ov),
1e-8))
reldiff = (abs_diff /
numpy.maaximum(numpy.absolute(nv) + numpy.absolute(ov),
1e-8))
print(" Max Rel Diff: ", numpy.max(reldiff), file=ssio)
print(" Mean Rel Diff: ", numpy.mean(reldiff), file=ssio)
print(" Median Rel Diff: ", numpy.median(reldiff), file=ssio)
......@@ -730,8 +730,8 @@ def _optcheck_fgraph(input_specs, output_specs, accept_inplace=False):
# We need to protect all immutable inputs from inplace operations.
fgraph.attach_feature(Supervisor(
input for spec, input in zip(input_specs, fgraph.inputs)
if not (spec.mutable or (hasattr(fgraph, 'destroyers')
and fgraph.destroyers(input)))))
if not (spec.mutable or (hasattr(fgraph, 'destroyers') and
fgraph.destroyers(input)))))
for feature in std_fgraph.features:
fgraph.attach_feature(feature())
......@@ -1340,9 +1340,9 @@ def _check_preallocated_output(node, thunk, prealloc_modes, def_val,
if type(getattr(node, 'op', None)) in ops_with_inner_function:
fn_attr_name = ops_with_inner_function[type(node.op)]
fn = getattr(node.op, fn_attr_name, None)
if (not fn
or not hasattr(fn, 'maker')
or not hasattr(fn.maker, 'mode')):
if (not fn or
not hasattr(fn, 'maker') or
not hasattr(fn.maker, 'mode')):
_logger.warn('Expected theano function not found in %s.%s',
node.op, fn_attr_name)
else:
......@@ -2251,7 +2251,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
inputs = [inputs]
# Wrap them in In or Out instances if needed.
inputs = map(self.wrap_in, inputs),
inputs = map(self.wrap_in, inputs)
outputs = map(self.wrap_out, outputs)
_inputs = gof.graph.inputs([o.variable for o in outputs] +
[i.update for i in inputs
......
"""Define the `function` function
"""
__docformat__ = "restructuredtext en"
import cPickle
import logging
_logger = logging.getLogger('theano.compile.function')
import traceback as tb
import re
......@@ -16,6 +13,9 @@ from numpy import any
import warnings
from theano import compat
__docformat__ = "restructuredtext en"
_logger = logging.getLogger('theano.compile.function')
def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
givens=None,
......
......@@ -2,8 +2,6 @@
"""
from __future__ import print_function
__docformat__ = "restructuredtext en"
import copy
import copy_reg
import cPickle
......@@ -25,6 +23,8 @@ from theano.gof.op import ops_with_inner_function
import logging
_logger = logging.getLogger('theano.compile.function_module')
__docformat__ = "restructuredtext en"
class UnusedInputError(Exception):
"""
......@@ -1276,8 +1276,8 @@ class FunctionMaker(object):
# - variables that have to be provided (used_inputs)
# - shared variables that will be updated
used_inputs = gof.graph.ancestors(
([o.variable for o in outputs]
+ [i.update for i in inputs if getattr(i, 'update', False)]),
([o.variable for o in outputs] +
[i.update for i in inputs if getattr(i, 'update', False)]),
blockers=[i.variable for i in inputs])
msg = ("theano.function was asked to create a function computing "
......
"""Define `SymbolicInput`, `SymbolicOutput`, `In`, `Out` """
__docformat__ = 'restructuredtext en'
from theano import gof
from sharedvalue import SharedVariable
......@@ -7,6 +6,8 @@ from sharedvalue import SharedVariable
import logging
_logger = logging.getLogger("theano.compile.io")
__docformat__ = 'restructuredtext en'
class SymbolicInput(object):
"""
......
......@@ -48,9 +48,9 @@ def check_equal(x, y):
y = y.todense()
if isinstance(x, numpy.ndarray) and isinstance(y, numpy.ndarray):
if (x.dtype != y.dtype
or x.shape != y.shape
or numpy.any(abs(x - y) > 1e-10)):
if (x.dtype != y.dtype or
x.shape != y.shape or
numpy.any(abs(x - y) > 1e-10)):
raise Exception("Output mismatch.",
{'performlinker': x, 'clinker': y})
else:
......
"""Provide a simple user friendly API """
__docformat__ = 'restructuredtext en'
from theano import config
from theano.compile import orig_function, In, Out
from theano.compile import UnusedInputError
......@@ -13,6 +9,8 @@ from theano.gof import Variable, Constant
import logging
_logger = logging.getLogger("theano.compile.pfunc")
__docformat__ = 'restructuredtext en'
def rebuild_collect_shared(outputs,
inputs=None,
......@@ -232,8 +230,8 @@ def rebuild_collect_shared(outputs,
cloned_outputs.append(Out(cloned_v, borrow=v.borrow))
else:
raise TypeError('Outputs must be theano Variable or '
'Out instances. Received ' + str(v)
+ ' of type ' + str(type(v)))
'Out instances. Received ' + str(v) +
' of type ' + str(type(v)))
# computed_list.append(cloned_v)
else:
if isinstance(outputs, Variable):
......
......@@ -12,12 +12,13 @@ from theano.compile.mode import (Mode, register_mode,
predefined_optimizers)
from theano.configparser import config, AddConfigVar, IntParam, BoolParam
from theano.compile.function_module import FunctionMaker
run_cthunk = None # Will be imported only when needed.
from profiling import ProfileStats
run_cthunk = None # Will be imported only when needed.
import_time = time.time()
AddConfigVar('ProfileMode.n_apply_to_print',
"Number of apply instances to print by default",
IntParam(15, lambda i: i > 0),
......
"""Provide a simple user friendly API to Theano-managed memory"""
__docformat__ = 'restructuredtext en'
# Standard imports
import copy
import logging
......@@ -12,6 +10,7 @@ import numpy
from theano.gof import Container, Variable, generic, utils
_logger = logging.getLogger('theano.compile.sharedvalue')
__docformat__ = 'restructuredtext en'
class SharedVariable(Variable):
......
......@@ -39,9 +39,9 @@ def make_depends():
def depends(pair):
""" Returns True if a depends on b """
a, b = pair
return (any(bout in a.inputs for bout in b.outputs)
or any(depends((ainp.owner, b)) for ainp in a.inputs
if ainp.owner))
return (any(bout in a.inputs for bout in b.outputs) or
any(depends((ainp.owner, b)) for ainp in a.inputs
if ainp.owner))
return depends
......
......@@ -36,8 +36,11 @@ def test_give_variables_names_small():
def test_remove():
even = lambda x: x % 2 == 0
odd = lambda x: x % 2 == 1
# The list are neede as with python 3, remove and filter return generators
def even(x):
return x % 2 == 0
def odd(x):
return x % 2 == 1
# The list are needed as with python 3, remove and filter return generators
# and we can't compare generators.
assert list(remove(even, range(5))) == list(filter(odd, range(5)))
"""WRITEME Defines the `Type` class."""
__docformat__ = "restructuredtext en"
from theano.compat import PY3
from theano.gof import utils
......@@ -13,6 +10,8 @@ from theano.gof import graph
########
from theano.gof.op import CLinkerObject
__docformat__ = "restructuredtext en"
class CLinkerType(CLinkerObject):
"""Interface specification for Types that can be arguments to a `CLinkerOp`.
......
......@@ -405,7 +405,9 @@ def give_variables_names(variables):
This function is idempotent."""
names = map(lambda var: var.name, variables)
h = hist(names)
bad_var = lambda var: not var.name or h[var.name] > 1
def bad_var(var):
return not var.name or h[var.name] > 1
for i, var in enumerate(filter(bad_var, variables)):
var.name = (var.name or "") + "_%d" % i
......
......@@ -93,11 +93,11 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re,
for ins in node.inputs:
assert not (ins in view_of and viewed_by[ins])
if (getattr(ins, 'ndim', None) == 0 and not storage_map[ins][0]
and ins not in fgraph.outputs and ins.owner
and all([compute_map_re[v][0]
for v in dependencies.get(ins, [])])
and ins not in allocated):
if (getattr(ins, 'ndim', None) == 0 and not storage_map[ins][0] and
ins not in fgraph.outputs and ins.owner and
all([compute_map_re[v][0]
for v in dependencies.get(ins, [])]) and
ins not in allocated):
# Constant Memory cannot be changed
# Constant and shared variables' storage_map value is not empty
reuse_out = None
......@@ -526,9 +526,9 @@ class Stack(VM):
for i in current_apply.inputs:
# Garbage Collection -> check if anybody else uses
# this input
if (dependencies[i]
and i.owner
and i not in self.outputs):
if (dependencies[i] and
i.owner and
i not in self.outputs):
if all(compute_map[v][0]
for v in dependencies[i]):
storage_map[i][0] = None
......@@ -1034,10 +1034,10 @@ class VM_Linker(link.LocalLinker):
for node in order:
clear_after_this_thunk = []
for input in node.inputs:
if ((input in computed)
and (input not in fgraph.outputs)
and (node == last_user[input])
and input not in reallocated_info.keys()):
if (input in computed and
input not in fgraph.outputs and
node == last_user[input] and
input not in reallocated_info.keys()):
clear_after_this_thunk.append(storage_map[input])
post_thunk_clear.append(clear_after_this_thunk)
else:
......
......@@ -7,13 +7,13 @@ from theano.tests import unittest_tools as utt
# Skip tests if cuda_ndarray is not available.
from nose.plugins.skip import SkipTest
import theano.sandbox.cuda as cuda_ndarray
if not cuda_ndarray.cuda_available:
if not cuda_ndarray.cuda_available: # noqa
raise SkipTest('Optional package cuda not available')
from theano.misc.pycuda_init import pycuda_available
if not pycuda_available:
if not pycuda_available: # noqa
raise SkipTest('Optional package pycuda not available')
from theano.sandbox.cuda.fftconv import scikits_cuda_available
if not scikits_cuda_available:
if not scikits_cuda_available: # noqa
raise SkipTest('Optional package scikits.cuda not available')
from theano.sandbox.cuda import float32_shared_constructor as shared
......
......@@ -2,13 +2,14 @@
# mpiexec -np 2 python _test_mpi_roundtrip.py
from mpi4py import MPI
comm = MPI.COMM_WORLD
import theano
from theano.tensor.io import send, recv, mpi_cmps
from theano.gof.sched import sort_schedule_fn
import numpy as np
from sys import stdout, stderr, exit
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
......
from datetime import datetime
__authors__ = "Ian Goodfellow"
__credits__ = ["Ian Goodfellow"]
__license__ = "3-clause BSD"
__maintainer__ = "Ian Goodfellow"
__email__ = "goodfeli@iro"
from datetime import datetime
def disturb_mem():
# Allocate a time-dependent amount of objects to increase
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论