Skip to content

Commit 911871a

Browse files
author
Release Manager
committed
sagemathgh-39488: Fix issue on matrix construction over integer mod ring for large coefficients Fixes sagemath#36104. In previous versions of Python, `int` size was limited and therefore could be cast to `long`. With Python 3 this limit does not exists and the code breaks with large integers. We modify the construction of `Matrix_modn_dense_template` from Python integers, directly using some existing cast from Sage. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: sagemath#39488 Reported by: Hugo Passe Reviewer(s): Vincent Neiger
2 parents b62d78d + d40c2a5 commit 911871a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/sage/matrix/matrix_modn_dense_template.pxi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
514514
sage: Matrix(Integers(4618990), 2, 2, [-1, int(-2), GF(7)(-3), 1/7]) # needs sage.rings.finite_rings
515515
[4618989 4618988]
516516
[ 4 2639423]
517+
518+
sage: Matrix(IntegerModRing(200), [[int(2**128+1), int(2**256+1), int(2**1024+1)]]) # needs sage.rings.finite_rings
519+
[ 57 137 17]
517520
"""
518521
ma = MatrixArgs_init(parent, entries)
519522
cdef long i, j
@@ -525,10 +528,7 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
525528
se = <SparseEntry>t
526529
x = se.entry
527530
v = self._matrix[se.i]
528-
if type(x) is int:
529-
tmp = (<long>x) % p
530-
v[se.j] = tmp + (tmp<0)*p
531-
elif type(x) is IntegerMod_int and (<IntegerMod_int>x)._parent is R:
531+
if type(x) is IntegerMod_int and (<IntegerMod_int>x)._parent is R:
532532
v[se.j] = <celement>(<IntegerMod_int>x).ivalue
533533
elif type(x) is Integer:
534534
if coerce:

0 commit comments

Comments
 (0)