Skip to content

Commit 7bd147d

Browse files
author
Release Manager
committed
gh-36207: Remove self-`cimport`s <!-- ^^^^^ 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 #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> Some Cython modules contain redundant `cimport` statements that cimport from themselves - directly or indirectly. We remove them and make some related cleanups of `import`s/`cimport`s. This helps with Cython 3.0.2, in which the self-`cimport`s trigger surprising behavior in the presence of implicit namespace packages. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> - Cherry-picked from #35095 <!-- 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. - [x] The description explains in detail what this PR is about. - [ ] 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 - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36207 Reported by: Matthias Köppe Reviewer(s): Frédéric Chapoton
2 parents 328988d + 1ba481b commit 7bd147d

File tree

13 files changed

+37
-51
lines changed

13 files changed

+37
-51
lines changed

src/sage/algebras/quatalg/quaternion_algebra_element.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Check that :trac:`20829` is fixed::
3434

3535
from sage.structure.element cimport AlgebraElement, Element
3636
from sage.structure.richcmp cimport rich_to_bool, rich_to_bool_sgn, richcmp_item
37-
from sage.algebras.quatalg.quaternion_algebra_element cimport QuaternionAlgebraElement_abstract
3837
from sage.rings.rational cimport Rational
3938
from sage.rings.integer cimport Integer
4039
from sage.rings.number_field.number_field_element cimport NumberFieldElement

src/sage/graphs/base/boost_graph.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,15 @@ cpdef bandwidth_heuristics(g, algorithm='cuthill_mckee'):
561561
562562
Given a wrong algorithm::
563563
564-
from sage.graphs.base.boost_graph import bandwidth_heuristics
564+
sage: from sage.graphs.base.boost_graph import bandwidth_heuristics
565565
sage: bandwidth_heuristics(graphs.PathGraph(3), algorithm='tip top')
566566
Traceback (most recent call last):
567567
...
568568
ValueError: unknown algorithm 'tip top'
569569
570570
Given a graph with no edges::
571571
572-
from sage.graphs.base.boost_graph import bandwidth_heuristics
572+
sage: from sage.graphs.base.boost_graph import bandwidth_heuristics
573573
sage: bandwidth_heuristics(Graph())
574574
(0, [])
575575
sage: bandwidth_heuristics(graphs.RandomGNM(10,0)) # needs networkx

src/sage/graphs/comparability.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ def is_permutation(g, algorithm="greedy", certificate=False, check=True,
677677
....: break
678678

679679
"""
680-
from sage.graphs.comparability import is_comparability
681680
if certificate:
682681
683682
# First poset, we stop if it fails

src/sage/graphs/strongly_regular_db.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,6 @@ def SRG_126_50_13_24():
26492649
sage: G.is_strongly_regular(parameters=True)
26502650
(126, 50, 13, 24)
26512651
"""
2652-
from sage.graphs.strongly_regular_db import SRG_175_72_20_36
26532652
from sage.graphs.generators.smallgraphs import HoffmanSingletonGraph
26542653
hs = HoffmanSingletonGraph()
26552654
s = set(hs.vertices(sort=False)).difference(hs.neighbors(0) + [0])

src/sage/libs/flint/fmpz_poly.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from sage.arith.long cimport pyobject_to_long
2727
from sage.cpython.string cimport char_to_str, str_to_bytes
2828
from sage.structure.sage_object cimport SageObject
2929
from sage.rings.integer cimport Integer
30-
from sage.libs.flint.fmpz_poly cimport *
30+
3131

3232
cdef class Fmpz_poly(SageObject):
3333

src/sage/libs/flint/qsieve.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ been absorbed into flint.
77
from cysignals.signals cimport sig_on, sig_off
88
from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz
99
from sage.libs.flint.fmpz_factor cimport *
10-
from sage.libs.flint.qsieve cimport *
1110
from sage.rings.integer cimport Integer
1211

1312

src/sage/matrix/matrix_modn_sparse.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .matrix_sparse cimport Matrix_sparse
1+
from sage.matrix.matrix_sparse cimport Matrix_sparse
22
from sage.modules.vector_modn_sparse cimport *
33

44
cdef class Matrix_modn_sparse(Matrix_sparse):

src/sage/matrix/matrix_modn_sparse.pyx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -86,44 +86,42 @@ from libc.limits cimport UINT_MAX
8686
from cysignals.memory cimport check_calloc, sig_free
8787
from cysignals.signals cimport sig_on, sig_off
8888

89-
from sage.ext.stdsage cimport PY_NEW
89+
cimport sage.libs.linbox.givaro as givaro
90+
cimport sage.libs.linbox.linbox as linbox
9091

92+
from sage.arith.misc import is_prime
93+
from sage.data_structures.binary_search cimport *
94+
from sage.ext.stdsage cimport PY_NEW
9195
from sage.libs.flint.fmpz cimport fmpz_get_mpz, fmpz_set_mpz
9296
from sage.libs.flint.fmpz_mat cimport fmpz_mat_entry
93-
97+
from sage.libs.gmp.mpz cimport mpz_set
98+
from sage.libs.linbox.conversion cimport (get_method,
99+
METHOD_DEFAULT,
100+
METHOD_DENSE_ELIMINATION,
101+
METHOD_SPARSE_ELIMINATION,
102+
METHOD_BLACKBOX,
103+
METHOD_WIEDEMANN,
104+
new_linbox_matrix_modn_sparse,
105+
new_linbox_matrix_integer_sparse,
106+
new_linbox_vector_integer_dense,
107+
new_sage_vector_integer_dense)
108+
from sage.matrix.args cimport SparseEntry, MatrixArgs_init
109+
from sage.matrix.matrix2 import Matrix as Matrix2
110+
from sage.matrix.matrix_dense cimport Matrix_dense
111+
from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
112+
from sage.misc.verbose import verbose, get_verbose
113+
from sage.modules.vector_integer_dense cimport Vector_integer_dense
114+
from sage.modules.vector_integer_sparse cimport *
94115
from sage.modules.vector_modn_sparse cimport *
95-
96-
cimport sage.libs.linbox.givaro as givaro
97-
cimport sage.libs.linbox.linbox as linbox
98-
99-
from sage.libs.linbox.conversion cimport *
100-
101-
from .matrix2 cimport Matrix
102-
cimport sage.matrix.matrix as matrix
103-
cimport sage.matrix.matrix_sparse as matrix_sparse
104-
cimport sage.matrix.matrix_dense as matrix_dense
116+
from sage.rings.fast_arith cimport arith_int
105117
from sage.rings.finite_rings.integer_mod cimport IntegerMod_int, IntegerMod_abstract
106118
from sage.rings.integer cimport Integer
107-
from sage.rings.rational_field import QQ
108119
from sage.rings.integer_ring import ZZ
109-
110-
from sage.misc.verbose import verbose, get_verbose
111-
112-
from sage.matrix.matrix2 import Matrix as Matrix2
113-
from .args cimport SparseEntry, MatrixArgs_init
114-
from sage.arith.misc import is_prime
115-
116-
cimport sage.structure.element
117-
118-
from sage.data_structures.binary_search cimport *
119-
from sage.modules.vector_integer_sparse cimport *
120-
121-
from .matrix_integer_dense cimport Matrix_integer_dense
122-
from sage.modules.vector_integer_dense cimport Vector_integer_dense
120+
from sage.rings.rational_field import QQ
121+
from sage.structure.element cimport Matrix
123122

124123
################
125124
# TODO: change this to use extern cdef's methods.
126-
from sage.rings.fast_arith cimport arith_int
127125
cdef arith_int ai
128126
ai = arith_int()
129127
################
@@ -133,7 +131,7 @@ ai = arith_int()
133131
# Github Issue #12679.
134132
MAX_MODULUS = 46341
135133

136-
cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
134+
cdef class Matrix_modn_sparse(Matrix_sparse):
137135
def __cinit__(self):
138136
nr = self._nrows
139137
nc = self._ncols
@@ -257,7 +255,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
257255
else:
258256
raise ValueError("unknown matrix format")
259257

260-
cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix _right):
258+
cdef Matrix _matrix_times_matrix_(self, Matrix _right):
261259
"""
262260
This code is implicitly called for multiplying self by another
263261
sparse matrix.
@@ -336,7 +334,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
336334
set_entry(&ans.rows[i], j, s)
337335
return ans
338336

339-
def _matrix_times_matrix_dense(self, sage.structure.element.Matrix _right):
337+
def _matrix_times_matrix_dense(self, Matrix _right):
340338
"""
341339
Multiply self by the sparse matrix _right, and return the
342340
result as a dense matrix.
@@ -361,7 +359,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
361359
<class 'sage.matrix.matrix_mod2_dense.Matrix_mod2_dense'>
362360
"""
363361
cdef Matrix_modn_sparse right
364-
cdef matrix_dense.Matrix_dense ans
362+
cdef Matrix_dense ans
365363
right = _right
366364

367365
cdef c_vector_modint* v
@@ -871,7 +869,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
871869
self.cache('det', d)
872870
return d
873871
elif algorithm == 'generic':
874-
d = matrix_sparse.Matrix_sparse.determinant(self)
872+
d = Matrix_sparse.determinant(self)
875873
self.cache('det', d)
876874
return d
877875
else:
@@ -949,7 +947,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
949947
if algorithm == "generic":
950948
return Matrix_sparse.solve_right(self, B)
951949
else:
952-
if isinstance(B, sage.structure.element.Matrix):
950+
if isinstance(B, Matrix):
953951
from sage.matrix.special import diagonal_matrix
954952
m, d = self._solve_matrix_linbox(B, algorithm)
955953
return m * diagonal_matrix([QQ((1,x)) for x in d])
@@ -1121,7 +1119,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
11211119
from sage.modules.free_module_element import vector
11221120

11231121
cdef Matrix_integer_dense B
1124-
if not isinstance(mat, Matrix):
1122+
if not isinstance(mat, Matrix2):
11251123
B = <Matrix_integer_dense?> matrix(ZZ, mat, sparse=False)
11261124
else:
11271125
B = <Matrix_integer_dense?> mat.change_ring(ZZ).dense_matrix()

src/sage/modules/vector_modn_sparse.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
from cysignals.memory cimport sig_malloc, sig_free
99

10-
from sage.modules.vector_modn_sparse cimport c_vector_modint
11-
1210

1311
cdef int allocate_c_vector_modint(c_vector_modint* v, Py_ssize_t num_nonzero) except -1:
1412
"""

src/sage/rings/complex_mpc.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,4 +2557,3 @@ cdef class CCtoMPC(Map):
25572557

25582558
# Support Python's numbers abstract base class
25592559
# import numbers
2560-
from sage.rings.complex_mpc import MPComplexNumber

0 commit comments

Comments
 (0)