提交 91547f2a authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix DebugMode error due to overflow in comparison

上级 9fad11da
...@@ -199,7 +199,11 @@ class Scalar(Type): ...@@ -199,7 +199,11 @@ class Scalar(Type):
type(data), data, self.dtype), e) type(data), data, self.dtype), e)
def values_eq_approx(self, a, b, tolerance=1e-4): def values_eq_approx(self, a, b, tolerance=1e-4):
return abs(a - b) <= ((abs(a) + abs(b)) * tolerance) # The addition have risk of overflow especially with [u]int8
diff = a - b
if diff == 0:
return True
return abs(diff) <= ((abs(a) + abs(b)) * tolerance)
def c_headers(self, c_compiler): def c_headers(self, c_compiler):
l = ['<math.h>'] l = ['<math.h>']
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论