ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 30 Sep 2013 11:16:55 -0500Sparse morphism versus sparse matrixhttps://ask.sagemath.org/question/10543/sparse-morphism-versus-sparse-matrix/I would like to use VectorSpaceMorphism when the underlying domain, codomain and matrix are sparse. However, the morphism seems to convert everything to dense. The following is from Sage 5.9.
sage: V = VectorSpace(QQ, 2, sparse=True)
sage: V
Sparse vector space of dimension 2 over Rational Field
sage: A = matrix(QQ, 2, 2, [[5, 6], [7, 8]], sparse=True)
sage: type(A)
sage.matrix.matrix_rational_sparse.Matrix_rational_sparse
sage: f = V.hom(A, V)
sage: f.matrix()
[5 6]
[7 8]
sage: type(f.matrix())
sage.matrix.matrix_rational_dense.Matrix_rational_dense
V.hom doesn't take the keyword 'sparse'.
sage: g = V.hom(A, V, sparse=True)
...
TypeError: hom() got an unexpected keyword argument 'sparse'
Let v be a vector in V, which is sparse. Tests with pdb show that when we call f(v), it converts v to dense behind the scenes, multiplies by the dense matrix, and
converts the dense vector result back to sparse. Of course this is slow. The more fundamental issue is that, in some of my applications, A will be too large to store densely.Mon, 16 Sep 2013 18:08:35 -0500https://ask.sagemath.org/question/10543/sparse-morphism-versus-sparse-matrix/Comment by vdelecroix for <p>I would like to use VectorSpaceMorphism when the underlying domain, codomain and matrix are sparse. However, the morphism seems to convert everything to dense. The following is from Sage 5.9.</p>
<pre><code>sage: V = VectorSpace(QQ, 2, sparse=True)
sage: V
Sparse vector space of dimension 2 over Rational Field
sage: A = matrix(QQ, 2, 2, [[5, 6], [7, 8]], sparse=True)
sage: type(A)
sage.matrix.matrix_rational_sparse.Matrix_rational_sparse
sage: f = V.hom(A, V)
sage: f.matrix()
[5 6]
[7 8]
sage: type(f.matrix())
sage.matrix.matrix_rational_dense.Matrix_rational_dense
</code></pre>
<p>V.hom doesn't take the keyword 'sparse'.</p>
<pre><code>sage: g = V.hom(A, V, sparse=True)
...
TypeError: hom() got an unexpected keyword argument 'sparse'
</code></pre>
<p>Let v be a vector in V, which is sparse. Tests with pdb show that when we call f(v), it converts v to dense behind the scenes, multiplies by the dense matrix, and
converts the dense vector result back to sparse. Of course this is slow. The more fundamental issue is that, in some of my applications, A will be too large to store densely.</p>
https://ask.sagemath.org/question/10543/sparse-morphism-versus-sparse-matrix/?comment=16968#post-id-16968Looks like a bug to me. You should ask the question on https://groups.google.com/forum/#!forum/sage-devel.Mon, 30 Sep 2013 11:16:55 -0500https://ask.sagemath.org/question/10543/sparse-morphism-versus-sparse-matrix/?comment=16968#post-id-16968