提交 fc332ccd authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix a test in DebugMode by makeing _Maker reuse its parent class create method.…

Fix a test in DebugMode by makeing _Maker reuse its parent class create method. The sub-version don't seem to add anything useful.
上级 9ec11732
...@@ -2323,95 +2323,12 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions ...@@ -2323,95 +2323,12 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
self.output_keys = output_keys self.output_keys = output_keys
self.name = name self.name = name
def create(self, input_storage=None, trustme=False, storage_map=None): self.required = [(i.value is None) for i in self.inputs]
""" self.refeed = [
Create a function. (i.value is not None and
not isinstance(i.value, gof.Container) and
Parameters i.update is None)
---------- for i in self.inputs]
input_storage
A list matching the inputs list and providing default values if the
default for an input is None, then that input is a required input.
For an input with an update, the default acts as initialization.
trustme
Disables some exceptions, used internally.
"""
if input_storage is None:
input_storage = [None] * len(self.inputs)
# List of independent one-element lists, will be passed to the linker.
input_storage_list = []
_defaults = []
# The following loop is to fill in the input_storage_list and _defaults
# lists.
for (input, indices, subinputs), default in izip(self.indices,
input_storage):
__default = default
if isinstance(default, gof.Container):
# If the default is a gof.Container, this means we want to
# share the same storage. This is done by appending
# default.storage to input_storage_list.
if indices is not None:
raise TypeError("Cannot take a Container instance as "
"default for a SymbolicInput.")
input_storage_list.append(default.storage)
default = None
else:
# Normal case: one new, independent storage unit
input_storage_list.append([None])
# Filling _defaults. Each entry is a tuple of three elements:
# (required, refeed, value)
# - required means that the user must provide a value when calling
# the function
# - refeed means that we want to put the default back in the
# storage after each function call
# - value is the value that will be put in the storage initially
if input.update is not None:
# If the input has an update, then (logically) it is
# not required since it is just a parameter and of
# course we don't want to refeed the default back into
# the storage as it would defeat the point of updating
# it. We always do this policy.
if default is None:
if trustme or isinstance(__default, gof.Container):
_defaults.append((False, False, None))
else:
# This might catch some bugs early
raise ValueError(
"A default (initial) value is required for an "
"input which can update itself.", input)
else:
_defaults.append((False, False, default))
else:
if default is None:
if trustme or isinstance(__default, gof.Container):
_defaults.append((False, False, None))
else:
# No default, so this is a required
# input. Nothing to feed back, initial value
# is None.
_defaults.append((True, False, None))
else:
# Default value. It is not required, but we want
# to put it back into the storage everytime so it
# behaves like most programming languages' default
# values
_defaults.append((False, True, default))
defaults = _defaults
# Get a function instance
_fn, _i, _o = self.linker.make_thunk(input_storage=input_storage_list,
storage_map=storage_map)
fn = self.function_builder(_fn, _i, _o, self.indices,
self.outputs, defaults, self.unpack_single,
self.return_none, self.output_keys, self,
name=self.name)
fn.profile = self.profile
return fn
######################## ########################
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论