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

fix SparseType.values_eq_approx when there is many elements.

上级 b73ee1ac
...@@ -222,10 +222,12 @@ class SparseType(gof.Type): ...@@ -222,10 +222,12 @@ class SparseType(gof.Type):
#WARNING: equality comparison of sparse matrices is not fast or easy #WARNING: equality comparison of sparse matrices is not fast or easy
# we definitely do not want to be doing this un-necessarily during # we definitely do not want to be doing this un-necessarily during
# a FAST_RUN computation.. # a FAST_RUN computation..
return scipy.sparse.issparse(a) \ if not scipy.sparse.issparse(a) or not scipy.sparse.issparse(b):
and scipy.sparse.issparse(b) \ return False
and ((abs(a-b).sum() < (1e-6 * a.nnz)) diff = abs(a-b)
or (a.nnz==0 and b.nnz==0))#in case a and b are empty if diff.nnz == 0:
return True
return max(diff)<eps
def values_eq(self, a, b): def values_eq(self, a, b):
#WARNING: equality comparison of sparse matrices is not fast or easy #WARNING: equality comparison of sparse matrices is not fast or easy
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论