Changes between Version 36 and Version 41 of Ticket #25076


Ignore:
Timestamp:
04/02/18 15:15:50 (3 years ago)
Author:
SimonKing
Comment:

OK, just adding a test here, and then opening another ticket for the two remaining issues (that do belong together).


New commits:

bf9cefdNew MatrixArgs object to deal with constructing matrices
cc82825Merge branch 'u/jdemeyer/new_matrixinput_object_to_deal_with_constructing_matrices' of git://trac.sagemath.org/sage into t/25076/fix_matrix_gfpn_dense___int
bed63f0Add a test ensuring that #24742 remains fixed

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #25076

    • Property Status changed from needs_work to needs_review
    • Property Authors changed from to SimonKing
    • Property Branch changed from to u/SimonKing/fix_matrix_gfpn_dense___int
    • Property Keywords _mul_long removed
    • Property Commit changed from to bed63f0a555cb1b8f291ec65428c0cf972fd40f8
  • Ticket #25076 – Description

    v36 v41  
    88[0 0 0]
    99sage: M*int(1)
    10 ---------------------------------------------------------------------------
    11 ValueError                                Traceback (most recent call last)
    12 <ipython-input-3-1a2faedb318b> in <module>()
    13 ----> 1 M*int(Integer(1))
    14 
    15 /home/king/Sage/git/sage/src/sage/structure/element.pyx in sage.structure.element.Matrix.__mul__ (build/cythonized/sage/structure/element.c:23460)()
    16    3671         if have_same_parent(left, right):
    17    3672             return (<Matrix>left)._matrix_times_matrix_(<Matrix>right)
    18 -> 3673         return coercion_model.bin_op(left, right, mul)
    19    3674
    20    3675     def __truediv__(left, right):
    21 
    22 /home/king/Sage/git/sage/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:9671)()
    23    1111             if xp is yp:
    24    1112                 return op(x,y)
    25 -> 1113             action = self.get_action(xp, yp, op, x, y)
    26    1114             if action is not None:
    27    1115                 return (<Action>action)._call_(x, y)
    28 
    29 /home/king/Sage/git/sage/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.get_action (build/cythonized/sage/structure/coerce.c:16889)()
    30    1654         except KeyError:
    31    1655             pass
    32 -> 1656         action = self.discover_action(R, S, op, r, s)
    33    1657         action = self.verify_action(action, R, S, op)
    34    1658         self._action_maps.set(R, S, op, action)
    35 
    36 /home/king/Sage/git/sage/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.discover_action (build/cythonized/sage/structure/coerce.c:18411)()
    37    1804
    38    1805         if isinstance(R, Parent):
    39 -> 1806             action = (<Parent>R).get_action(S, op, True, r, s)
    40    1807             if action is not None:
    41    1808                 return action
    42 
    43 /home/king/Sage/git/sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.get_action (build/cythonized/sage/structure/parent.c:21664)()
    44    2493         action = self._get_action_(S, op, self_on_left)
    45    2494         if action is None:
    46 -> 2495             action = self.discover_action(S, op, self_on_left, self_el, S_el)
    47    2496
    48    2497         if action is not None:
    49 
    50 /home/king/Sage/git/sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.discover_action (build/cythonized/sage/structure/parent.c:23017)()
    51    2604                     return action
    52    2605
    53 -> 2606                 if parent_is_integers(S) and not self.has_coerce_map_from(S):
    54    2607                     from sage.structure.coerce_actions import IntegerMulAction
    55    2608                     try:
    56 
    57 /home/king/Sage/git/sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.has_coerce_map_from (build/cythonized/sage/structure/parent.c:17925)()
    58    2022                 print("Warning: non-unique parents %s" % (type(S)))
    59    2023             return True
    60 -> 2024         return self._internal_coerce_map_from(S) is not None
    61    2025
    62    2026     cpdef _coerce_map_from_(self, S):
    63 
    64 /home/king/Sage/git/sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent._internal_coerce_map_from (build/cythonized/sage/structure/parent.c:18944)()
    65    2164         try:
    66    2165             _register_pair(self, S, "coerce")
    67 -> 2166             mor = self.discover_coerce_map_from(S)
    68    2167             #if mor is not None:
    69    2168             #    # Need to check that this morphism doesn't connect previously unconnected parts of the coercion diagram
    70 
    71 /home/king/Sage/git/sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.discover_coerce_map_from (build/cythonized/sage/structure/parent.c:19396)()
    72    2301                 return (<Parent>S)._embedding
    73    2302
    74 -> 2303         user_provided_mor = self._coerce_map_from_(S)
    75    2304
    76    2305         if user_provided_mor is None or user_provided_mor is False:
    77 
    78 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent._coerce_map_from_ (build/cythonized/sage/structure/parent_old.c:7549)()
    79     339     cpdef _coerce_map_from_(self, S):
    80     340         if self._element_constructor is None:
    81 --> 341             return self.coerce_map_from_c(S)
    82     342         else:
    83     343             return parent.Parent._coerce_map_from_(self, S)
    84 
    85 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent.coerce_map_from_c (build/cythonized/sage/structure/parent_old.c:4044)()
    86     157                 self._coerce_from_hash[S] = None
    87     158                 return None
    88 --> 159             mor = self.coerce_map_from_c(sage_type)
    89     160             if mor is not None:
    90     161                 mor = mor * sage_type._internal_coerce_map_from(S)
    91 
    92 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent.coerce_map_from_c (build/cythonized/sage/structure/parent_old.c:3768)()
    93     141             pass
    94     142
    95 --> 143         mor = self.coerce_map_from_c_impl(S)
    96     144         import sage.categories.morphism
    97     145         import sage.categories.map
    98 
    99 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent.coerce_map_from_c_impl (build/cythonized/sage/structure/parent_old.c:4710)()
    100     189         # Piggyback off the old code for now
    101     190         # WARNING: when working on this, make sure circular dependencies aren't introduced!
    102 --> 191         if self.has_coerce_map_from_c(S):
    103     192             if isinstance(S, type):
    104     193                 S = Set_PythonType(S)
    105 
    106 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent.has_coerce_map_from_c (build/cythonized/sage/structure/parent_old.c:6312)()
    107     275             except KeyError:
    108     276                 pass
    109 --> 277         x = self.has_coerce_map_from_c_impl(S)
    110     278         self._has_coerce_map_from.set(S, x)
    111     279         return x
    112 
    113 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent.has_coerce_map_from_c_impl (build/cythonized/sage/structure/parent_old.c:6489)()
    114     284             return False
    115     285         try:
    116 --> 286             self._coerce_c((<parent.Parent>S).an_element())
    117     287         except TypeError:
    118     288             return False
    119 
    120 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent._coerce_c (build/cythonized/sage/structure/parent_old.c:5382)()
    121     217             pass
    122     218         if HAS_DICTIONARY(self):
    123 --> 219             return self._coerce_impl(x)
    124     220         else:
    125     221             return self._coerce_c_impl(x)
    126 
    127 /home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in _coerce_impl(self, x)
    128    1100             and self.base_ring().has_coerce_map_from(x.base_ring())):
    129    1101             return self(x)
    130 -> 1102         return self._coerce_try(x, self.base_ring())
    131    1103
    132    1104     def _repr_(self):
    133 
    134 /home/king/Sage/git/sage/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent._coerce_try (build/cythonized/sage/structure/parent_old.c:5902)()
    135     255             try:
    136     256                 y = R._coerce_(x)
    137 --> 257                 return self(y)
    138     258             except (TypeError, AttributeError) as msg:
    139     259                 pass
    140 
    141 /home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in __call__(self, entries, coerce, copy, sparse)
    142     873             [t]
    143     874         """
    144 --> 875         return self.matrix(entries, coerce, copy)
    145     876
    146     877     def change_ring(self, R):
    147 
    148 /home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in matrix(self, x, coerce, copy)
    149    1886                 x = list_to_dict(x, m, n)
    150    1887                 copy = False
    151 -> 1888         return MC(self, x, copy=copy, coerce=coerce)
    152    1889
    153    1890     def matrix_space(self, nrows=None, ncols=None, sparse=False):
    154 
    155 /home/king/Sage/git/sage/src/sage/matrix/matrix_gfpn_dense.pyx in sage.matrix.matrix_gfpn_dense.Matrix_gfpn_dense.__init__ (build/cythonized/sage/matrix/matrix_gfpn_dense.c:5278)()
    156     423                 return
    157     424             if self._nrows != self._ncols:
    158 --> 425                 raise ValueError("Cannot initialise non-square matrix from {}".format(data))
    159     426             f = FfFromInt(self._converter.field_to_int(self._coerce_element(data)))
    160     427             x = self.Data.Data
    161 
     10...
    16211ValueError: Cannot initialise non-square matrix from 1
    16312}}}
    16413
    165 What #24742 doesn't fix:
    166 1. Multiplication of a matrix with a scalar that is given as a Python int fails to use _mul_long(), which is supported by sage.structure.element but isn't used anywhere in sage.matrix except in sage.matrix.matrix_gfpn_dense.
    167 2. The _mul_long implementation of Matrix_gfpn_dense is flawed, as it *should* do a coercion of the given integer into the underlying base ring (which is by computing the remainder modulo the modulus of the base ring), but currently uses a different way of conversion.
     14This ticket adds a test that makes sure that the issue remains fixed.