#20211 closed defect (duplicate)
Unify matrix __init__ methods
Reported by: | jdemeyer | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | linear algebra | Keywords: | |
Cc: | vdelecroix | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
There are various inconsistencies in matrix __init__
methods (details to follow).
- This should work:
sage: M = MatrixSpace(ZZ, 2) sage: p = pari('[1, 2; 3, 4]') sage: M(p) Traceback (most recent call last): ... TypeError: entries has the wrong length
2.
sage: MatrixSpace(ZZ, 1, 1)([1]) [1] sage: MatrixSpace(ZZ, 1, 1)(vector([1])) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-12-d1b8d7e0999e> in <module>() ----> 1 MatrixSpace(ZZ, Integer(1), Integer(1))(vector([Integer(1)])) /usr/local/src/sage-config/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in __call__(self, entries, coerce, copy, sparse) 549 [t] 550 """ --> 551 return self.matrix(entries, coerce, copy) 552 553 def change_ring(self, R): /usr/local/src/sage-config/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in matrix(self, x, coerce, copy) 1564 x = list_to_dict(x, m, n) 1565 copy = False -> 1566 return MC(self, x, copy=copy, coerce=coerce) 1567 1568 def matrix_space(self, nrows=None, ncols=None, sparse=False): /usr/local/src/sage-config/src/sage/matrix/matrix_integer_dense.pyx in sage.matrix.matrix_integer_dense.Matrix_integer_dense.__init__ (build/cythonized/sage/matrix/matrix_integer_dense.c:6848)() 349 x = ZZ(entries) 350 except TypeError: --> 351 raise TypeError("unable to coerce entry to an integer") 352 is_list = False 353 elif type(entries) is list: TypeError: unable to coerce entry to an integer
- The error message does not correspond to what is happening with other entries
sage: matrix(QQ,2,2,0) [0 0] [0 0] sage: matrix(QQ,2,2,0.0) [0 0] [0 0] sage: matrix(QQ,2,2,'0') [0 0] [0 0] sage: matrix(QQ,2,2,'0.0') ... TypeError: entries must be coercible to a list or integer
If the data must be coercible then the last 3 should fail. Though, if the ring is provided I would be less strict and also allow conversion (and make all the above work).
- The following should either work or not work for all rings
sage: matrix(QQ,2,2,'3') [3 0] [0 3] sage: matrix(RBF,2,2,'3') [3.000000000000000 0] [ 0 3.000000000000000] sage: matrix(ZZ,2,2,'3') ... TypeError: entries has the wrong length sage: matrix(QQbar,2,2,'3') ... TypeError: entries has the wrong length
(there is something weird above since QQbar('3')
does not work but ZZ('3')
does)
Change History (9)
comment:1 Changed 4 years ago by
- Cc vdelecroix added
- Description modified (diff)
- Milestone changed from sage-7.1 to sage-8.1
comment:2 Changed 4 years ago by
- Description modified (diff)
comment:3 Changed 4 years ago by
comment:4 in reply to: ↑ description Changed 3 years ago by
comment:5 Changed 3 years ago by
- Description modified (diff)
I'm removing issue 5 since that's just QQbar(3.0)
versus ZZ(3.0)
. That has nothing to do with matrices.
comment:6 Changed 3 years ago by
So far, issues 2, 3 and 4 are fixed in #24742. The examples involving strings all become an error and the rest works.
comment:7 Changed 3 years ago by
And 1. is subtly wrong with the current version of #24742:
sage: M = MatrixSpace(ZZ, 2) sage: p = pari('[1, 2; 3, 4]') sage: M(p) [1 3] [2 4]
comment:8 Changed 3 years ago by
- Milestone changed from sage-8.1 to sage-duplicate/invalid/wontfix
- Resolution set to duplicate
- Status changed from new to closed
comment:9 Changed 3 years ago by
All fixed in #24742.
I noticed that you closed #19700 to move its resolution here, you might want to do the same with #19134.