Opened 10 years ago
Closed 10 years ago
#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: | Merged in: | sage-4.6.2.rc0 | |
Authors: | Rob Beezer | Reviewers: | Jason Grout |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
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 (2)
Change History (13)
comment:1 follow-up: ↓ 2 Changed 10 years ago by
comment:2 in reply to: ↑ 1 ; follow-ups: ↓ 3 ↓ 5 Changed 10 years ago by
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 10 years ago by
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.
Changed 10 years ago by
comment:4 Changed 10 years ago by
- Status changed from new to needs_review
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 10 years ago by
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 10 years ago by
- 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 10 years ago by
- Description modified (diff)
- Status changed from needs_work to needs_review
Isomorphic fix for columns in second patch, but apply in the order: rows first, then columns. Which seems appropriate.
comment:8 Changed 10 years ago by
- Reviewers set to Jason Grout
- Status changed from needs_review to positive_review
Looks great! Thanks for your work on this!
comment:9 Changed 10 years ago by
- Status changed from positive_review to needs_work
Please change the commit message of the second patch.
Changed 10 years ago by
comment:10 Changed 10 years ago by
- 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 10 years ago by
- Merged in set to sage-4.6.2.rc0
- Resolution set to fixed
- Status changed from positive_review to closed
Good catch! The rows returned should probably be sparse vectors too.