Skip to content

Commit

Permalink
Trac #30784: sage.matrix: Resolve circular imports without using __in…
Browse files Browse the repository at this point in the history
…it__.py

This is preparation for making `sage.matrix` a namespace package in
#28925.

URL: https://trac.sagemath.org/30784
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): François Bissey
  • Loading branch information
Release Manager committed Nov 22, 2020
2 parents 496b3f6 + ea0d15a commit 2cd4f82
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 2cd4f82

Please sign in to comment.