def test_may_share_memory_scipy():
a = scipy.sparse.csc_matrix(scipy.sparse.eye(5, 3))
b = scipy.sparse.csc_matrix(scipy.sparse.eye(4, 3))
def as_ar(a):
return theano._asarray(a, dtype='int32')
for a_, b_, rep in [(a, a, True), (b, b, True), (a, b, False),
(a, a.data, True), (a, a.indptr, True),
(a, a.indices, True), (a, as_ar(a.shape), False),
(a.data, a, True), (a.indptr, a, True),
(a.indices, a, True), (as_ar(a.shape), a, False),
(b, b.data, True), (b, b.indptr, True),
(b, b.indices, True), (b, as_ar(b.shape), False),
(b.data, b, True), (b.indptr, b, True),
(b.indices, b, True), (as_ar(b.shape), b, False),
(b.data, a, False), (b.indptr, a, False),
(b.indices, a, False), (as_ar(b.shape), a, False)]:
assert may_share_memory(a_, b_) == rep
assert may_share_memory(b_, a_) == rep
# test that it raise error when needed.
for a_, b_, rep in [(a, (0,), False), (a, 1, False), (a, None, False)]:
assert may_share_memory(a_, b_, False) == rep
assert may_share_memory(b_, a_, False) == rep
try:
may_share_memory(a_, b_)
raise Exception("An error was expected")
except TypeError:
pass
try:
may_share_memory(b_, a_)
raise Exception("An error was expected")
except TypeError:
pass
test_may_share_memory.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录