def test_size():
"""
Ensure the `size` attribute of sparse matrices behaves as in numpy.
"""
for sparse_type in ('csc_matrix', 'csr_matrix'):
x = getattr(theano.sparse, sparse_type)()
y = getattr(scipy.sparse, sparse_type)((5, 7)).astype(config.floatX)
get_size = theano.function([x], x.size)
def check():
assert y.size == get_size(y)
# We verify that the size is correctly updated as we store more data
# into the sparse matrix (including zeros).
check()
y[0, 0] = 1
check()
y[0, 1] = 0
check()
评论列表
文章目录