Ticket #10714 (closed defect: fixed)
Rows of a zero-row sparse matrix are incorrect
| Reported by: | rbeezer | Owned by: | jason, was |
|---|---|---|---|
| Priority: | major | Milestone: | sage-4.6.2 |
| Component: | linear algebra | Keywords: | |
| Cc: | Work issues: | ||
| Report Upstream: | N/A | Reviewers: | Jason Grout |
| Authors: | Rob Beezer | Merged in: | sage-4.6.2.rc0 |
| Dependencies: | Stopgaps: |
Description (last modified by rbeezer) (diff)
Row vectors from a sparse matrix are incorrect when the matrix has zero rows.
sage: D = matrix(0, 2, sparse=False) sage: D.parent() Full MatrixSpace of 0 by 2 dense matrices over Integer Ring sage: D.nrows() 0 sage: D.rows() [] sage: S = matrix(0, 2, sparse=True) sage: S.parent() Full MatrixSpace of 0 by 2 sparse matrices over Integer Ring sage: S.nrows() 0 sage: S.rows() [(0, 0)]
sage/matrix/matrix1.Matrix.sparse_rows() is the place to look.
Apply trac_10714-rows-sparse-matrices.patch, trac_10714-columns-sparse-matrices.patch
Attachments
Change History
comment:2 in reply to: ↑ 1 ; follow-ups: ↓ 3 ↓ 5 Changed 2 years ago by was
Replying to jason:
Good catch! The rows returned should probably be sparse vectors too.
It seems to me like they are sparse vectors.
sage: S = matrix(0, 2, sparse=True) sage: v = S.rows()[0] sage: type(v) <type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'> sage: v.is_sparse() True
comment:3 in reply to: ↑ 2 Changed 2 years ago by jason
Replying to was:
Replying to jason:
Good catch! The rows returned should probably be sparse vectors too.
It seems to me like they are sparse vectors.
sage: S = matrix(0, 2, sparse=True) sage: v = S.rows()[0] sage: type(v) <type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'> sage: v.is_sparse() True
Great.
comment:4 Changed 2 years ago by rbeezer
- Status changed from new to needs_review
- Authors set to Rob Beezer
The problem seems to be the append() at the outer level in the "finish up" stanza.
Patch just short-circuits when there are no rows and returns an empty list before anything happens to it. Passes all tests on 4.6.2.alpha2.
comment:5 in reply to: ↑ 2 Changed 2 years ago by rbeezer
Replying to was:
It seems to me like they are sparse vectors.
Correct. Returned vectors have their entries specified by dictionaries when created, so they default to sparse.
comment:6 Changed 2 years ago by rbeezer
- Status changed from needs_review to needs_work
Should have checked this sooner. Columns behave poorly as well. I'll work up a companion patch.
sage: A = matrix(2,0,[[],[]], sparse=True) sage: A.parent() Full MatrixSpace of 2 by 0 sparse matrices over Integer Ring sage: A.columns() [(0, 0)]
comment:7 Changed 2 years ago by rbeezer
- Status changed from needs_work to needs_review
- Description modified (diff)
Isomorphic fix for columns in second patch, but apply in the order: rows first, then columns. Which seems appropriate.
comment:8 Changed 2 years ago by jason
- Status changed from needs_review to positive_review
- Reviewers set to Jason Grout
Looks great! Thanks for your work on this!
comment:9 Changed 2 years ago by jdemeyer
- Status changed from positive_review to needs_work
Please change the commit message of the second patch.
comment:10 Changed 2 years ago by rbeezer
- Status changed from needs_work to positive_review
Commit message fixed - sorry about that.
Fixed patch replaces the old one, so apply "rows," then "columns."
comment:11 Changed 2 years ago by jdemeyer
- Status changed from positive_review to closed
- Resolution set to fixed
- Merged in set to sage-4.6.2.rc0


Good catch! The rows returned should probably be sparse vectors too.