提交 57709e8b authored 作者: Frederic Bastien's avatar Frederic Bastien

Don't subtitute compute_test_value error with not implemented!

上级 da2298c2
...@@ -1132,40 +1132,59 @@ class _tensor_py_operators: ...@@ -1132,40 +1132,59 @@ class _tensor_py_operators:
def __add__(self,other): def __add__(self,other):
try: try:
return add(self,other) return add(self,other)
except Exception, e: # We should catch only NotImplementedError.
# As otherwise this will transfer error to the wrong error
# Theano flags compute_test_value need to be able to raise
# other type of error.
except NotImplementedError, e:
# We must return NotImplemented and not an
# NotImplementedError or raise an NotImplementedError.
# That way python will give a good error message like this
# `TypeError: unsupported operand type(s) for +:
# 'TensorVariable' and 'TensorVariable'`
return NotImplemented return NotImplemented
def __sub__(self,other): def __sub__(self,other):
# See explanation in __add__ for the error catched
# adn the return value in that case
try: try:
return sub(self,other) return sub(self,other)
except Exception, e: except NotImplementedError, e:
return NotImplemented return NotImplemented
def __mul__(self,other): def __mul__(self,other):
# See explanation in __add__ for the error catched
# adn the return value in that case
try: try:
return mul(self,other) return mul(self,other)
except Exception, e: except NotImplementedError, e:
return NotImplemented return NotImplemented
def __div__(self,other): def __div__(self,other):
# See explanation in __add__ for the error catched
# adn the return value in that case
try: try:
return div_proxy(self,other) return div_proxy(self,other)
except IntegerDivisionError: except IntegerDivisionError:
# This is to raise the exception that occurs when trying to divide # This is to raise the exception that occurs when trying to divide
# two integer arrays (currently forbidden). # two integer arrays (currently forbidden).
raise raise
except Exception, e: except NotImplementedError, e:
return NotImplemented return NotImplemented
def __pow__(self,other): def __pow__(self,other):
# See explanation in __add__ for the error catched
# adn the return value in that case
try: try:
return pow(self,other) return pow(self,other)
except Exception, e: except NotImplementedError, e:
return NotImplemented return NotImplemented
def __mod__(self,other): def __mod__(self,other):
# See explanation in __add__ for the error catched
# adn the return value in that case
try: try:
return mod_check(self, other) return mod_check(self, other)
except ComplexError: except ComplexError:
# This is to raise the exception that occurs when trying to compute # This is to raise the exception that occurs when trying to compute
# x % y with either x or y a complex number. # x % y with either x or y a complex number.
raise raise
except Exception, e: except NotImplementedError, e:
return NotImplemented return NotImplemented
def __truediv__(self,other): return true_div(self, other) def __truediv__(self,other): return true_div(self, other)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论