2 | | |
3 | | In your test, checking that multiplication of matrices with different implementation is disallowed, I replaced "*" by "+" for fun. |
4 | | |
5 | | The addition of "generic" and "sparse" gives the following error: |
6 | | |
7 | | {{{ |
8 | | RuntimeError: There is a bug in the coercion code in Sage. |
9 | | Both x (=[1 0] |
10 | | [0 0]) and y (=[1 0] |
11 | | [0 0]) are supposed to have identical parents but they don't. |
12 | | In fact, x has parent 'Full MatrixSpace of 2 by 2 dense matrices over Integer Ring' |
13 | | whereas y has parent 'Full MatrixSpace of 2 by 2 dense matrices over Integer Ring' |
14 | | Original elements [1 0] |
15 | | [0 0] (parent Full MatrixSpace of 2 by 2 dense matrices over Integer Ring) and [1 0] |
16 | | [0 0] (parent Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring) and maps |
17 | | <type 'NoneType'> None |
18 | | <type 'sage.categories.morphism.CallMorphism'> (map internal to coercion system -- copy before use) |
19 | | Call morphism: |
20 | | From: Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring |
21 | | To: Full MatrixSpace of 2 by 2 dense matrices over Integer Ring |
22 | | }}} |
23 | | |
24 | | Could it be possible to give a perhaps shorter and informative message? But first: is that relevant here to do what I suggest? |
25 | | |
26 | | Further, if I run the test directly in sage: |
27 | | |
28 | | {{{ |
29 | | sage: sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') |
30 | | sage: sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') |
31 | | sage: sage: M3 = MatrixSpace(ZZ, 2, sparse=True) |
32 | | sage: sage: M = [M1, M2, M3] |
33 | | sage: for i in range(3): |
34 | | ....: for j in range(3): |
35 | | ....: try: |
36 | | ....: s = M[i].an_element() * M[j].an_element() |
37 | | ....: print 'X' |
38 | | ....: except TypeError: |
39 | | ....: print 'O' |
40 | | ....: except RuntimeError: |
41 | | ....: print i,j |
42 | | ....: |
43 | | X |
44 | | --------------------------------------------------------------------------- |
45 | | SignalError Traceback (most recent call last) |
46 | | <ipython-input-5-b6610b9dabcc> in <module>() |
47 | | 2 for j in range(Integer(3)): |
48 | | 3 try: |
49 | | ----> 4 s = M[i].an_element() * M[j].an_element() |
50 | | 5 print 'X' |
51 | | 6 except TypeError: |
52 | | |
53 | | sage/sage2/src/sage/structure/element.pyx in sage.structure.element.Matrix.__mul__ (sage/sage2/src/build/cythonized/sage/structure/element.c:22149)() |
54 | | 3479 if have_same_parent(left, right): |
55 | | 3480 return (<Matrix>left)._matrix_times_matrix_(<Matrix>right) |
56 | | -> 3481 return coercion_model.bin_op(left, right, mul) |
57 | | 3482 |
58 | | 3483 def __truediv__(left, right): |
59 | | |
60 | | sage/sage2/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/sage2/src/build/cythonized/sage/structure/coerce.c:9442)() |
61 | | 1062 action = self.get_action(xp, yp, op, x, y) |
62 | | 1063 if action is not None: |
63 | | -> 1064 return (<Action>action)._call_(x, y) |
64 | | 1065 |
65 | | 1066 xy = None |
66 | | |
67 | | sage/sage2/src/sage/matrix/action.pyx in sage.matrix.action.MatrixMatrixAction._call_ (sage/sage2/src/build/cythonized/sage/matrix/action.c:4242)() |
68 | | 253 else: |
69 | | 254 A = A.dense_matrix() |
70 | | --> 255 prod = A._matrix_times_matrix_(B) |
71 | | 256 if A._subdivisions is not None or B._subdivisions is not None: |
72 | | 257 Asubs = A.subdivisions() |
73 | | |
74 | | sage/sage2/src/sage/matrix/matrix_integer_dense.pyx in sage.matrix.matrix_integer_dense.Matrix_integer_dense._matrix_times_matrix_ (sage/sage2/src/build/cythonized/sage/matrix/matrix_integer_dense.c:10054)() |
75 | | 872 M = self._new(self._nrows, right._ncols) |
76 | | 873 |
77 | | --> 874 sig_on() |
78 | | 875 fmpz_mat_mul(M._matrix, self._matrix, (<Matrix_integer_dense>right)._matrix) |
79 | | 876 sig_off() |
80 | | |
81 | | SignalError: Segmentation fault |
82 | | }}} |
83 | | |
84 | | What is that!!!??? |