提交 47853608 authored 作者: Iban Harlouchet's avatar Iban Harlouchet

flake8 for tensor/type.py ; one E left

上级 acd37bd7
import logging import logging
_logger = logging.getLogger("theano.tensor.type") import warnings
import numpy import numpy
import theano import theano
from theano import config from theano import config
from theano.gof import Constant, hashtype, Type, Variable from theano.gof import hashtype, Type, Variable
from theano.gof.utils import MethodNotDefined
from theano import scalar as scal from theano import scalar as scal
_logger = logging.getLogger("theano.tensor.type")
class TensorType(Type): class TensorType(Type):
"""Symbolic `Type` representing a numpy.ndarray value.""" """Symbolic `Type` representing a numpy.ndarray value."""
...@@ -39,7 +40,7 @@ class TensorType(Type): ...@@ -39,7 +40,7 @@ class TensorType(Type):
if self.dtype == 'floatX': if self.dtype == 'floatX':
self.dtype = config.floatX self.dtype = config.floatX
# broadcastable is immutable, and all elements are either # broadcastable is immutable, and all elements are either
### True or False # True or False
self.broadcastable = tuple(bool(b) for b in broadcastable) self.broadcastable = tuple(bool(b) for b in broadcastable)
self.dtype_specs() # error checking is done there self.dtype_specs() # error checking is done there
self.name = name self.name = name
...@@ -78,13 +79,13 @@ class TensorType(Type): ...@@ -78,13 +79,13 @@ class TensorType(Type):
'maybe you are trying to call a function on a (possibly ' 'maybe you are trying to call a function on a (possibly '
'shared) variable instead of a numeric array?') 'shared) variable instead of a numeric array?')
if ((type(data) is numpy.ndarray) if ((type(data) is numpy.ndarray) and
and (data.dtype == self.numpy_dtype)): (data.dtype == self.numpy_dtype)):
if data.dtype.num != self.numpy_dtype.num: if data.dtype.num != self.numpy_dtype.num:
data = theano._asarray(data, dtype=self.dtype) data = theano._asarray(data, dtype=self.dtype)
# -- now fall through to ndim check # -- now fall through to ndim check
elif((type(data) is numpy.memmap) elif ((type(data) is numpy.memmap) and
and (data.dtype == self.numpy_dtype)): (data.dtype == self.numpy_dtype)):
# numpy.memmap is a "safe" subclass of ndarray, # numpy.memmap is a "safe" subclass of ndarray,
# so we can use it whereever we expect a base ndarray. # so we can use it whereever we expect a base ndarray.
# however, casting it would defeat the purpose of not # however, casting it would defeat the purpose of not
...@@ -98,8 +99,8 @@ class TensorType(Type): ...@@ -98,8 +99,8 @@ class TensorType(Type):
data, type(data)) data, type(data))
if data.dtype != self.numpy_dtype: if data.dtype != self.numpy_dtype:
raise TypeError(("%s expected a ndarray object with " raise TypeError(("%s expected a ndarray object with "
"dtype = %s (got %s).") % ( "dtype = %s (got %s).") %
self, self.numpy_dtype, data.dtype)) (self, self.numpy_dtype, data.dtype))
assert False, "This point should never be reached." assert False, "This point should never be reached."
else: else:
if allow_downcast: if allow_downcast:
...@@ -210,12 +211,10 @@ class TensorType(Type): ...@@ -210,12 +211,10 @@ class TensorType(Type):
raise TypeError( raise TypeError(
'Cannot convert Type %(othertype)s ' 'Cannot convert Type %(othertype)s '
'(of Variable %(other)s) into Type %(self)s. ' '(of Variable %(other)s) into Type %(self)s. '
'You can try to manually convert %(other)s into a %(self)s.' 'You can try to manually convert %(other)s into a %(self)s.' %
% dict( dict(othertype=other.type,
othertype=other.type,
other=other, other=other,
self=self) self=self))
)
def value_validity_msg(self, a): def value_validity_msg(self, a):
try: try:
...@@ -422,7 +421,7 @@ class TensorType(Type): ...@@ -422,7 +421,7 @@ class TensorType(Type):
def __repr__(self): def __repr__(self):
return str(self) return str(self)
#"TensorType{%s, %s}" % (str(self.dtype), str(self.broadcastable)) # "TensorType{%s, %s}" % (str(self.dtype), str(self.broadcastable))
def c_declare(self, name, sub, check_input=True): def c_declare(self, name, sub, check_input=True):
"""Override `CLinkerType.c_declare` """ """Override `CLinkerType.c_declare` """
......
...@@ -57,7 +57,6 @@ whitelist_flake8 = [ ...@@ -57,7 +57,6 @@ whitelist_flake8 = [
"typed_list/tests/test_type.py", "typed_list/tests/test_type.py",
"typed_list/tests/test_opt.py", "typed_list/tests/test_opt.py",
"typed_list/tests/test_basic.py", "typed_list/tests/test_basic.py",
"tensor/type.py",
"tensor/fourier.py", "tensor/fourier.py",
"tensor/__init__.py", "tensor/__init__.py",
"tensor/opt_uncanonicalize.py", "tensor/opt_uncanonicalize.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论