提交 e710ee08 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Flake8 for compile/io.py

上级 c7add2a3
...@@ -17,42 +17,55 @@ class SymbolicInput(object): ...@@ -17,42 +17,55 @@ class SymbolicInput(object):
not computed from its owner. not computed from its owner.
name: Any type. (If autoname=True, defaults to variable.name). name: Any type. (If autoname=True, defaults to variable.name).
If name is a valid Python identifier, this input can be set by kwarg, and its value If name is a valid Python identifier, this input can be set by
can be accessed by self.<name>. kwarg, and its value can be accessed by self.<name>.
update: Variable instance (default: None) update: Variable instance (default: None)
value (see previous) will be replaced with this expression variable after each function call. value (see previous) will be replaced with this expression
If update is None, the update will be the default value of the input. variable after each function call. If update is None, the
update will be the default value of the input.
mutable: Bool (default: False if update is None, True if update is not None) mutable: Bool (default: False if update is None, True if update is
True: permit the compiled function to modify the python object being passed as the input not None)
False: do not permit the compiled function to modify the python object being passed as the input.
True: permit the compiled function to modify the python object
being passed as the input
False: do not permit the compiled function to modify the
python object being passed as the input.
strict: Bool (default: False) strict: Bool (default: False)
True: means that the value you pass for this input must have exactly the right type
False: the value you pass for this input may be cast automatically to the proper type True: means that the value you pass for this input must have
exactly the right type
False: the value you pass for this input may be cast
automatically to the proper type
allow_downcast: Bool or None (default: None) allow_downcast: Bool or None (default: None)
Only applies when `strict` is False. Only applies when `strict` is False.
True: the value you pass for this input can be silently True: the value you pass for this input can be silently
downcasted to fit the right type, which may lose precision. downcasted to fit the right type, which may lose precision.
False: the value will only be cast to a more general, or precise, type.
None: Almost like False, but allows downcast of Python floats to floatX. False: the value will only be cast to a more general, or
precise, type. None: Almost like False, but allows downcast
of Python floats to floatX.
autoname: Bool (default: True) autoname: Bool (default: True)
See the name option. See the name option.
implicit: Bool (default: False) implicit: Bool (default: False)
See help(In). Note that 'None' is not allowed here, since we are in the See help(In). Note that 'None' is not allowed here, since we
symbolic case. are in the symbolic case.
""" """
def __init__(self, variable, name=None, update=None, mutable=None, def __init__(self, variable, name=None, update=None, mutable=None,
strict=False, allow_downcast=None, autoname=True, strict=False, allow_downcast=None, autoname=True,
implicit=False): implicit=False):
assert implicit is not None # Safety check. assert implicit is not None # Safety check.
self.variable = variable self.variable = variable
if (autoname and name is None): if (autoname and name is None):
self.name = variable.name self.name = variable.name
else: else:
self.name = name self.name = name
...@@ -146,36 +159,54 @@ class In(SymbolicInput): ...@@ -146,36 +159,54 @@ class In(SymbolicInput):
not computed from its owner. not computed from its owner.
name: Any type. (If autoname=True, defaults to variable.name). name: Any type. (If autoname=True, defaults to variable.name).
If name is a valid Python identifier, this input can be set by kwarg, and its value If name is a valid Python identifier, this input can be set by
can be accessed by self.<name>. kwarg, and its value can be accessed by self.<name>.
value: Any type. value: Any type.
The initial/default value for this input. If update is None, this input acts just like The initial/default value for this input. If update is None,
an argument with a default value in Python. If update is not None, changes to this this input acts just like an argument with a default value in
value will "stick around", whether due to an update or a user's explicit action. Python. If update is not None, changes to this value will
"stick around", whether due to an update or a user's explicit
action.
update: Variable instance (default: None) update: Variable instance (default: None)
value (see previous) will be replaced with this expression variable after each function call. value (see previous) will be replaced with this expression
If update is None, the update will be the default value of the input. variable after each function call. If update is None, the
update will be the default value of the input.
mutable: Bool (default: False if update is None, True if update is
not None)
True: permit the compiled function to modify the python object
being passed as the input
mutable: Bool (default: False if update is None, True if update is not None) False: do not permit the compiled function to modify the
True: permit the compiled function to modify the python object being passed as the input python object being passed as the input.
False: do not permit the compiled function to modify the python object being passed as the input.
borrow: Bool (default: take the same value as mutable) borrow: Bool (default: take the same value as mutable)
True: permit the output of the compiled function to be aliased to the input
True: permit the output of the compiled function to be aliased
to the input
False: do not permit any output to be aliased to the input False: do not permit any output to be aliased to the input
strict: Bool (default: False) strict: Bool (default: False)
True: means that the value you pass for this input must have exactly the right type
False: the value you pass for this input may be cast automatically to the proper type True: means that the value you pass for this input must have
exactly the right type
False: the value you pass for this input may be cast
automatically to the proper type
allow_downcast: Bool or None (default: None) allow_downcast: Bool or None (default: None)
Only applies when `strict` is False. Only applies when `strict` is False.
True: the value you pass for this input can be silently True: the value you pass for this input can be silently
downcasted to fit the right type, which may lose precision. downcasted to fit the right type, which may lose precision.
False: the value will only be cast to a more general, or precise, type.
None: Almost like False, but allows downcast of Python floats to floatX. False: the value will only be cast to a more general, or
precise, type. None: Almost like False, but allows downcast
of Python floats to floatX.
autoname: Bool (default: True) autoname: Bool (default: True)
See the name option. See the name option.
...@@ -194,11 +225,11 @@ class In(SymbolicInput): ...@@ -194,11 +225,11 @@ class In(SymbolicInput):
# Note: the documentation above is duplicated in doc/topics/function.txt, # Note: the documentation above is duplicated in doc/topics/function.txt,
# try to keep it synchronized. # try to keep it synchronized.
def __init__(self, variable, name=None, value=None, update=None, def __init__(self, variable, name=None, value=None, update=None,
mutable=None, strict=False, allow_downcast=None, autoname=True, mutable=None, strict=False, allow_downcast=None,
implicit=None, borrow=None, shared=False): autoname=True, implicit=None, borrow=None, shared=False):
# if shared, an input's value comes from its persistent
# if shared, an input's value comes from its persistent storage, not from a default stored # storage, not from a default stored in the function or from
# in the function or from the caller # the caller
self.shared = shared self.shared = shared
if borrow is None: if borrow is None:
...@@ -211,25 +242,25 @@ class In(SymbolicInput): ...@@ -211,25 +242,25 @@ class In(SymbolicInput):
# aliased to the input. Thus mutable=True should require borrow=True. # aliased to the input. Thus mutable=True should require borrow=True.
if mutable and not self.borrow: if mutable and not self.borrow:
raise AssertionError( raise AssertionError(
"Symbolic input for variable %s (name=%s) has " "Symbolic input for variable %s (name=%s) has "
"flags mutable=True, borrow=False. This combination is " "flags mutable=True, borrow=False. This combination is "
"incompatible since mutable=True implies that the " "incompatible since mutable=True implies that the "
"input variable may be both aliased (borrow=True) and " "input variable may be both aliased (borrow=True) and "
"overwritten.", "overwritten.",
variable, name) variable, name)
if implicit is None: if implicit is None:
implicit = (isinstance(value, gof.Container) or implicit = (isinstance(value, gof.Container) or
isinstance(value, SharedVariable)) isinstance(value, SharedVariable))
super(In, self).__init__( super(In, self).__init__(
variable=variable, variable=variable,
name=name, name=name,
update=update, update=update,
mutable=mutable, mutable=mutable,
strict=strict, strict=strict,
allow_downcast=allow_downcast, allow_downcast=allow_downcast,
autoname=autoname, autoname=autoname,
implicit=implicit) implicit=implicit)
self.value = value self.value = value
if self.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')
......
...@@ -42,7 +42,6 @@ whitelist_flake8 = [ ...@@ -42,7 +42,6 @@ whitelist_flake8 = [
"compile/profiling.py", "compile/profiling.py",
"compile/function_module.py", "compile/function_module.py",
"compile/monitormode.py", "compile/monitormode.py",
"compile/io.py",
"compile/tests/test_builders.py", "compile/tests/test_builders.py",
"compile/tests/test_misc.py", "compile/tests/test_misc.py",
"compile/tests/test_monitormode.py", "compile/tests/test_monitormode.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论