提交 8317a572 authored 作者: nouiz's avatar nouiz

Merge pull request #815 from delallea/minor

Minor stuff
...@@ -536,7 +536,7 @@ Then you must install g++. You can do this by installing XCode. See the first bu ...@@ -536,7 +536,7 @@ Then you must install g++. You can do this by installing XCode. See the first bu
If you use the trunk or version 0.6 or later of Theano, we try to If you use the trunk or version 0.6 or later of Theano, we try to
automaticaly link with the EPD blas version. Due to Mac OS automaticaly link with the EPD blas version. Due to Mac OS
peculiarities, we need a user intervention to do it. We detect peculiarities, we need a user intervention to do it. We detect
if the user did the modification and if not, we tell him how todo if the user did the modification and if not, we tell him how to do
it. it.
.. _macports: .. _macports:
......
...@@ -60,8 +60,8 @@ Environment Variables ...@@ -60,8 +60,8 @@ Environment Variables
.. envvar:: THEANORC .. envvar:: THEANORC
The location[s] of the .theanorc file[s] in ConfigParser format. The location[s] of the .theanorc file[s] in ConfigParser format.
It defaults to ``$HOME/.theanorc``. On Windows, it defalt to It defaults to ``$HOME/.theanorc``. On Windows, it defaults to
``$HOME/.theanorc:$HOME/.theanorc.txt`` to make Windows users life ``$HOME/.theanorc:$HOME/.theanorc.txt`` to make Windows users' life
easier. easier.
Here is the .theanorc equivalent to the THEANO_FLAGS in the example above: Here is the .theanorc equivalent to the THEANO_FLAGS in the example above:
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
""" """
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import sys, traceback, logging import logging
import sys
import traceback
_logger = logging.getLogger('theano.compile.function') _logger = logging.getLogger('theano.compile.function')
from io import In from io import In
from function_module import orig_function from function_module import orig_function
from profiling import ProfileStats from profiling import ProfileStats
from pfunc import pfunc from pfunc import pfunc
from numpy import any #for to work in python 2.4 from numpy import any # to work in python 2.4
def function(inputs, outputs=None, mode=None, updates=None, givens=None, def function(inputs, outputs=None, mode=None, updates=None, givens=None,
no_default_updates=False, accept_inplace=False, name=None, no_default_updates=False, accept_inplace=False, name=None,
...@@ -145,7 +148,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None, ...@@ -145,7 +148,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
the cvm is a linker that replaces this python loop with a c the cvm is a linker that replaces this python loop with a c
loop to avoid continuously changing between python and c. loop to avoid continuously changing between python and c.
The CVM is faster for 2 reasons: The CVM is faster for 2 reasons:
1) It's internal logic in C, so no Python interpreter overhead. 1) Its internal logic in C, so no Python interpreter overhead.
2) It makes native calls from the VM logic into thunks that 2) It makes native calls from the VM logic into thunks that
have been compiled using the CLinker. have been compiled using the CLinker.
the vm is a linker that was developed to prototype the cvm. it the vm is a linker that was developed to prototype the cvm. it
...@@ -167,16 +170,16 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None, ...@@ -167,16 +170,16 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
raise Exception("Inputs variable of a Theano function should be contained in a list, even when there is a single input.") raise Exception("Inputs variable of a Theano function should be contained in a list, even when there is a single input.")
# compute some features of the arguments: # compute some features of the arguments:
uses_In = any([isinstance(i, In) for i in inputs]) #N.B. the square brackets are ncessary uses_In = any([isinstance(i, In) for i in inputs]) # N.B. the square brackets are ncessary
uses_tuple = any([isinstance(i, (list, tuple)) for i in inputs])#N.B. the square brackets are ncessary uses_tuple = any([isinstance(i, (list, tuple)) for i in inputs]) # N.B. the square brackets are ncessary
uses_updates = (updates != []) uses_updates = (updates != [])
uses_givens = (givens != []) uses_givens = (givens != [])
# See if we have any mutable / borrow inputs # See if we have any mutable / borrow inputs
check_for_aliased_inputs = False check_for_aliased_inputs = False
for i in inputs: for i in inputs:
if (isinstance(i, In) and ( (hasattr(i,'borrow') and i.borrow) or if (isinstance(i, In) and ((hasattr(i, 'borrow') and i.borrow) or
(hasattr(i,'mutable') and i.mutable)) ): (hasattr(i, 'mutable') and i.mutable))):
check_for_aliased_inputs = True check_for_aliased_inputs = True
if uses_In or uses_tuple: if uses_In or uses_tuple:
...@@ -185,9 +188,9 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None, ...@@ -185,9 +188,9 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
raise NotImplementedError('profiling not supported in old-style function') raise NotImplementedError('profiling not supported in old-style function')
if uses_updates or uses_givens: if uses_updates or uses_givens:
raise NotImplementedError("In() instances and tuple inputs triggers the old semantics, which disallow using updates and givens") raise NotImplementedError("In() instances and tuple inputs triggers the old semantics, which disallow using updates and givens")
fn = orig_function(inputs, outputs, fn = orig_function(inputs, outputs,
mode=mode, mode=mode,
accept_inplace=accept_inplace, name=name) accept_inplace=accept_inplace, name=name)
else: else:
fn = pfunc(params=inputs, fn = pfunc(params=inputs,
outputs=outputs, outputs=outputs,
...@@ -195,7 +198,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None, ...@@ -195,7 +198,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
updates=updates, updates=updates,
givens=givens, givens=givens,
no_default_updates=no_default_updates, no_default_updates=no_default_updates,
accept_inplace=accept_inplace,name=name, accept_inplace=accept_inplace, name=name,
rebuild_strict=rebuild_strict, rebuild_strict=rebuild_strict,
allow_input_downcast=allow_input_downcast, allow_input_downcast=allow_input_downcast,
on_unused_input=on_unused_input, on_unused_input=on_unused_input,
......
...@@ -956,17 +956,17 @@ class FunctionMaker(object): ...@@ -956,17 +956,17 @@ class FunctionMaker(object):
def env_getter(self): def env_getter(self):
warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'", warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'",
stacklevel = 2) stacklevel=2)
return self.fgraph return self.fgraph
def env_setter(self,value): def env_setter(self,value):
warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'", warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'",
stacklevel = 2) stacklevel=2)
self.fgraph = value self.fgraph = value
def env_deleter(self): def env_deleter(self):
warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'", warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'",
stacklevel = 2) stacklevel=2)
del self.fgraph del self.fgraph
env = property(env_getter, env_setter, env_deleter) env = property(env_getter, env_setter, env_deleter)
...@@ -1035,21 +1035,19 @@ class FunctionMaker(object): ...@@ -1035,21 +1035,19 @@ class FunctionMaker(object):
if not isinstance(inputs, (list, tuple)): if not isinstance(inputs, (list, tuple)):
inputs = [inputs] inputs = [inputs]
# Wrap them in In or Out instances if needed. # Wrap them in In or Out instances if needed.
#import pudb; pudb.set_trace() #import pudb; pudb.set_trace()
inputs, outputs = map(self.wrap_in, inputs), map(self.wrap_out, outputs) inputs, outputs = map(self.wrap_in, inputs), map(self.wrap_out, outputs)
_inputs = gof.graph.inputs([o.variable for o in outputs] + [i.update _inputs = gof.graph.inputs([o.variable for o in outputs] + [i.update
for i in inputs if getattr(i, 'update', False)]) for i in inputs if getattr(i, 'update', False)])
# Check if some input variables are unused # Check if some input variables are unused
self._check_unused_inputs(inputs, outputs, on_unused_input) self._check_unused_inputs(inputs, outputs, on_unused_input)
#TODO: REMOVE THIS CRUFT - it's complicated for SymbolicInputKits #TODO: REMOVE THIS CRUFT - it's complicated for SymbolicInputKits
indices = [[input] + self.expand_in(input, _inputs) for input in inputs] indices = [[input] + self.expand_in(input, _inputs) for input in inputs]
expanded_inputs = reduce(list.__add__, [list(z) for x, y, z in indices], []) expanded_inputs = reduce(list.__add__, [list(z) for x, y, z in indices], [])
assert expanded_inputs == inputs #JB - I added this to make sure we could delete above assert expanded_inputs == inputs # JB - I added this to make sure we could delete above
# make the fgraph (copies the graph, creates NEW INPUT AND OUTPUT VARIABLES) # make the fgraph (copies the graph, creates NEW INPUT AND OUTPUT VARIABLES)
fgraph, additional_outputs = std_fgraph(expanded_inputs, outputs, accept_inplace) fgraph, additional_outputs = std_fgraph(expanded_inputs, outputs, accept_inplace)
...@@ -1079,7 +1077,7 @@ class FunctionMaker(object): ...@@ -1079,7 +1077,7 @@ class FunctionMaker(object):
_logger.debug('Optimizing took %f seconds', opt_time) _logger.debug('Optimizing took %f seconds', opt_time)
#Add deep copy to respect the memory interface #Add deep copy to respect the memory interface
insert_deepcopy(fgraph, inputs, outputs+additional_outputs) insert_deepcopy(fgraph, inputs, outputs + additional_outputs)
finally: finally:
theano.config.compute_test_value = compute_test_value_orig theano.config.compute_test_value = compute_test_value_orig
gof.Op.add_stack_trace_on_call = add_stack_trace_on_call gof.Op.add_stack_trace_on_call = add_stack_trace_on_call
...@@ -1090,10 +1088,10 @@ class FunctionMaker(object): ...@@ -1090,10 +1088,10 @@ class FunctionMaker(object):
"or one of %s" % mode_module.predefined_linkers.keys()) "or one of %s" % mode_module.predefined_linkers.keys())
#the 'no_borrow' outputs are the ones for which that we can't return the internal storage pointer. #the 'no_borrow' outputs are the ones for which that we can't return the internal storage pointer.
assert len(fgraph.outputs) == len(outputs+additional_outputs) assert len(fgraph.outputs) == len(outputs + additional_outputs)
no_borrow = [output for output, spec in zip(fgraph.outputs, outputs+additional_outputs) if not spec.borrow] no_borrow = [output for output, spec in zip(fgraph.outputs, outputs + additional_outputs) if not spec.borrow]
if no_borrow: if no_borrow:
self.linker = linker.accept(fgraph, no_recycling = infer_reuse_pattern(fgraph, no_borrow)) self.linker = linker.accept(fgraph, no_recycling=infer_reuse_pattern(fgraph, no_borrow))
else: else:
self.linker = linker.accept(fgraph) self.linker = linker.accept(fgraph)
...@@ -1170,8 +1168,8 @@ class FunctionMaker(object): ...@@ -1170,8 +1168,8 @@ class FunctionMaker(object):
""" """
if input_storage is None: if input_storage is None:
input_storage = [None]*len(self.inputs) input_storage = [None] * len(self.inputs)
input_storage_lists = [] # list of independent one-element lists, will be passed to the linker input_storage_lists = [] # list of independent one-element lists, will be passed to the linker
defaults = [] defaults = []
# The following loop is to fill in the input_storage_lists and defaults lists. # The following loop is to fill in the input_storage_lists and defaults lists.
...@@ -1224,11 +1222,9 @@ class FunctionMaker(object): ...@@ -1224,11 +1222,9 @@ class FunctionMaker(object):
refeed, refeed,
storage)) storage))
# Get a function instance # Get a function instance
start_linker = time.time() start_linker = time.time()
_fn, _i, _o = self.linker.make_thunk(input_storage = input_storage_lists) _fn, _i, _o = self.linker.make_thunk(input_storage=input_storage_lists)
end_linker = time.time() end_linker = time.time()
linker_time = end_linker - start_linker linker_time = end_linker - start_linker
...@@ -1238,30 +1234,30 @@ class FunctionMaker(object): ...@@ -1238,30 +1234,30 @@ class FunctionMaker(object):
self.profile.linker_time += linker_time self.profile.linker_time += linker_time
_fn.time_thunks = self.profile.flag_time_thunks _fn.time_thunks = self.profile.flag_time_thunks
fn = self.function_builder(_fn, _i, _o, self.indices, self.outputs, fn = self.function_builder(_fn, _i, _o, self.indices, self.outputs,
defaults, self.unpack_single, self.return_none, self) defaults, self.unpack_single, self.return_none, self)
fn.profile = self.profile fn.profile = self.profile
return fn return fn
def _pickle_FunctionMaker(self): def _pickle_FunctionMaker(self):
kwargs = dict( kwargs = dict(
inputs = self.inputs, inputs=self.inputs,
outputs = self.orig_outputs, outputs=self.orig_outputs,
mode = self.mode, mode=self.mode,
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,
) )
return (_constructor_FunctionMaker, (kwargs,)) return (_constructor_FunctionMaker, (kwargs,))
def _constructor_FunctionMaker(kwargs): def _constructor_FunctionMaker(kwargs):
return FunctionMaker(**kwargs) return FunctionMaker(**kwargs)
copy_reg.pickle(FunctionMaker, _pickle_FunctionMaker) copy_reg.pickle(FunctionMaker, _pickle_FunctionMaker)
try: try:
# Pickle of slice is implemented on python 2.6. To enabled be # Pickle of slice is implemented on python 2.6. To enabled be
# compatible with python 2.4, we implement pickling of slice # compatible with python 2.4, we implement pickling of slice
...@@ -1276,6 +1272,7 @@ except TypeError: ...@@ -1276,6 +1272,7 @@ except TypeError:
__checkers = [] __checkers = []
def check_equal(x, y): def check_equal(x, y):
for checker in __checkers: for checker in __checkers:
try: try:
...@@ -1285,6 +1282,7 @@ def check_equal(x, y): ...@@ -1285,6 +1282,7 @@ def check_equal(x, y):
return x == y return x == y
#raise Exception('No checker for equality between %s and %s' % (x, y)) #raise Exception('No checker for equality between %s and %s' % (x, y))
def register_checker(checker): def register_checker(checker):
__checkers.insert(0, checker) __checkers.insert(0, checker)
......
""" """
This file define Theano flags, but we define them later in the import order. This file defines Theano flags which need to be defined late in import order.
This is needed as we need to have parsed the previous This is needed as they rely on the values of other previously-defined flags.
""" """
import os import os
...@@ -49,8 +49,8 @@ else: ...@@ -49,8 +49,8 @@ else:
dummy_stdin = open(os.devnull) dummy_stdin = open(os.devnull)
if default_openmp and theano.configdefaults.gxx_avail: if default_openmp and theano.configdefaults.gxx_avail:
#check if g++ support openmp. We need to compile a file as the EPD #check if g++ supports openmp. We need to compile a file as the EPD
#version have openmp enabled in the specs file but do not include #version has openmp enabled in the specs file but does not include
#the OpenMP files. #the OpenMP files.
try: try:
code = """ code = """
...@@ -68,6 +68,7 @@ int main( int argc, const char* argv[] ) ...@@ -68,6 +68,7 @@ int main( int argc, const char* argv[] )
try: try:
os.write(fd, code) os.write(fd, code)
os.close(fd) os.close(fd)
fd = None
proc = subprocess.Popen(['g++', '-fopenmp', path], proc = subprocess.Popen(['g++', '-fopenmp', path],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
...@@ -76,7 +77,12 @@ int main( int argc, const char* argv[] ) ...@@ -76,7 +77,12 @@ int main( int argc, const char* argv[] )
if proc.returncode != 0: if proc.returncode != 0:
default_openmp = False default_openmp = False
finally: finally:
os.remove(path) # Ensure `fd` is closed before we remove the temporary file.
try:
if fd is not None:
os.close(fd)
finally:
os.remove(path)
except OSError, e: except OSError, e:
default_openmp = False default_openmp = False
......
...@@ -239,13 +239,13 @@ class Variable(utils.object2): ...@@ -239,13 +239,13 @@ class Variable(utils.object2):
- `Constant` (a subclass) which adds a default and un-replaceable :literal:`value`, and - `Constant` (a subclass) which adds a default and un-replaceable :literal:`value`, and
requires that owner is None requires that owner is None
- `TensorVariable` subclass of Variable that represent numpy.ndarray object - `TensorVariable` subclass of Variable that represents a numpy.ndarray object
- `SharedTensorVariable` Shared version of TensorVariable - `SharedTensorVariable` Shared version of TensorVariable
- `SparseVariable` subclass of Variable that represent scipy.sparse.{csc,csr}_matrix object - `SparseVariable` subclass of Variable that represents a scipy.sparse.{csc,csr}_matrix object
- `CudaNdarrayVariable` subclass of Variable that represent our object on the GPU that is a subset of numpy.ndarray - `CudaNdarrayVariable` subclass of Variable that represents our object on the GPU that is a subset of numpy.ndarray
- `RandomVariable` - `RandomVariable`
......
...@@ -451,7 +451,7 @@ class Stack(VM): ...@@ -451,7 +451,7 @@ class Stack(VM):
if not hasattr(o[0], 'size'): if not hasattr(o[0], 'size'):
size.append(-1) size.append(-1)
continue continue
s=o[0].size s = o[0].size
dtype = str(o[0].dtype) dtype = str(o[0].dtype)
dtype2 = dtype[-2:] dtype2 = dtype[-2:]
# KeyError here: couldn't determine the # KeyError here: couldn't determine the
...@@ -493,10 +493,10 @@ try: ...@@ -493,10 +493,10 @@ try:
except ImportError: except ImportError:
pass pass
except OSError: except OSError:
#OSError happen when g++ is not installed. In that case, we # OSError happens when g++ is not installed. In that case, we
#alread changed the default linker to something else then CVM. # already changed the default linker to something else then CVM.
#Currently this is the py linker. # Currently this is the py linker.
#Here we assert that the default linker is not cvm. # Here we assert that the default linker is not cvm.
assert not [x for x in theano.configparser._config_var_list assert not [x for x in theano.configparser._config_var_list
if x.fullname == 'linker'][0].default.startswith('cvm') if x.fullname == 'linker'][0].default.startswith('cvm')
pass pass
...@@ -540,8 +540,8 @@ class VM_Linker(link.LocalLinker): ...@@ -540,8 +540,8 @@ class VM_Linker(link.LocalLinker):
def accept(self, fgraph, no_recycling=None): def accept(self, fgraph, no_recycling=None):
""" """
:param fgraph: a PerformLinker can have accepted one FunctionGraph instance :param fgraph: a PerformLinker can have accepted one FunctionGraph
at a time. instance at a time.
:param no_recycling: WRITEME :param no_recycling: WRITEME
...@@ -661,7 +661,7 @@ class VM_Linker(link.LocalLinker): ...@@ -661,7 +661,7 @@ class VM_Linker(link.LocalLinker):
assert type(compute_map_list[0]) is list assert type(compute_map_list[0]) is list
if self.allow_gc: if self.allow_gc:
dependency_map=self.compute_gc_dependencies(storage_map) dependency_map = self.compute_gc_dependencies(storage_map)
dependency_map_list = [ dependency_map_list = [
[vars_idx[d] for d in dependency_map[vars_idx_inv[i]]] [vars_idx[d] for d in dependency_map[vars_idx_inv[i]]]
for i in xrange(len(vars_idx_inv))] for i in xrange(len(vars_idx_inv))]
...@@ -777,8 +777,8 @@ class VM_Linker(link.LocalLinker): ...@@ -777,8 +777,8 @@ class VM_Linker(link.LocalLinker):
return vm return vm
def make_all(self, profiler=None, input_storage=None, def make_all(self, profiler=None, input_storage=None,
output_storage = None, output_storage=None,
): ):
fgraph = self.fgraph fgraph = self.fgraph
order = list(fgraph.toposort()) order = list(fgraph.toposort())
no_recycling = self.no_recycling no_recycling = self.no_recycling
...@@ -819,8 +819,8 @@ class VM_Linker(link.LocalLinker): ...@@ -819,8 +819,8 @@ class VM_Linker(link.LocalLinker):
return (vm, return (vm,
[link.Container(input, storage) [link.Container(input, storage)
for input, storage in zip(fgraph.inputs, input_storage)], for input, storage in zip(fgraph.inputs, input_storage)],
[link.Container(output, storage, True) [link.Container(output, storage, True)
for output, storage in zip(fgraph.outputs, output_storage)], for output, storage in zip(fgraph.outputs, output_storage)],
thunks, thunks,
order) order)
...@@ -2185,7 +2185,7 @@ class MaxAndArgmax(Op): ...@@ -2185,7 +2185,7 @@ class MaxAndArgmax(Op):
x = _as_tensor_variable(x) x = _as_tensor_variable(x)
if isinstance(axis, Variable): if isinstance(axis, Variable):
if not isinstance(axis, Constant): if not isinstance(axis, Constant):
raise TypeError("MaxAndArgmax need a constant axis") raise TypeError("MaxAndArgmax needs a constant axis")
axis = [axis.data] axis = [axis.data]
if isinstance(axis, int): if isinstance(axis, int):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论