提交 5c3db8e4 authored 作者: Frederic Bastien's avatar Frederic Bastien

small fix. python don't seam to like that we put the default value of an…

small fix. python don't seam to like that we put the default value of an argument to be the result of a fct call to another module.
上级 f5dee2b2
...@@ -665,7 +665,7 @@ class FunctionMaker(object): ...@@ -665,7 +665,7 @@ class FunctionMaker(object):
raise TypeError("Unknown output type: %s (%s)", type(output), output) raise TypeError("Unknown output type: %s (%s)", type(output), output)
def __init__(self, inputs, outputs, def __init__(self, inputs, outputs,
mode = mode_module.get_default_mode(), accept_inplace = False, function_builder = Function): mode = None, accept_inplace = False, function_builder = Function):
""" """
:type inputs: a list of SymbolicInput instances :type inputs: a list of SymbolicInput instances
...@@ -681,6 +681,9 @@ class FunctionMaker(object): ...@@ -681,6 +681,9 @@ class FunctionMaker(object):
in the graph from the inputs to the outputs in the graph from the inputs to the outputs
""" """
if mode is None:
mode = mode_module.default_mode
# Handle the case where inputs and/or outputs is a single Variable (not in a list) # Handle the case where inputs and/or outputs is a single Variable (not in a list)
unpack_single = False unpack_single = False
return_none = False return_none = False
...@@ -704,6 +707,7 @@ class FunctionMaker(object): ...@@ -704,6 +707,7 @@ class FunctionMaker(object):
self.env = env self.env = env
# Fetch the mode and then the optimizer and linker # Fetch the mode and then the optimizer and linker
mode = mode_module.predefined_modes.get(mode, mode)
optimizer, linker = mode.optimizer, copy.copy(mode.linker) optimizer, linker = mode.optimizer, copy.copy(mode.linker)
# optimize the env # optimize the env
...@@ -831,7 +835,7 @@ def register_checker(checker): ...@@ -831,7 +835,7 @@ def register_checker(checker):
def function(inputs, outputs, mode=mode_module.get_default_mode(), accept_inplace = False): def function(inputs, outputs, mode=None, accept_inplace = False):
""" """
Return a Function that will calculate the outputs from the inputs. Return a Function that will calculate the outputs from the inputs.
...@@ -866,6 +870,8 @@ def function(inputs, outputs, mode=mode_module.get_default_mode(), accept_inplac ...@@ -866,6 +870,8 @@ def function(inputs, outputs, mode=mode_module.get_default_mode(), accept_inplac
#`Out` instance if necessary: #`Out` instance if necessary:
t1 = time.time() t1 = time.time()
if mode is None:
mode = mode_module.default_mode
inputs = map(convert_function_input, inputs) inputs = map(convert_function_input, inputs)
if outputs is not None: if outputs is not None:
...@@ -876,6 +882,7 @@ def function(inputs, outputs, mode=mode_module.get_default_mode(), accept_inplac ...@@ -876,6 +882,7 @@ def function(inputs, outputs, mode=mode_module.get_default_mode(), accept_inplac
defaults = [getattr(input, 'value', None) for input in inputs] defaults = [getattr(input, 'value', None) for input in inputs]
mode = mode_module.predefined_modes.get(mode, mode)
if isinstance(mode, (list, tuple)): # "mode comparison" semantics if isinstance(mode, (list, tuple)): # "mode comparison" semantics
_logger.warning('Passing multiple modes is deprecated (20091019)') _logger.warning('Passing multiple modes is deprecated (20091019)')
if not mode: if not mode:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论