提交 1c739b72 authored 作者: Frederic's avatar Frederic

fix SparseType.may_share_memory with 2 sparse inputs.

上级 0d465332
...@@ -437,7 +437,9 @@ class SparseType(gof.Type): ...@@ -437,7 +437,9 @@ class SparseType(gof.Type):
# This is Fred suggestion for a quick and dirty way of checking # This is Fred suggestion for a quick and dirty way of checking
# aliasing .. this can potentially be further refined (ticket #374) # aliasing .. this can potentially be further refined (ticket #374)
if _is_sparse(a) and _is_sparse(b): if _is_sparse(a) and _is_sparse(b):
return a is b return (SparseType.may_share_memory(a, b.data) or
SparseType.may_share_memory(a, b.indices) or
SparseType.may_share_memory(a, b.indptr))
if _is_sparse(b) and isinstance(a, numpy.ndarray): if _is_sparse(b) and isinstance(a, numpy.ndarray):
a, b = b, a a, b = b, a
if _is_sparse(a) and isinstance(b, numpy.ndarray): if _is_sparse(a) and isinstance(b, numpy.ndarray):
......
...@@ -1323,6 +1323,10 @@ def test_may_share_memory(): ...@@ -1323,6 +1323,10 @@ def test_may_share_memory():
(b.indptr, a, False), (b.indptr, a, False),
(b.indices, a, False), (b.indices, a, False),
(as_ar(b.shape), a, False), (as_ar(b.shape), a, False),
(a.transpose(), a, True),
(b.transpose(), b, True),
(a.transpose(), b, False),
(b.transpose(), a, False),
]: ]:
assert SparseType.may_share_memory(a_, b_) == rep assert SparseType.may_share_memory(a_, b_) == rep
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论