Skip to content

Matrix construction over prime field fails for some types of inputs #36104

Closed
@vneiger

Description

Steps To Reproduce

The constructor for matrices of type matrix_modn_dense is supposed to accept a matrix of Python integers int. Yet it will fail with overflow if given integers that exceed the maximum value for a long.

Try the following example:

sage: x = int(2**128 + 1)
sage: mat = matrix(GF(9001), [[x]])

Expected Behavior

We expect that mat is constructed as an 1 x 1 matrix with single entry the element GF(9001)(x) (represented by 7633 in sage).

Actual Behavior

[...]
File src/sage/matrix/matrix_modn_dense_template.pxi:531, in sage.matrix.matrix_modn_dense_double.Matrix_modn_dense_template.__init__()
    529 x = next(it)
    530 if type(x) is int:
--> 531     tmp = (<long>x) % p
    532     v[j] = tmp + (tmp<0)*p
    533 elif type(x) is IntegerMod_int and (<IntegerMod_int>x)._parent is R:

OverflowError: Python int too large to convert to C long

Additional Information

We see in the error message that there is an attempt to convert x into a long, hence the overflow error.

Environment

- **OS**: ubuntu 22.04
- **Sage Version**: 10.1.rc0

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions