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

fix TensorType.values_eq_approx. Returned False when they where equal. That fix…

fix TensorType.values_eq_approx. Returned False when they where equal. That fix a buildbot error. Added test for this.
上级 317b5783
......@@ -539,12 +539,13 @@ class TensorType(Type):
# Find places where both a and b have inf of the same sign.
both_inf = a_inf * numpy.isinf(b)
#cmp_elemwise is True when we have inf and -inf.
#cmp_elemwise is weird when we have inf and -inf.
#set it to False
cmp_elemwise = numpy.where(both_inf&cmp_elemwise,
a==b,cmp_elemwise)
#check the sign of the inf
both_inf = numpy.where(both_inf,cmp_elemwise,both_inf)
both_inf = numpy.where(both_inf,a==b,both_inf)
if allow_remove_inf:
both_inf += a_inf
......
......@@ -736,6 +736,30 @@ _approx_eq.debug = 0
# val = fn(*args_in)
# self.failUnless( numpy.all(val == arg_out), (val, arg_out))
def test_tensor_values_eq_approx():
#test, inf, -inf and nan equal themself
a=numpy.asarray([-numpy.inf,-1,0,1,numpy.inf,numpy.nan])
import pdb;pdb.set_trace()
assert TensorType.values_eq_approx(a,a)
#test inf, -inf don't equal themself
b=numpy.asarray([numpy.inf,-1,0,1,numpy.inf,numpy.nan])
assert not TensorType.values_eq_approx(a,b)
b=numpy.asarray([-numpy.inf,-1,0,1,-numpy.inf,numpy.nan])
assert not TensorType.values_eq_approx(a,b)
#test allow_remove_inf
b=numpy.asarray([numpy.inf,-1,0,1,5,numpy.nan])
assert TensorType.values_eq_approx(a,b,allow_remove_inf=True)
b=numpy.asarray([numpy.inf,-1,0,1,5,6])
assert not TensorType.values_eq_approx(a,b,allow_remove_inf=True)
#test allow_remove_nan
b=numpy.asarray([numpy.inf,-1,0,1,5,numpy.nan])
assert not TensorType.values_eq_approx(a,b,allow_remove_nan=False)
b=numpy.asarray([-numpy.inf,-1,0,1,numpy.inf,6])
assert not TensorType.values_eq_approx(a,b,allow_remove_nan=False)
class T_Shape(unittest.TestCase):
def test_basic0(self):
s = shape(numpy.ones((5, 3)))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论