提交 41f43f0d authored 作者: Olivier Delalleau's avatar Olivier Delalleau

The 'implicit' parameter of In can now be None to automatically find its appropriate value

上级 f00d40b0
"""Define `SymbolicInput`, `SymbolicOutput`, `In`, `Out` """ """Define `SymbolicInput`, `SymbolicOutput`, `In`, `Out` """
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from theano import gof
class SymbolicInput(object): class SymbolicInput(object):
""" """
Represents a symbolic input for use with function or FunctionMaker. Represents a symbolic input for use with function or FunctionMaker.
...@@ -29,11 +31,13 @@ class SymbolicInput(object): ...@@ -29,11 +31,13 @@ class SymbolicInput(object):
See the name option. See the name option.
implicit: Bool (default: False) implicit: Bool (default: False)
See help(In). See help(In). Note that 'None' is not allowed here, since we are in the
symbolic case.
""" """
def __init__(self, variable, name=None, update=None, mutable=None, strict=False, autoname=True, def __init__(self, variable, name=None, update=None, mutable=None, strict=False, autoname=True,
implicit=False): implicit=False):
assert implicit is not None # Safety check.
self.variable = variable self.variable = variable
self.name = variable.name if (autoname and name is None) else name self.name = variable.name if (autoname and name is None) else name
if self.name is not None and not isinstance(self.name, str): if self.name is not None and not isinstance(self.name, str):
...@@ -142,19 +146,27 @@ class In(SymbolicInput): ...@@ -142,19 +146,27 @@ class In(SymbolicInput):
autoname: Bool (default: True) autoname: Bool (default: True)
See the name option. See the name option.
implicit: Bool (default: False) implicit: Bool or None (default: None)
True: This input is implicit in the sense that the user is not allowed True: This input is implicit in the sense that the user is not allowed
to provide a value for it. Requires 'value' to be set. to provide a value for it. Requires 'value' to be set. Setting an
False: The user can provide a value for this input. input as implicit allows Theano to directly share containers when
'value' is an existing container.
False: The user can provide a value for this input. In this case,
containers will not be shared (to avoid accidentally overwriting a
container's content with an input value provided by the user).
None: Automatically choose between True or False depending on the
situation. It will be set to False in all cases except if 'value'
is a container (so that it can be shared by default).
""" """
def __init__(self, variable, name=None, value=None, update=None, def __init__(self, variable, name=None, value=None, update=None,
mutable=None, strict=False, autoname=True, mutable=None, strict=False, autoname=True,
implicit=False): implicit=None):
if implicit is None:
implicit = isinstance(value, gof.Container)
super(In, self).__init__(variable, name, update, mutable, strict, super(In, self).__init__(variable, name, update, mutable, strict,
autoname, implicit = implicit) autoname, implicit = implicit)
self.value = value self.value = value
if implicit and value is None: if self.implicit and value is None:
raise TypeError('An implicit input must be given a default value') raise TypeError('An implicit input must be given a default value')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论