提交 a8ce3207 authored 作者: Frederic Bastien's avatar Frederic Bastien

Catch only exception.

上级 d7515eaf
...@@ -158,7 +158,7 @@ def as_tensor_variable(x, name=None, ndim=None): ...@@ -158,7 +158,7 @@ def as_tensor_variable(x, name=None, ndim=None):
except TypeError: except TypeError:
try: try:
str_x = str(x) str_x = str(x)
except: except Exception, e:
str_x = repr(x) str_x = repr(x)
raise TypeError("Cannot convert %s to TensorType" % str_x, type(x)) raise TypeError("Cannot convert %s to TensorType" % str_x, type(x))
...@@ -340,7 +340,7 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None): ...@@ -340,7 +340,7 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
else: else:
# leave the shape out of the type # leave the shape out of the type
return rtype(TensorType(dtype = x_.dtype, broadcastable = bcastable), x_, name=name) return rtype(TensorType(dtype = x_.dtype, broadcastable = bcastable), x_, name=name)
except: except Exception:
raise TypeError("Could not convert %s to TensorType" % x, type(x)) raise TypeError("Could not convert %s to TensorType" % x, type(x))
def constant(x, name=None, ndim=None, dtype=None): def constant(x, name=None, ndim=None, dtype=None):
...@@ -425,7 +425,7 @@ def get_constant_value(v): ...@@ -425,7 +425,7 @@ def get_constant_value(v):
try: try:
numpy.complex(data) #works for all numeric scalars numpy.complex(data) #works for all numeric scalars
return data return data
except: except Exception:
raise TypeError('v.data is non-numeric, non-scalar, or has more than one unique value', v) raise TypeError('v.data is non-numeric, non-scalar, or has more than one unique value', v)
if v.owner: if v.owner:
if isinstance(v.owner.op, Alloc): if isinstance(v.owner.op, Alloc):
...@@ -1361,7 +1361,7 @@ class TensorConstantSignature(tuple): ...@@ -1361,7 +1361,7 @@ class TensorConstantSignature(tuple):
return False return False
try: try:
(t0, d0), (t1,d1) = self, other (t0, d0), (t1,d1) = self, other
except: except Exception, e:
return False return False
#N.B. compare shape to ensure no broadcasting in == #N.B. compare shape to ensure no broadcasting in ==
if t0 != t1 or d0.shape != d1.shape: if t0 != t1 or d0.shape != d1.shape:
...@@ -1994,7 +1994,7 @@ def max(x, axis='DEFAULT'): ...@@ -1994,7 +1994,7 @@ def max(x, axis='DEFAULT'):
try: try:
const = get_constant_value(axis) const = get_constant_value(axis)
return CAReduce(scal.maximum,list(const))(x) return CAReduce(scal.maximum,list(const))(x)
except: except Exception:
return max_and_argmax(x,axis)[0] return max_and_argmax(x,axis)[0]
@constructor @constructor
...@@ -2873,7 +2873,7 @@ def extract_constant(x): ...@@ -2873,7 +2873,7 @@ def extract_constant(x):
''' '''
try: try:
x = get_constant_value(x) x = get_constant_value(x)
except: except Exception:
pass pass
if isinstance(x, scal.ScalarVariable): if isinstance(x, scal.ScalarVariable):
if x.owner and isinstance(x.owner.op, ScalarFromTensor): if x.owner and isinstance(x.owner.op, ScalarFromTensor):
...@@ -4398,7 +4398,7 @@ class Reshape(Op): ...@@ -4398,7 +4398,7 @@ class Reshape(Op):
', should be %i' % (len(shp), self.ndim), shp) ', should be %i' % (len(shp), self.ndim), shp)
try: try:
out[0] = numpy.reshape(x, shp) out[0] = numpy.reshape(x, shp)
except: except Exception, e:
raise ValueError('Cannot reshape input of shape %s to shape %s' % (x.shape,shp)) raise ValueError('Cannot reshape input of shape %s to shape %s' % (x.shape,shp))
def grad(self, inp, grads): def grad(self, inp, grads):
x, shp = inp x, shp = inp
...@@ -4593,7 +4593,7 @@ class ARange(Op): ...@@ -4593,7 +4593,7 @@ class ARange(Op):
try: try:
v = get_constant_value(var) v = get_constant_value(var)
return numpy.all(v == value) return numpy.all(v == value)
except: except Exception:
pass pass
return False return False
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论