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

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

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