Ticket #2658 (closed defect: fixed)
Matrix from a vector doesn't preserve the vector's parent ring automatically
| Reported by: | dfdeshom | Owned by: | was |
|---|---|---|---|
| Priority: | major | Milestone: | sage-3.0 |
| Component: | linear algebra | Keywords: | |
| Cc: | Work issues: | ||
| Report Upstream: | Reviewers: | ||
| Authors: | Merged in: | ||
| Dependencies: | Stopgaps: |
Description
Creating a matrix from a vector doesn't preserve the vector's parent ring automatically.:
sage: v = vector(RR,range(5)) ; v ; v.parent() (0.000000000000000, 1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000) Vector space of dimension 5 over Real Field with 53 bits of precision sage: M=matrix(v) ; M ; M.parent() [0 1 2 3 4] Full MatrixSpace of 1 by 5 dense matrices over Integer Ring
This works if you specify the ring explicitly (ie Matrix(RR,v) ) but I don't see why sage can't do the "right" thing automatically.
Change History
comment:2 Changed 5 years ago by jason
- Status changed from new to closed
- Resolution set to duplicate
This is resolved in the matrix() rewrite in #2651.
comment:3 Changed 5 years ago by mabshoff
- Status changed from closed to reopened
- Resolution duplicate deleted
- Milestone changed from sage-3.0 to sage-2.11
This is not a duplicate and not fixed yet. Tickets like this get only closed when the original ticket is close. Reopened.
Cheers,
Michael
comment:4 Changed 5 years ago by dfdeshom
I'm glad mabshoff didn't close this. The matrix rewrite (#2651) missed some stuff:
sage: v = vector(IntegerModRing(2),range(5));v.parent() Vector space of dimension 5 over Ring of integers modulo 2 sage: M=matrix(v) ; M.parent() Full MatrixSpace of 1 by 5 dense matrices over Integer Ring
and :
sage: v = vector(QQ,range(5));v.parent() Vector space of dimension 5 over Rational Field sage: M=matrix(v) ; M.parent() Full MatrixSpace of 1 by 5 dense matrices over Integer Ring
comment:5 Changed 5 years ago by jason
Are you *sure* that the rewrite missed those things? The rewrite was applied in 3.0alpha0. You shouldn't get those results after applying #2651.
In fact, a doctest for the new matrix() rewrite is the following:
sage: matrix(vector(RR,[1,2,3])).parent() Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of precision
The fact that this doctest is not failing indicates that this issue is resolved.

The code tries to call v._matrix_(ZZ) and if this fails, it calls v._matrix_() (which gives the answer you want).
Is there a good reason for the code to call v._matrix_(ZZ) before trying v._matrix_()?