Skip to content

Commit

Permalink
sagemathgh-36105: sage.rings.finite_rings.element_*: Remove unused …
Browse files Browse the repository at this point in the history
…imports

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Likewise for the module providing the parent class.

Also replace an import that is more specific than necessary, which helps
for modularization.

<!-- Why is this change required? What problem does it solve? -->
- Part of: sagemath#29705
- Cherry-picked from: sagemath#35095
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36105
Reported by: Matthias Köppe
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Aug 31, 2023
2 parents f4b2fe9 + c0bad32 commit 22446cb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 59 deletions.
20 changes: 4 additions & 16 deletions src/sage/rings/finite_rings/element_givaro.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ from cypari2.gen cimport Gen
from cypari2.stack cimport clear_stack

from sage.structure.parent cimport Parent
from sage.structure.element cimport Vector

from sage.interfaces.abc import GapElement

cdef object is_IntegerMod
cdef object Integer
cdef object Rational
cdef object ConwayPolynomials
cdef object conway_polynomial
cdef object MPolynomial
cdef object Polynomial
cdef object FreeModuleElement


cdef void late_import():
"""
Expand All @@ -84,11 +83,8 @@ cdef void late_import():
global is_IntegerMod, \
Integer, \
Rational, \
ConwayPolynomials, \
conway_polynomial, \
MPolynomial, \
Polynomial, \
FreeModuleElement
Polynomial

if is_IntegerMod is not None:
return
Expand All @@ -102,20 +98,12 @@ cdef void late_import():
import sage.rings.rational
Rational = sage.rings.rational.Rational

import sage.databases.conway
ConwayPolynomials = sage.databases.conway.ConwayPolynomials

import sage.rings.finite_rings.finite_field_constructor
conway_polynomial = sage.rings.finite_rings.conway_polynomials.conway_polynomial

import sage.rings.polynomial.multi_polynomial_element
MPolynomial = sage.rings.polynomial.multi_polynomial_element.MPolynomial

import sage.rings.polynomial.polynomial_element
Polynomial = sage.rings.polynomial.polynomial_element.Polynomial

import sage.modules.free_module_element
FreeModuleElement = sage.modules.free_module_element.FreeModuleElement

cdef class Cache_givaro(Cache_base):
def __init__(self, parent, unsigned int p, unsigned int k, modulus, repr="poly", cache=False):
Expand Down Expand Up @@ -391,7 +379,7 @@ cdef class Cache_givaro(Cache_base):
return self.parent(eval(e.replace("^", "**"),
self.parent.gens_dict()))

elif isinstance(e, FreeModuleElement):
elif isinstance(e, Vector):
if self.parent.vector_space(map=False) != e.parent():
raise TypeError("e.parent must match self.vector_space")
ret = self._zero_element
Expand Down
28 changes: 2 additions & 26 deletions src/sage/rings/finite_rings/element_ntl_gf2e.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ from sage.structure.richcmp cimport (richcmp,
richcmp_not_equal, rich_to_bool)

from sage.structure.parent cimport Parent
from sage.structure.element cimport Vector

from sage.rings.finite_rings.finite_field_base cimport FiniteField

Expand All @@ -50,15 +51,10 @@ from sage.interfaces.abc import GapElement


cdef object is_IntegerMod
cdef object IntegerModRing_generic
cdef object Integer
cdef object Rational
cdef object is_Polynomial
cdef object ConwayPolynomials
cdef object conway_polynomial
cdef object MPolynomial
cdef object Polynomial
cdef object FreeModuleElement
cdef object GF
cdef object GF2, GF2_0, GF2_1

Expand All @@ -69,15 +65,10 @@ cdef int late_import() except -1:
imports.
"""
global is_IntegerMod, \
IntegerModRing_generic, \
Integer, \
Rational, \
is_Polynomial, \
ConwayPolynomials, \
conway_polynomial, \
MPolynomial, \
Polynomial, \
FreeModuleElement, \
GF, \
GF2, GF2_0, GF2_1

Expand All @@ -87,30 +78,15 @@ cdef int late_import() except -1:
import sage.rings.finite_rings.integer_mod
is_IntegerMod = sage.rings.finite_rings.integer_mod.is_IntegerMod

import sage.rings.finite_rings.integer_mod_ring
IntegerModRing_generic = sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic

import sage.rings.rational
Rational = sage.rings.rational.Rational

import sage.rings.polynomial.polynomial_element
is_Polynomial = sage.rings.polynomial.polynomial_element.is_Polynomial

import sage.databases.conway
ConwayPolynomials = sage.databases.conway.ConwayPolynomials

import sage.rings.finite_rings.conway_polynomials
conway_polynomial = sage.rings.finite_rings.conway_polynomials.conway_polynomial

import sage.rings.polynomial.multi_polynomial_element
MPolynomial = sage.rings.polynomial.multi_polynomial_element.MPolynomial

import sage.rings.polynomial.polynomial_element
Polynomial = sage.rings.polynomial.polynomial_element.Polynomial

import sage.modules.free_module_element
FreeModuleElement = sage.modules.free_module_element.FreeModuleElement

import sage.rings.finite_rings.finite_field_constructor
GF = sage.rings.finite_rings.finite_field_constructor.FiniteField
GF2 = GF(2)
Expand Down Expand Up @@ -313,7 +289,7 @@ cdef class Cache_ntl_gf2e(Cache_base):
elif isinstance(e, str):
return self._parent(eval(e.replace("^","**"),self._parent.gens_dict()))

elif isinstance(e, FreeModuleElement):
elif isinstance(e, Vector):
if self._parent.vector_space(map=False) != e.parent():
raise TypeError("e.parent must match self.vector_space")
ztmp = Integer(e.list(),2)
Expand Down
9 changes: 3 additions & 6 deletions src/sage/rings/finite_rings/element_pari_ffelt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ from sage.rings.integer cimport Integer
from sage.rings.polynomial.polynomial_element import Polynomial
from sage.rings.polynomial.multi_polynomial_element import MPolynomial
from sage.rings.rational import Rational
from sage.structure.element cimport Vector
from sage.structure.richcmp cimport rich_to_bool

try:
from sage.modules.free_module_element import FreeModuleElement
except ImportError:
FreeModuleElement = ()

from sage.interfaces.abc import GapElement


cdef GEN _INT_to_FFELT(GEN g, GEN x) except NULL:
"""
Convert the t_INT `x` to an element of the field of definition of
Expand Down Expand Up @@ -457,7 +454,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement):
sig_off()
raise TypeError(f"unable to convert PARI {x.type()} to finite field element")

elif (isinstance(x, FreeModuleElement)
elif (isinstance(x, Vector)
and x.parent() is self._parent.vector_space(map=False)):
g = (<pari_gen>self._parent._gen_pari).g
t = g[1] # codeword: t_FF_FpXQ, t_FF_Flxq, t_FF_F2xq
Expand Down
12 changes: 1 addition & 11 deletions src/sage/rings/finite_rings/finite_field_ntl_gf2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ def late_import():
"""
if "GF2" in globals():
return
global is_FiniteField, exists_conway_polynomial, conway_polynomial, Cache_ntl_gf2e, GF, GF2, is_Polynomial

import sage.rings.finite_rings.finite_field_base
is_FiniteField = sage.rings.finite_rings.finite_field_base.is_FiniteField

import sage.rings.finite_rings.conway_polynomials
exists_conway_polynomial = sage.rings.finite_rings.conway_polynomials.exists_conway_polynomial
conway_polynomial = sage.rings.finite_rings.conway_polynomials.conway_polynomial
global Cache_ntl_gf2e, GF, GF2

import sage.rings.finite_rings.element_ntl_gf2e
Cache_ntl_gf2e = sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e
Expand All @@ -49,9 +42,6 @@ def late_import():
GF = sage.rings.finite_rings.finite_field_constructor.GF
GF2 = GF(2)

import sage.rings.polynomial.polynomial_element
is_Polynomial = sage.rings.polynomial.polynomial_element.is_Polynomial


class FiniteField_ntl_gf2e(FiniteField):
"""
Expand Down

0 comments on commit 22446cb

Please sign in to comment.