Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dividing a sparse matrix by a scalar gives a dense matrix, but multiplying gives a sparse one #5032

Closed
williamstein opened this issue Jan 20, 2009 · 4 comments

Comments

@williamstein
Copy link
Contributor

This is a bug:

sage: A = matrix(ZZ, 2, [1..4], sparse=True)
sage: type(A*1)
<type 'sage.matrix.matrix_integer_sparse.Matrix_integer_sparse'>
sage: type(A/1)
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>

Component: linear algebra

Issue created by migration from https://trac.sagemath.org/ticket/5032

@williamstein williamstein added this to the sage-3.3 milestone Jan 20, 2009
@williamstein williamstein self-assigned this Jan 20, 2009
@robertwb
Copy link
Contributor

comment:1

This is because it creates the matrix space over the fraction field when division is done, and I agree that it is a bug that the sparce flag doesn't get passed on. In contrast

sage: A = matrix(QQ, 2, [1..4], sparse=True)
sage: type(A)
<type 'sage.matrix.matrix_rational_sparse.Matrix_rational_sparse'>
sage: type(A/1)
<type 'sage.matrix.matrix_rational_sparse.Matrix_rational_sparse'>

What needs to change is

File:           /Users/robert/sage/sage-3.1.3/local/lib/python2.5/site-packages/sage/matrix/matrix_space.py
Definition:     MS.construction(self)
Source:
    def construction(self):
        from sage.categories.pushout import MatrixFunctor
        return MatrixFunctor(self.__nrows, self.__ncols), self.base_ring()

It should read

        return MatrixFunctor(self.__nrows, self.__ncols, is_sparse=self.is_sparse), self.base_ring()

@robertwb
Copy link
Contributor

comment:2

Attachment: 5032-sparce-matrix.patch.gz

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 23, 2009

comment:3

I was right in the middle of tracking this down when you posted the patch, so I figured I'd review it right away. ;)

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Jan 24, 2009

comment:4

Merged in Sage 3.3.alpha2

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Jan 24, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants