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

Flake8 for compile/sharedvalue.py

上级 d5ff2b48
...@@ -49,7 +49,8 @@ class SharedVariable(Variable): ...@@ -49,7 +49,8 @@ class SharedVariable(Variable):
or copied, so they must have the correct type. or copied, so they must have the correct type.
:param allow_downcast: Only applies if `strict` is False. :param allow_downcast: Only applies if `strict` is False.
True -> allow assigned value to lose precision when cast during assignment. True -> allow assigned value to lose precision when cast
during assignment.
False -> never allow precision loss. False -> never allow precision loss.
None -> only allow downcasting of a Python float to a scalar floatX. None -> only allow downcasting of a Python float to a scalar floatX.
...@@ -65,17 +66,18 @@ class SharedVariable(Variable): ...@@ -65,17 +66,18 @@ class SharedVariable(Variable):
if container is not None: if container is not None:
self.container = container self.container = container
if (value is not None) or (strict is not None): if (value is not None) or (strict is not None):
raise TypeError( raise TypeError('value and strict are ignored if you pass '
'value and strict are ignored if you pass a container here') 'a container here')
else: else:
if container is not None: if container is not None:
raise TypeError('Error to specify both value and container') raise TypeError('Error to specify both value and container')
self.container = Container(self, self.container = Container(
storage=[type.filter(value, strict=strict, self,
allow_downcast=allow_downcast)], storage=[type.filter(value, strict=strict,
readonly=False, allow_downcast=allow_downcast)],
strict=strict, readonly=False,
allow_downcast=allow_downcast) strict=strict,
allow_downcast=allow_downcast)
def get_value(self, borrow=False, return_internal_type=False): def get_value(self, borrow=False, return_internal_type=False):
"""Get the non-symbolic value associated with this SharedVariable. """Get the non-symbolic value associated with this SharedVariable.
...@@ -114,11 +116,11 @@ class SharedVariable(Variable): ...@@ -114,11 +116,11 @@ class SharedVariable(Variable):
def clone(self): def clone(self):
cp = self.__class__( cp = self.__class__(
name=self.name, name=self.name,
type=self.type, type=self.type,
value=None, value=None,
strict=None, strict=None,
container=self.container) container=self.container)
cp.tag = copy.copy(self.tag) cp.tag = copy.copy(self.tag)
return cp return cp
...@@ -140,8 +142,8 @@ class SharedVariable(Variable): ...@@ -140,8 +142,8 @@ class SharedVariable(Variable):
type(value)) type(value))
raise TypeError( raise TypeError(
"The generic 'SharedVariable' object is not subscriptable. " "The generic 'SharedVariable' object is not subscriptable. "
"This shared variable contains %s" % msg) "This shared variable contains %s" % msg)
def _value_get(self): def _value_get(self):
raise Exception("sharedvar.value does not exist anymore. Use " raise Exception("sharedvar.value does not exist anymore. Use "
...@@ -183,7 +185,8 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -183,7 +185,8 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
potential constructors to those that can accept those kwargs. potential constructors to those that can accept those kwargs.
:note: Some shared variable have ``borrow`` as extra kwargs. :note: Some shared variable have ``borrow`` as extra kwargs.
`See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail. `See <http://deeplearning.net/software/theano/tutorial/aliasing.\
html#borrowing-when-creating-shared-variables>`_ for detail.
:note: Some shared variable have ``broadcastable`` as extra kwargs. :note: Some shared variable have ``broadcastable`` as extra kwargs.
As shared variable shapes can change, all dimensions default As shared variable shapes can change, all dimensions default
...@@ -200,7 +203,8 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -200,7 +203,8 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
try: try:
if isinstance(value, Variable): if isinstance(value, Variable):
raise TypeError(" Shared variable constructor needs numeric values and not symbolic variables.") raise TypeError("Shared variable constructor needs numeric "
"values and not symbolic variables.")
for ctor in reversed(shared.constructors): for ctor in reversed(shared.constructors):
try: try:
...@@ -234,4 +238,4 @@ shared.constructors = [] ...@@ -234,4 +238,4 @@ shared.constructors = []
def generic_constructor(value, name=None, strict=False, allow_downcast=None): def generic_constructor(value, name=None, strict=False, allow_downcast=None):
"""SharedVariable Constructor""" """SharedVariable Constructor"""
return SharedVariable(type=generic, value=value, name=name, strict=strict, return SharedVariable(type=generic, value=value, name=name, strict=strict,
allow_downcast=allow_downcast) allow_downcast=allow_downcast)
...@@ -41,7 +41,6 @@ whitelist_flake8 = [ ...@@ -41,7 +41,6 @@ whitelist_flake8 = [
"compile/__init__.py", "compile/__init__.py",
"compile/profiling.py", "compile/profiling.py",
"compile/function_module.py", "compile/function_module.py",
"compile/sharedvalue.py",
"compile/monitormode.py", "compile/monitormode.py",
"compile/io.py", "compile/io.py",
"compile/tests/test_builders.py", "compile/tests/test_builders.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论