id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,merged,author,reviewer,upstream,work_issues,branch,commit,dependencies,stopgaps
18312,Construction of a sparse matrix from sparse vectors does not exploit sparseness,nthiery,,"{{{
sage: n = 10^3
sage: F = FreeModule(QQ, n, sparse=True)
sage: v = F.an_element()
sage: vectors = [v]*n
sage: %time a = matrix(vectors, sparse=True)
CPU times: user 2.01 s, sys: 38.4 ms, total: 2.05 s
Wall time: 1.96 s
}}}
Compare with the construction of the same matrix through an
intermediate dictionary:
{{{
sage: %time b = matrix(QQ, n, {(i,j): c for i,v in enumerate(vectors) for j,c in v.iteritems()}, sparse=True)
CPU times: user 7.33 ms, sys: 124 µs, total: 7.46 ms
Wall time: 6.06 ms
sage: a == b
True
}}}
Running `%prun` shows that the input vectors are converted to dense
lists and back (gasp!), which gives a complexity of `n^2` instead of
linear in the number of nonzero entries as would be expected.
See also: #10312",defect,closed,major,sage-8.9,linear algebra,fixed,sparse matrix constructor,jdemeyer vdelecroix,,Travis Scrimshaw,Vincent Delecroix,N/A,,2044e5259d0b897c0b65d430c3c06f4a5444561a,2044e5259d0b897c0b65d430c3c06f4a5444561a,,