From ea0d15a3d546c76a902a37c0db1d09ae54c5f3d9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 17 Oct 2020 10:00:46 -0700 Subject: [PATCH] sage.matrix: Resolve circular imports without using __init__.py --- src/sage/matrix/__init__.py | 2 -- src/sage/matrix/args.pyx | 6 +++++- src/sage/matrix/matrix_mod2_dense.pyx | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sage/matrix/__init__.py b/src/sage/matrix/__init__.py index 58b5ef12b66..e69de29bb2d 100644 --- a/src/sage/matrix/__init__.py +++ b/src/sage/matrix/__init__.py @@ -1,2 +0,0 @@ -# Resolve a cyclic import -import sage.matrix.args diff --git a/src/sage/matrix/args.pyx b/src/sage/matrix/args.pyx index bf4692ad726..82e0ba58571 100644 --- a/src/sage/matrix/args.pyx +++ b/src/sage/matrix/args.pyx @@ -20,7 +20,8 @@ from cysignals.signals cimport sig_check from cypari2.gen cimport Gen from cypari2.types cimport typ, t_MAT, t_VEC, t_COL, t_VECSMALL, t_LIST, t_STR, t_CLOSURE -from .matrix_space import MatrixSpace +MatrixSpace = None + from sage.rings.integer_ring import ZZ from sage.rings.real_double import RDF from sage.rings.complex_double import CDF @@ -931,6 +932,9 @@ cdef class MatrixArgs: self.sparse = (self.typ & MA_FLAG_SPARSE) != 0 if self.space is None: + global MatrixSpace + if MatrixSpace is None: + from .matrix_space import MatrixSpace self.space = MatrixSpace(self.base, self.nrows, self.ncols, sparse=self.sparse, **self.kwds) diff --git a/src/sage/matrix/matrix_mod2_dense.pyx b/src/sage/matrix/matrix_mod2_dense.pyx index be2ba45a5d2..faa3860907a 100644 --- a/src/sage/matrix/matrix_mod2_dense.pyx +++ b/src/sage/matrix/matrix_mod2_dense.pyx @@ -118,7 +118,7 @@ from sage.libs.gmp.random cimport * from sage.misc.randstate cimport randstate, current_randstate from sage.misc.misc import cputime from sage.misc.verbose import verbose, get_verbose -from sage.modules.free_module import VectorSpace +VectorSpace = None from sage.modules.vector_mod2_dense cimport Vector_mod2_dense from sage.structure.richcmp cimport rich_to_bool from sage.cpython.string cimport bytes_to_str, char_to_str, str_to_bytes @@ -507,6 +507,9 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse return self.rows(copy=False)[i] cdef Py_ssize_t j cdef Vector_mod2_dense z = Vector_mod2_dense.__new__(Vector_mod2_dense) + global VectorSpace + if VectorSpace is None: + from sage.modules.free_module import VectorSpace z._init(self._ncols, VectorSpace(self.base_ring(),self._ncols)) if self._ncols: mzd_submatrix(z._entries, self._entries, i, 0, i+1, self._ncols) @@ -600,6 +603,9 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) """ cdef mzd_t *tmp + global VectorSpace + if VectorSpace is None: + from sage.modules.free_module import VectorSpace VS = VectorSpace(self._base_ring, self._nrows) if not isinstance(v, Vector_mod2_dense): v = VS(v)