Skip to content

Commit

Permalink
sage.matrix: Resolve circular imports without using __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Oct 17, 2020
1 parent 1e728ac commit ea0d15a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/sage/matrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Resolve a cyclic import
import sage.matrix.args
6 changes: 5 additions & 1 deletion src/sage/matrix/args.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion src/sage/matrix/matrix_mod2_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ea0d15a

Please sign in to comment.