Ticket #6553 (closed defect: fixed)
[with patch, positive review] fast slicing of sparse matrices
| Reported by: | jason | Owned by: | was |
|---|---|---|---|
| Priority: | major | Milestone: | sage-4.1.1 |
| Component: | linear algebra | Keywords: | |
| Cc: | rbeezer | Work issues: | |
| Report Upstream: | Reviewers: | Rob Beezer | |
| Authors: | Jason Grout | Merged in: | Sage 4.1.1.alpha1 |
| Dependencies: | Stopgaps: |
Description
Extracting a slice from a sparse matrix is insanely slow, as the code effectively treats the matrix as a dense matrix.
Attachments
Change History
comment:1 Changed 4 years ago by jason
- Summary changed from fast slicing of sparse matrices to [with patch, needs review] fast slicing of sparse matrices
comment:3 Changed 4 years ago by rbeezer
- Summary changed from [with patch, needs review] fast slicing of sparse matrices to [with patch, needs work] fast slicing of sparse matrices
Nicely done. Three comments before giving this a positive review.
- The last test behaves differently for me, and the result seems "more correct" according to the density specified. This is on 4.1.rc1 (which is the newest upgrade I could muster).
sage: len(B.nonzero_positions())
Expected:
14047
Got:
100550
- Lists of non-integers (admittedly silly) fails silently and incorrectly. It would appear that no entry of the new matrix gets set properly, so the result is the zero matrix of the correct size.
sage: A = random_matrix(ZZ, 20, 20, x=10, sparse=True) sage: len(A.nonzero_positions()) 353 sage: A.matrix_from_rows_and_columns([1.1, 2.1, 3.1, 4.1], [5.1, 6.1, 7.1, 8.1]) [0 0 0 0] [0 0 0 0] [0 0 0 0] [0 0 0 0]
- I'd think the doctests would be improved if there were tests for
(a) the condition in (2)
(b) the case of non-list input (raising the TypeError as implemented)
comment:4 Changed 4 years ago by jason
- Summary changed from [with patch, needs work] fast slicing of sparse matrices to [with patch, needs review] fast slicing of sparse matrices
Thanks for reviewing these so quickly!
- Are you on a 64-bit system (maybe you are getting a different random matrix)? That doctest quite definitely passes for me. I agree that your answer seems more correct, though.
- The error is in the sparse matrix indexing function, not in this function. I've opened up #6569 to address this issue, with a relevant example. I don't think that should hold back this code.
- The condition in (2) should be tested in #6569. I've updated the patch to include a doctest for (b).
comment:6 Changed 4 years ago by rbeezer
Yes, I'm testing on a 64-bit system. What do you want to do with this doctest?
I think that is all that needs to be addressed now, since you are right that the non-integer index and density behavior belong elsewhere.
Solve one problem and expose two more? ;-)
Rob
comment:7 Changed 4 years ago by jason
I've updated the patch again with both of our outputs. It should pass your doctests now too. Can you review it again?
Thanks!
comment:8 Changed 4 years ago by rbeezer
- Reviewers set to Rob Beezer
- Summary changed from [with patch, needs review] fast slicing of sparse matrices to [with patch, positive review] fast slicing of sparse matrices
The fix on the one doctest works. Passes tests for all of sage/matrix/*
Positive review.
PS The discrepancy here, and as illustrated in #3436, is troubling.


Before, I waited for several minutes before giving up.
AFTER:
Also:
BEFORE:
AFTER: