提交 7ed9fb90 authored 作者: Pascal Lamblin's avatar Pascal Lamblin 提交者: GitHub

Merge pull request #6111 from jhelie/fix-alerts-found-with-lgtm

Fix alerts found with lgtm
...@@ -56,8 +56,8 @@ class Optimizer(object): ...@@ -56,8 +56,8 @@ class Optimizer(object):
# in subclasses from other bases. # in subclasses from other bases.
return id(self) == id(other) return id(self) == id(other)
def __neq__(self, other): def __ne__(self, other):
# added to override the __neq__ implementation that may be inherited # added to override the __ne__ implementation that may be inherited
# in subclasses from other bases. # in subclasses from other bases.
return id(self) != id(other) return id(self) != id(other)
...@@ -492,8 +492,7 @@ class _metadict: ...@@ -492,8 +492,7 @@ class _metadict:
except Exception: except Exception:
if item is item2: if item is item2:
return value return value
else: return default
return default
def clear(self): def clear(self):
self.d = {} self.d = {}
......
...@@ -65,7 +65,7 @@ class BoundVariable(Variable): ...@@ -65,7 +65,7 @@ class BoundVariable(Variable):
""" """
def __init__(self, name, value): def __init__(self, name, value):
self.name = name super(BoundVariable, self).__init__(name=name)
self.value = value self.value = value
...@@ -77,7 +77,7 @@ class OrVariable(Variable): ...@@ -77,7 +77,7 @@ class OrVariable(Variable):
""" """
def __init__(self, name, options): def __init__(self, name, options):
self.name = name super(OrVariable, self).__init__(name=name)
self.options = options self.options = options
...@@ -89,7 +89,7 @@ class NotVariable(Variable): ...@@ -89,7 +89,7 @@ class NotVariable(Variable):
""" """
def __init__(self, name, not_options): def __init__(self, name, not_options):
self.name = name super(NotVariable, self).__init__(name=name)
self.not_options = not_options self.not_options = not_options
......
...@@ -1315,7 +1315,6 @@ class GpuJoin(HideC, Join): ...@@ -1315,7 +1315,6 @@ class GpuJoin(HideC, Join):
fail = sub['fail'] fail = sub['fail']
out = out_[0] out = out_[0]
copy_inputs_to_list = '\n'.join(copy_to_list) copy_inputs_to_list = '\n'.join(copy_to_list)
restype = restype
ctx = sub['params'] ctx = sub['params']
code = """ code = """
......
...@@ -771,8 +771,7 @@ class GpuAdvancedIncSubtensor1(Op): ...@@ -771,8 +771,7 @@ class GpuAdvancedIncSubtensor1(Op):
else: else:
opname = 'increment' opname = 'increment'
raise TypeError( raise TypeError(
'cannot %s x subtensor with ndim=%s' 'cannot %s x subtensor with ndim=%s by y with ndim=%s ' % (
' by y with ndim=%s to x subtensor with ndim=%s ' % (
opname, x_.type.ndim, y_.type.ndim)) opname, x_.type.ndim, y_.type.ndim))
return gof.Apply(self, [x_, y_, ilist_], [x_.type()]) return gof.Apply(self, [x_, y_, ilist_], [x_.type()])
...@@ -995,8 +994,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuKernelBase, HideC, ...@@ -995,8 +994,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuKernelBase, HideC,
else: else:
opname = 'increment' opname = 'increment'
raise TypeError( raise TypeError(
'cannot %s x subtensor with ndim=%s' 'cannot %s x subtensor with ndim=%s by y with ndim=%s ' % (
' by y with ndim=%s to x subtensor with ndim=%s ' % (
opname, x_.type.ndim, y_.type.ndim)) opname, x_.type.ndim, y_.type.ndim))
return gof.Apply(self, [x_, y_, ilist_], [x_.type()]) return gof.Apply(self, [x_, y_, ilist_], [x_.type()])
......
...@@ -56,7 +56,7 @@ def safe_new(x, tag='', dtype=None): ...@@ -56,7 +56,7 @@ def safe_new(x, tag='', dtype=None):
if dtype and x.dtype != dtype: if dtype and x.dtype != dtype:
casted_x = x.astype(dtype) casted_x = x.astype(dtype)
nwx = x.__class__(casted_x.type, x.data, x.name) nwx = x.__class__(casted_x.type, x.data, x.name)
nwx.tag = copy(x.tag) nwx.tag = copy.copy(x.tag)
return nwx return nwx
else: else:
return x.clone() return x.clone()
......
...@@ -333,6 +333,9 @@ class SparseConstantSignature(tuple): ...@@ -333,6 +333,9 @@ class SparseConstantSignature(tuple):
(b.shape == y.shape) and (b.shape == y.shape) and
(abs(b - y).sum() < 1e-6 * b.nnz)) (abs(b - y).sum() < 1e-6 * b.nnz))
def __ne__(self, other):
return not self == other
def __hash__(self): def __hash__(self):
(a, b) = self (a, b) = self
return hash(type(self)) ^ hash(a) ^ hash(type(b)) return hash(type(self)) ^ hash(a) ^ hash(type(b))
...@@ -1330,7 +1333,7 @@ class GetItemScalar(gof.op.Op): ...@@ -1330,7 +1333,7 @@ class GetItemScalar(gof.op.Op):
elif ind.ndim == 0: elif ind.ndim == 0:
input_op += [ind] input_op += [ind]
else: else:
raise NotImplemented() raise NotImplementedError
return gof.Apply(self, input_op, [tensor.scalar(dtype=x.dtype)]) return gof.Apply(self, input_op, [tensor.scalar(dtype=x.dtype)])
......
...@@ -1350,7 +1350,7 @@ def local_mul_s_d(node): ...@@ -1350,7 +1350,7 @@ def local_mul_s_d(node):
CSx = sparse.CSR CSx = sparse.CSR
mul_s_d_csx = mul_s_d_csr mul_s_d_csx = mul_s_d_csr
else: else:
raise NotImplemented() raise NotImplementedError
if x.dtype != y.dtype: if x.dtype != y.dtype:
# mul_s_d_csx don't support that case # mul_s_d_csx don't support that case
return return
......
...@@ -194,7 +194,7 @@ class Multinomial(gof.op.Op): ...@@ -194,7 +194,7 @@ class Multinomial(gof.op.Op):
assert _is_sparse(p) assert _is_sparse(p)
if p.format != 'csr': if p.format != 'csr':
raise NotImplemented() raise NotImplementedError
out[0] = p.copy() out[0] = p.copy()
......
...@@ -8386,6 +8386,19 @@ class T_Choose(utt.InferShapeTester): ...@@ -8386,6 +8386,19 @@ class T_Choose(utt.InferShapeTester):
n_c = np.choose(A, B, mode=m) n_c = np.choose(A, B, mode=m)
assert np.allclose(t_c, n_c) assert np.allclose(t_c, n_c)
def test_method(self):
a = tensor.vector(dtype='int32')
b = tensor.matrix(dtype='float32')
A = np.random.randint(0, 4, 4).astype('int32')
B = np.asarray(np.random.rand(4, 4), dtype='float32')
for m in self.modes:
f = function([a, b], a.choose(b, mode=m))
t_c = f(A, B)
n_c = A.choose(B, mode=m)
assert np.allclose(t_c, n_c)
def test_broadcasted(self): def test_broadcasted(self):
a = tensor.scalar(dtype='int32') a = tensor.scalar(dtype='int32')
b = tensor.matrix(dtype='float32') b = tensor.matrix(dtype='float32')
......
...@@ -762,14 +762,13 @@ class _tensor_py_operators(object): ...@@ -762,14 +762,13 @@ class _tensor_py_operators(object):
"""Fill inputted tensor with the assigned value.""" """Fill inputted tensor with the assigned value."""
return theano.tensor.basic.fill(self, value) return theano.tensor.basic.fill(self, value)
def choose(self, a, choices, out=None, mode='raise'): def choose(self, choices, out=None, mode='raise'):
""" """
Construct an array from an index array and a set of arrays to choose Construct an array from an index array and a set of arrays to choose
from. from.
""" """
return theano.tensor.basic.choose(self, a, choices, out=None, return theano.tensor.basic.choose(self, choices, out=None, mode='raise')
mode='raise')
def squeeze(self): def squeeze(self):
""" """
...@@ -864,6 +863,9 @@ class TensorConstantSignature(tuple): ...@@ -864,6 +863,9 @@ class TensorConstantSignature(tuple):
# here). # here).
return (self.sum == other.sum) and np.all(d0 == d1) return (self.sum == other.sum) and np.all(d0 == d1)
def __ne__(self, other):
return not self == other
def __hash__(self): def __hash__(self):
t, d = self t, d = self
return hashtype(self) ^ hash(t) ^ hash(d.shape) ^ hash(self.sum) return hashtype(self) ^ hash(t) ^ hash(d.shape) ^ hash(self.sum)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论