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])
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)
评论列表
文章目录