Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
sage.structure, sage.rings, sage.matrix: Use sage.rings.abc for Integ…
Browse files Browse the repository at this point in the history
…erModRing
  • Loading branch information
Matthias Koeppe committed Oct 1, 2021
1 parent 9e74b6a commit 8ef2b35
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
from sage.misc.derivative import multi_derivative
import sage.rings.abc
from sage.arith.numerical_approx cimport digits_to_bits
from copy import copy

Expand Down Expand Up @@ -822,8 +823,7 @@ cdef class Matrix(Matrix1):
if not K.is_integral_domain():
# The non-integral-domain case is handled almost entirely
# separately.
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
if is_IntegerModRing(K):
if isinstance(K, sage.rings.abc.IntegerModRing):
from sage.libs.pari import pari
A = pari(self.lift())
b = pari(B).lift()
Expand Down Expand Up @@ -1985,7 +1985,6 @@ cdef class Matrix(Matrix1):
sage: A.determinant() == B.determinant()
True
"""
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
from sage.symbolic.ring import is_SymbolicExpressionRing

cdef Py_ssize_t n
Expand Down Expand Up @@ -2031,7 +2030,7 @@ cdef class Matrix(Matrix1):
return d

# Special case for Z/nZ or GF(p):
if is_IntegerModRing(R) and self.is_dense():
if isinstance(R, sage.rings.abc.IntegerModRing) and self.is_dense():
import sys
# If the characteristic is prime and smaller than a machine
# word, use PARI.
Expand Down Expand Up @@ -14723,6 +14722,8 @@ cdef class Matrix(Matrix1):
for i from 0 <= i < size:
PyList_Append(M,<object>f(<object>PyList_GET_ITEM(L,i)))

from sage.rings.finite_rings.integer_mod_ring import IntegerModRing

return MatrixSpace(IntegerModRing(2),
nrows=self._nrows,ncols=self._ncols).matrix(M)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
except ImportError:
pass

if sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R):
if isinstance(R, sage.rings.abc.IntegerModRing):
from . import matrix_modn_dense_double, matrix_modn_dense_float
if R.order() < matrix_modn_dense_float.MAX_MODULUS:
return matrix_modn_dense_float.Matrix_modn_dense_float
Expand Down Expand Up @@ -326,7 +326,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
if implementation is not None:
raise ValueError("cannot choose an implementation for sparse matrices")

if sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R) and R.order() < matrix_modn_sparse.MAX_MODULUS:
if isinstance(R, sage.rings.abc.IntegerModRing) and R.order() < matrix_modn_sparse.MAX_MODULUS:
return matrix_modn_sparse.Matrix_modn_sparse

if sage.rings.rational_field.is_RationalField(R):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/finite_field_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ from sage.misc.persist import register_unpickle_override
from sage.misc.cachefunc import cached_method
from sage.misc.prandom import randrange
from sage.rings.integer cimport Integer
import sage.rings.abc
from sage.misc.superseded import deprecation_cython as deprecation

# Copied from sage.misc.fast_methods, used in __hash__() below.
Expand Down Expand Up @@ -1342,10 +1343,9 @@ cdef class FiniteField(Field):
False
"""
from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
if R is int or R is long or R is ZZ:
return True
if is_IntegerModRing(R) and self.characteristic().divides(R.characteristic()):
if isinstance(R, sage.rings.abc.IntegerModRing) and self.characteristic().divides(R.characteristic()):
return R.hom((self.one(),), check=False)
if is_FiniteField(R):
if R is self:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/parent.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2642,8 +2642,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject):
elif self_on_left and op is operator.pow:
S_is_int = parent_is_integers(S)
if not S_is_int:
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
if is_IntegerModRing(S):
from sage.rings.abc import IntegerModRing
if isinstance(S, IntegerModRing):
# We allow powering by an IntegerMod by treating it
# as an integer.
#
Expand Down

0 comments on commit 8ef2b35

Please sign in to comment.