提交 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
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
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.
.. _macports:
......
......@@ -60,8 +60,8 @@ Environment Variables
.. envvar:: THEANORC
The location[s] of the .theanorc file[s] in ConfigParser format.
It defaults to ``$HOME/.theanorc``. On Windows, it defalt to
``$HOME/.theanorc:$HOME/.theanorc.txt`` to make Windows users life
It defaults to ``$HOME/.theanorc``. On Windows, it defaults to
``$HOME/.theanorc:$HOME/.theanorc.txt`` to make Windows users' life
easier.
Here is the .theanorc equivalent to the THEANO_FLAGS in the example above:
......
......@@ -2,14 +2,17 @@
"""
__docformat__ = "restructuredtext en"
import sys, traceback, logging
import logging
import sys
import traceback
_logger = logging.getLogger('theano.compile.function')
from io import In
from function_module import orig_function
from profiling import ProfileStats
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,
no_default_updates=False, accept_inplace=False, name=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
loop to avoid continuously changing between python and c.
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
have been compiled using the CLinker.
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,
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:
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_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_updates = (updates != [])
uses_givens = (givens != [])
# See if we have any mutable / borrow inputs
check_for_aliased_inputs = False
for i in inputs:
if (isinstance(i, In) and ( (hasattr(i,'borrow') and i.borrow) or
(hasattr(i,'mutable') and i.mutable)) ):
if (isinstance(i, In) and ((hasattr(i, 'borrow') and i.borrow) or
(hasattr(i, 'mutable') and i.mutable))):
check_for_aliased_inputs = True
if uses_In or uses_tuple:
......@@ -185,9 +188,9 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
raise NotImplementedError('profiling not supported in old-style function')
if uses_updates or uses_givens:
raise NotImplementedError("In() instances and tuple inputs triggers the old semantics, which disallow using updates and givens")
fn = orig_function(inputs, outputs,
mode=mode,
accept_inplace=accept_inplace, name=name)
fn = orig_function(inputs, outputs,
mode=mode,
accept_inplace=accept_inplace, name=name)
else:
fn = pfunc(params=inputs,
outputs=outputs,
......@@ -195,7 +198,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
updates=updates,
givens=givens,
no_default_updates=no_default_updates,
accept_inplace=accept_inplace,name=name,
accept_inplace=accept_inplace, name=name,
rebuild_strict=rebuild_strict,
allow_input_downcast=allow_input_downcast,
on_unused_input=on_unused_input,
......
......@@ -956,17 +956,17 @@ class FunctionMaker(object):
def env_getter(self):
warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'",
stacklevel = 2)
stacklevel=2)
return self.fgraph
def env_setter(self,value):
warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'",
stacklevel = 2)
stacklevel=2)
self.fgraph = value
def env_deleter(self):
warnings.warn("FunctionMaker.env is deprecated, it has been renamed 'fgraph'",
stacklevel = 2)
stacklevel=2)
del self.fgraph
env = property(env_getter, env_setter, env_deleter)
......@@ -1035,21 +1035,19 @@ class FunctionMaker(object):
if not isinstance(inputs, (list, tuple)):
inputs = [inputs]
# Wrap them in In or Out instances if needed.
#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
for i in inputs if getattr(i, 'update', False)])
# Check if some input variables are unused
self._check_unused_inputs(inputs, outputs, on_unused_input)
#TODO: REMOVE THIS CRUFT - it's complicated for SymbolicInputKits
indices = [[input] + self.expand_in(input, _inputs) for input in inputs]
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)
fgraph, additional_outputs = std_fgraph(expanded_inputs, outputs, accept_inplace)
......@@ -1079,7 +1077,7 @@ class FunctionMaker(object):
_logger.debug('Optimizing took %f seconds', opt_time)
#Add deep copy to respect the memory interface
insert_deepcopy(fgraph, inputs, outputs+additional_outputs)
insert_deepcopy(fgraph, inputs, outputs + additional_outputs)
finally:
theano.config.compute_test_value = compute_test_value_orig
gof.Op.add_stack_trace_on_call = add_stack_trace_on_call
......@@ -1090,10 +1088,10 @@ class FunctionMaker(object):
"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.
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]
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]
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:
self.linker = linker.accept(fgraph)
......@@ -1170,8 +1168,8 @@ class FunctionMaker(object):
"""
if input_storage is None:
input_storage = [None]*len(self.inputs)
input_storage_lists = [] # list of independent one-element lists, will be passed to the linker
input_storage = [None] * len(self.inputs)
input_storage_lists = [] # list of independent one-element lists, will be passed to the linker
defaults = []
# The following loop is to fill in the input_storage_lists and defaults lists.
......@@ -1224,11 +1222,9 @@ class FunctionMaker(object):
refeed,
storage))
# Get a function instance
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()
linker_time = end_linker - start_linker
......@@ -1238,30 +1234,30 @@ class FunctionMaker(object):
self.profile.linker_time += linker_time
_fn.time_thunks = self.profile.flag_time_thunks
fn = self.function_builder(_fn, _i, _o, self.indices, self.outputs,
defaults, self.unpack_single, self.return_none, self)
fn.profile = self.profile
return fn
def _pickle_FunctionMaker(self):
kwargs = dict(
inputs = self.inputs,
outputs = self.orig_outputs,
mode = self.mode,
accept_inplace = self.accept_inplace,
function_builder = self.function_builder,
profile = self.profile,
inputs=self.inputs,
outputs=self.orig_outputs,
mode=self.mode,
accept_inplace=self.accept_inplace,
function_builder=self.function_builder,
profile=self.profile,
)
return (_constructor_FunctionMaker, (kwargs,))
def _constructor_FunctionMaker(kwargs):
return FunctionMaker(**kwargs)
copy_reg.pickle(FunctionMaker, _pickle_FunctionMaker)
try:
# Pickle of slice is implemented on python 2.6. To enabled be
# compatible with python 2.4, we implement pickling of slice
......@@ -1276,6 +1272,7 @@ except TypeError:
__checkers = []
def check_equal(x, y):
for checker in __checkers:
try:
......@@ -1285,6 +1282,7 @@ def check_equal(x, y):
return x == y
#raise Exception('No checker for equality between %s and %s' % (x, y))
def register_checker(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
......@@ -49,8 +49,8 @@ else:
dummy_stdin = open(os.devnull)
if default_openmp and theano.configdefaults.gxx_avail:
#check if g++ support openmp. We need to compile a file as the EPD
#version have openmp enabled in the specs file but do not include
#check if g++ supports openmp. We need to compile a file as the EPD
#version has openmp enabled in the specs file but does not include
#the OpenMP files.
try:
code = """
......@@ -68,6 +68,7 @@ int main( int argc, const char* argv[] )
try:
os.write(fd, code)
os.close(fd)
fd = None
proc = subprocess.Popen(['g++', '-fopenmp', path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
......@@ -76,7 +77,12 @@ int main( int argc, const char* argv[] )
if proc.returncode != 0:
default_openmp = False
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:
default_openmp = False
......
......@@ -239,13 +239,13 @@ class Variable(utils.object2):
- `Constant` (a subclass) which adds a default and un-replaceable :literal:`value`, and
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
- `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`
......
......@@ -451,7 +451,7 @@ class Stack(VM):
if not hasattr(o[0], 'size'):
size.append(-1)
continue
s=o[0].size
s = o[0].size
dtype = str(o[0].dtype)
dtype2 = dtype[-2:]
# KeyError here: couldn't determine the
......@@ -493,10 +493,10 @@ try:
except ImportError:
pass
except OSError:
#OSError happen when g++ is not installed. In that case, we
#alread changed the default linker to something else then CVM.
#Currently this is the py linker.
#Here we assert that the default linker is not cvm.
# OSError happens when g++ is not installed. In that case, we
# already changed the default linker to something else then CVM.
# Currently this is the py linker.
# Here we assert that the default linker is not cvm.
assert not [x for x in theano.configparser._config_var_list
if x.fullname == 'linker'][0].default.startswith('cvm')
pass
......@@ -540,8 +540,8 @@ class VM_Linker(link.LocalLinker):
def accept(self, fgraph, no_recycling=None):
"""
:param fgraph: a PerformLinker can have accepted one FunctionGraph instance
at a time.
:param fgraph: a PerformLinker can have accepted one FunctionGraph
instance at a time.
:param no_recycling: WRITEME
......@@ -661,7 +661,7 @@ class VM_Linker(link.LocalLinker):
assert type(compute_map_list[0]) is list
if self.allow_gc:
dependency_map=self.compute_gc_dependencies(storage_map)
dependency_map = self.compute_gc_dependencies(storage_map)
dependency_map_list = [
[vars_idx[d] for d in dependency_map[vars_idx_inv[i]]]
for i in xrange(len(vars_idx_inv))]
......@@ -777,8 +777,8 @@ class VM_Linker(link.LocalLinker):
return vm
def make_all(self, profiler=None, input_storage=None,
output_storage = None,
):
output_storage=None,
):
fgraph = self.fgraph
order = list(fgraph.toposort())
no_recycling = self.no_recycling
......@@ -819,8 +819,8 @@ class VM_Linker(link.LocalLinker):
return (vm,
[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)
for output, storage in zip(fgraph.outputs, output_storage)],
for output, storage in zip(fgraph.outputs, output_storage)],
thunks,
order)
......@@ -2185,7 +2185,7 @@ class MaxAndArgmax(Op):
x = _as_tensor_variable(x)
if isinstance(axis, Variable):
if not isinstance(axis, Constant):
raise TypeError("MaxAndArgmax need a constant axis")
raise TypeError("MaxAndArgmax needs a constant axis")
axis = [axis.data]
if isinstance(axis, int):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论