From 3878e5154a7941cae1f06c6c7389f1049c72d5c0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 6 Sep 2023 22:16:45 -0700 Subject: [PATCH 1/7] Clean up cimports --- .../quatalg/quaternion_algebra_element.pyx | 1 - src/sage/libs/flint/fmpz_poly.pyx | 2 +- src/sage/matrix/matrix_modn_sparse.pyx | 38 +++++++++++-------- src/sage/modules/vector_modn_sparse.pyx | 2 - src/sage/rings/complex_mpc.pyx | 1 - src/sage/rings/ring_extension.pxd | 1 - src/sage/symbolic/constants_c_impl.pxi | 3 -- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index 8cb7e848fd0..723c284989e 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -34,7 +34,6 @@ Check that :trac:`20829` is fixed:: from sage.structure.element cimport AlgebraElement, Element from sage.structure.richcmp cimport rich_to_bool, rich_to_bool_sgn, richcmp_item -from sage.algebras.quatalg.quaternion_algebra_element cimport QuaternionAlgebraElement_abstract from sage.rings.rational cimport Rational from sage.rings.integer cimport Integer from sage.rings.number_field.number_field_element cimport NumberFieldElement diff --git a/src/sage/libs/flint/fmpz_poly.pyx b/src/sage/libs/flint/fmpz_poly.pyx index 8811ccf3a51..74915b37612 100644 --- a/src/sage/libs/flint/fmpz_poly.pyx +++ b/src/sage/libs/flint/fmpz_poly.pyx @@ -27,7 +27,7 @@ from sage.arith.long cimport pyobject_to_long from sage.cpython.string cimport char_to_str, str_to_bytes from sage.structure.sage_object cimport SageObject from sage.rings.integer cimport Integer -from sage.libs.flint.fmpz_poly cimport * + cdef class Fmpz_poly(SageObject): diff --git a/src/sage/matrix/matrix_modn_sparse.pyx b/src/sage/matrix/matrix_modn_sparse.pyx index dd908a4c91b..aaf9035b306 100644 --- a/src/sage/matrix/matrix_modn_sparse.pyx +++ b/src/sage/matrix/matrix_modn_sparse.pyx @@ -90,18 +90,26 @@ from sage.ext.stdsage cimport PY_NEW from sage.libs.flint.fmpz cimport fmpz_get_mpz, fmpz_set_mpz from sage.libs.flint.fmpz_mat cimport fmpz_mat_entry +from sage.libs.gmp.mpz cimport mpz_set from sage.modules.vector_modn_sparse cimport * cimport sage.libs.linbox.givaro as givaro cimport sage.libs.linbox.linbox as linbox -from sage.libs.linbox.conversion cimport * - -from .matrix2 cimport Matrix -cimport sage.matrix.matrix as matrix -cimport sage.matrix.matrix_sparse as matrix_sparse -cimport sage.matrix.matrix_dense as matrix_dense +from sage.libs.linbox.conversion cimport (get_method, + METHOD_DEFAULT, + METHOD_DENSE_ELIMINATION, + METHOD_SPARSE_ELIMINATION, + METHOD_BLACKBOX, + METHOD_WIEDEMANN, + new_linbox_matrix_modn_sparse, + new_linbox_matrix_integer_sparse, + new_linbox_vector_integer_dense, + new_sage_vector_integer_dense) + +from sage.matrix.matrix_sparse cimport Matrix_sparse +from sage.matrix.matrix_dense cimport Matrix_dense from sage.rings.finite_rings.integer_mod cimport IntegerMod_int, IntegerMod_abstract from sage.rings.integer cimport Integer from sage.rings.rational_field import QQ @@ -113,14 +121,14 @@ from sage.matrix.matrix2 import Matrix as Matrix2 from .args cimport SparseEntry, MatrixArgs_init from sage.arith.misc import is_prime -cimport sage.structure.element - from sage.data_structures.binary_search cimport * from sage.modules.vector_integer_sparse cimport * from .matrix_integer_dense cimport Matrix_integer_dense from sage.modules.vector_integer_dense cimport Vector_integer_dense +from sage.structure.element cimport Matrix + ################ # TODO: change this to use extern cdef's methods. from sage.rings.fast_arith cimport arith_int @@ -133,7 +141,7 @@ ai = arith_int() # Github Issue #12679. MAX_MODULUS = 46341 -cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): +cdef class Matrix_modn_sparse(Matrix_sparse): def __cinit__(self): nr = self._nrows nc = self._ncols @@ -257,7 +265,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): else: raise ValueError("unknown matrix format") - cdef sage.structure.element.Matrix _matrix_times_matrix_(self, sage.structure.element.Matrix _right): + cdef Matrix _matrix_times_matrix_(self, Matrix _right): """ This code is implicitly called for multiplying self by another sparse matrix. @@ -336,7 +344,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): set_entry(&ans.rows[i], j, s) return ans - def _matrix_times_matrix_dense(self, sage.structure.element.Matrix _right): + def _matrix_times_matrix_dense(self, Matrix _right): """ Multiply self by the sparse matrix _right, and return the result as a dense matrix. @@ -361,7 +369,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): """ cdef Matrix_modn_sparse right - cdef matrix_dense.Matrix_dense ans + cdef Matrix_dense ans right = _right cdef c_vector_modint* v @@ -871,7 +879,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): self.cache('det', d) return d elif algorithm == 'generic': - d = matrix_sparse.Matrix_sparse.determinant(self) + d = Matrix_sparse.determinant(self) self.cache('det', d) return d else: @@ -949,7 +957,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): if algorithm == "generic": return Matrix_sparse.solve_right(self, B) else: - if isinstance(B, sage.structure.element.Matrix): + if isinstance(B, Matrix): from sage.matrix.special import diagonal_matrix m, d = self._solve_matrix_linbox(B, algorithm) return m * diagonal_matrix([QQ((1,x)) for x in d]) @@ -1121,7 +1129,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): from sage.modules.free_module_element import vector cdef Matrix_integer_dense B - if not isinstance(mat, Matrix): + if not isinstance(mat, Matrix2): B = matrix(ZZ, mat, sparse=False) else: B = mat.change_ring(ZZ).dense_matrix() diff --git a/src/sage/modules/vector_modn_sparse.pyx b/src/sage/modules/vector_modn_sparse.pyx index 746f9897db2..e2dd1d7c1a6 100644 --- a/src/sage/modules/vector_modn_sparse.pyx +++ b/src/sage/modules/vector_modn_sparse.pyx @@ -7,8 +7,6 @@ from cysignals.memory cimport sig_malloc, sig_free -from sage.modules.vector_modn_sparse cimport c_vector_modint - cdef int allocate_c_vector_modint(c_vector_modint* v, Py_ssize_t num_nonzero) except -1: """ diff --git a/src/sage/rings/complex_mpc.pyx b/src/sage/rings/complex_mpc.pyx index c847a9302b5..bed1102d4c9 100644 --- a/src/sage/rings/complex_mpc.pyx +++ b/src/sage/rings/complex_mpc.pyx @@ -2557,4 +2557,3 @@ cdef class CCtoMPC(Map): # Support Python's numbers abstract base class # import numbers -from sage.rings.complex_mpc import MPComplexNumber diff --git a/src/sage/rings/ring_extension.pxd b/src/sage/rings/ring_extension.pxd index 1607dd6fc2e..9115f8d26f8 100644 --- a/src/sage/rings/ring_extension.pxd +++ b/src/sage/rings/ring_extension.pxd @@ -1,6 +1,5 @@ from sage.categories.map cimport Map from sage.rings.ring cimport CommutativeRing, CommutativeAlgebra -from sage.rings.ring_extension cimport RingExtension_generic cdef class RingExtension_generic(CommutativeAlgebra): diff --git a/src/sage/symbolic/constants_c_impl.pxi b/src/sage/symbolic/constants_c_impl.pxi index b92b14318aa..3818926a9a2 100644 --- a/src/sage/symbolic/constants_c_impl.pxi +++ b/src/sage/symbolic/constants_c_impl.pxi @@ -16,9 +16,6 @@ The constant `e` # http://www.gnu.org/licenses/ #***************************************************************************** -from sage.symbolic.expression cimport Expression - - # keep exp(1) for fast access # this is initialized in the constructor of the class E below to prevent # circular imports while loading the library From 2716f62591ba58de1f004c6320225f38fc82f0a6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 7 Sep 2023 13:04:54 -0700 Subject: [PATCH 2/7] src/sage/matrix/matrix_modn_sparse.pyx: Sort imports --- src/sage/matrix/matrix_modn_sparse.pxd | 2 +- src/sage/matrix/matrix_modn_sparse.pyx | 38 ++++++++++---------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/sage/matrix/matrix_modn_sparse.pxd b/src/sage/matrix/matrix_modn_sparse.pxd index 5c471a7082f..dded069b3d8 100644 --- a/src/sage/matrix/matrix_modn_sparse.pxd +++ b/src/sage/matrix/matrix_modn_sparse.pxd @@ -1,4 +1,4 @@ -from .matrix_sparse cimport Matrix_sparse +from sage.matrix.matrix_sparse cimport Matrix_sparse from sage.modules.vector_modn_sparse cimport * cdef class Matrix_modn_sparse(Matrix_sparse): diff --git a/src/sage/matrix/matrix_modn_sparse.pyx b/src/sage/matrix/matrix_modn_sparse.pyx index aaf9035b306..84cfbedb226 100644 --- a/src/sage/matrix/matrix_modn_sparse.pyx +++ b/src/sage/matrix/matrix_modn_sparse.pyx @@ -86,17 +86,15 @@ from libc.limits cimport UINT_MAX from cysignals.memory cimport check_calloc, sig_free from cysignals.signals cimport sig_on, sig_off -from sage.ext.stdsage cimport PY_NEW +cimport sage.libs.linbox.givaro as givaro +cimport sage.libs.linbox.linbox as linbox +from sage.arith.misc import is_prime +from sage.data_structures.binary_search cimport * +from sage.ext.stdsage cimport PY_NEW from sage.libs.flint.fmpz cimport fmpz_get_mpz, fmpz_set_mpz from sage.libs.flint.fmpz_mat cimport fmpz_mat_entry from sage.libs.gmp.mpz cimport mpz_set - -from sage.modules.vector_modn_sparse cimport * - -cimport sage.libs.linbox.givaro as givaro -cimport sage.libs.linbox.linbox as linbox - from sage.libs.linbox.conversion cimport (get_method, METHOD_DEFAULT, METHOD_DENSE_ELIMINATION, @@ -107,31 +105,23 @@ from sage.libs.linbox.conversion cimport (get_method, new_linbox_matrix_integer_sparse, new_linbox_vector_integer_dense, new_sage_vector_integer_dense) - -from sage.matrix.matrix_sparse cimport Matrix_sparse +from sage.matrix.args cimport SparseEntry, MatrixArgs_init +from sage.matrix.matrix2 import Matrix as Matrix2 from sage.matrix.matrix_dense cimport Matrix_dense +from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense +from sage.misc.verbose import verbose, get_verbose +from sage.modules.vector_integer_dense cimport Vector_integer_dense +from sage.modules.vector_integer_sparse cimport * +from sage.modules.vector_modn_sparse cimport * +from sage.rings.fast_arith cimport arith_int from sage.rings.finite_rings.integer_mod cimport IntegerMod_int, IntegerMod_abstract from sage.rings.integer cimport Integer -from sage.rings.rational_field import QQ from sage.rings.integer_ring import ZZ - -from sage.misc.verbose import verbose, get_verbose - -from sage.matrix.matrix2 import Matrix as Matrix2 -from .args cimport SparseEntry, MatrixArgs_init -from sage.arith.misc import is_prime - -from sage.data_structures.binary_search cimport * -from sage.modules.vector_integer_sparse cimport * - -from .matrix_integer_dense cimport Matrix_integer_dense -from sage.modules.vector_integer_dense cimport Vector_integer_dense - +from sage.rings.rational_field import QQ from sage.structure.element cimport Matrix ################ # TODO: change this to use extern cdef's methods. -from sage.rings.fast_arith cimport arith_int cdef arith_int ai ai = arith_int() ################ From 978d3185658dfd84e434f63787fc30628f4442e7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 7 Sep 2023 13:26:15 -0700 Subject: [PATCH 3/7] src/sage/libs/flint/qsieve.pyx: Remove self-cimport --- src/sage/libs/flint/qsieve.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/libs/flint/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx index 780d6f5c150..7d93d41f4cc 100644 --- a/src/sage/libs/flint/qsieve.pyx +++ b/src/sage/libs/flint/qsieve.pyx @@ -7,7 +7,6 @@ been absorbed into flint. from cysignals.signals cimport sig_on, sig_off from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz from sage.libs.flint.fmpz_factor cimport * -from sage.libs.flint.qsieve cimport * from sage.rings.integer cimport Integer From 711835fcbf821d73964f7c7c378629f06d1e3e55 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 7 Sep 2023 13:26:35 -0700 Subject: [PATCH 4/7] src/sage/graphs/base/boost_graph.pyx: Add missing doctest prompts --- src/sage/graphs/base/boost_graph.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/graphs/base/boost_graph.pyx b/src/sage/graphs/base/boost_graph.pyx index ff222837117..72e1353339e 100644 --- a/src/sage/graphs/base/boost_graph.pyx +++ b/src/sage/graphs/base/boost_graph.pyx @@ -561,7 +561,7 @@ cpdef bandwidth_heuristics(g, algorithm='cuthill_mckee'): Given a wrong algorithm:: - from sage.graphs.base.boost_graph import bandwidth_heuristics + sage: from sage.graphs.base.boost_graph import bandwidth_heuristics sage: bandwidth_heuristics(graphs.PathGraph(3), algorithm='tip top') Traceback (most recent call last): ... @@ -569,7 +569,7 @@ cpdef bandwidth_heuristics(g, algorithm='cuthill_mckee'): Given a graph with no edges:: - from sage.graphs.base.boost_graph import bandwidth_heuristics + sage: from sage.graphs.base.boost_graph import bandwidth_heuristics sage: bandwidth_heuristics(Graph()) (0, []) sage: bandwidth_heuristics(graphs.RandomGNM(10,0)) # needs networkx From c9d555d99a6f67c52c8afdaa6882c9b0df40c9cb Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 7 Sep 2023 13:27:41 -0700 Subject: [PATCH 5/7] src/sage/graphs/comparability.pyx: Remove self-import --- src/sage/graphs/comparability.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/graphs/comparability.pyx b/src/sage/graphs/comparability.pyx index 119cd892265..405b4ace2ff 100644 --- a/src/sage/graphs/comparability.pyx +++ b/src/sage/graphs/comparability.pyx @@ -677,7 +677,6 @@ def is_permutation(g, algorithm="greedy", certificate=False, check=True, ....: break """ - from sage.graphs.comparability import is_comparability if certificate: # First poset, we stop if it fails From f75277a4305553f8ca1d7442a18062e5a656b11e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 7 Sep 2023 13:28:41 -0700 Subject: [PATCH 6/7] src/sage/symbolic/expression.pyx: Remove self-import --- src/sage/symbolic/expression.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 2300c10d125..0f251ac4e5c 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -6396,7 +6396,6 @@ cdef class Expression(Expression_abc): sage: type(u._unpack_operands()[0]) <... 'tuple'> """ - from sage.symbolic.expression import unpack_operands return unpack_operands(self) def operands(self): From 1ba481b127156383c475f9f32248b38167cbbeb9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 7 Sep 2023 13:30:05 -0700 Subject: [PATCH 7/7] src/sage/graphs/strongly_regular_db.pyx: Remove self-import --- src/sage/graphs/strongly_regular_db.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/graphs/strongly_regular_db.pyx b/src/sage/graphs/strongly_regular_db.pyx index ae7eee6f4ea..8f9f37d196f 100644 --- a/src/sage/graphs/strongly_regular_db.pyx +++ b/src/sage/graphs/strongly_regular_db.pyx @@ -2649,7 +2649,6 @@ def SRG_126_50_13_24(): sage: G.is_strongly_regular(parameters=True) (126, 50, 13, 24) """ - from sage.graphs.strongly_regular_db import SRG_175_72_20_36 from sage.graphs.generators.smallgraphs import HoffmanSingletonGraph hs = HoffmanSingletonGraph() s = set(hs.vertices(sort=False)).difference(hs.neighbors(0) + [0])