提交 767f8684 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix to Scalar.values_eq_approx so that 0.0 is considered close to 0.0

Ideally, we should replicate lots of things that are in TensorType.values_eq_approx. See #664.
上级 7f039667
...@@ -103,7 +103,7 @@ class Scalar(Type): ...@@ -103,7 +103,7 @@ class Scalar(Type):
raise TypeError("Could not convert %s (value=%s) to %s" % (type(data), data, self.dtype), e) raise TypeError("Could not convert %s (value=%s) to %s" % (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) / (a+b) < tolerance return abs(a - b) <= ((abs(a)+abs(b)) * tolerance)
def c_headers(self): def c_headers(self):
l=['<math.h>'] l=['<math.h>']
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论