Skip to content

Commit 45e98cb

Browse files
author
Release Manager
committed
gh-35263: `sage.topology`: Move imports from `sage.graphs`, `sage.homology` into methods <!-- ^^^^^ 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" --> ### 📚 Description Part of: - #29705 <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 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! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35263 Reported by: Matthias Köppe Reviewer(s): David Coudert
2 parents 65c89ec + 8d79ca8 commit 45e98cb

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

src/sage/topology/cubical_complex.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@
7474
from sage.rings.integer_ring import ZZ
7575
from sage.rings.rational_field import QQ
7676
from sage.matrix.constructor import matrix
77-
from sage.homology.chain_complex import ChainComplex
78-
from sage.graphs.graph import Graph
7977
from sage.misc.cachefunc import cached_method
8078
from sage.misc.superseded import deprecation
8179
from functools import total_ordering
@@ -1192,6 +1190,8 @@ def chain_complex(self, subcomplex=None, augmented=False,
11921190
sage: Square.homology(subcomplex=EdgesLTR)[2] == Square.homology(subcomplex=EdgesLBR)[2]
11931191
True
11941192
"""
1193+
from sage.homology.chain_complex import ChainComplex
1194+
11951195
# initialize subcomplex
11961196
if subcomplex is None:
11971197
subcomplex = CubicalComplex()
@@ -1333,6 +1333,8 @@ def graph(self):
13331333
sage: cubical_complexes.Sphere(2).graph()
13341334
Graph on 8 vertices
13351335
"""
1336+
from sage.graphs.graph import Graph
1337+
13361338
data = {}
13371339
vertex_dict = {}
13381340
i = 0

src/sage/topology/delta_complex.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@
5151

5252
from copy import copy
5353
from sage.topology.cell_complex import GenericCellComplex
54-
from sage.homology.chains import Chains, Cochains
5554
from sage.rings.integer_ring import ZZ
5655
from sage.rings.rational_field import QQ
5756
from sage.rings.integer import Integer
5857
from sage.matrix.constructor import matrix
5958
from .simplicial_complex import Simplex, lattice_paths, SimplicialComplex
60-
from sage.homology.chain_complex import ChainComplex
61-
from sage.graphs.graph import Graph
6259
from sage.arith.misc import binomial
6360
from sage.misc.cachefunc import cached_method
6461

@@ -630,6 +627,8 @@ def chain_complex(self, subcomplex=None, augmented=False,
630627
sage: T.homology(subcomplex=A)
631628
{0: 0, 1: 0, 2: Z}
632629
"""
630+
from sage.homology.chain_complex import ChainComplex
631+
633632
if subcomplex is not None:
634633
# relative chain complex, so don't augment the chain complex
635634
augmented = False
@@ -776,6 +775,8 @@ def graph(self):
776775
sage: delta_complexes.Simplex(4).graph() == graphs.CompleteGraph(5)
777776
True
778777
"""
778+
from sage.graphs.graph import Graph
779+
779780
data = {}
780781
for vertex in range(len(self.n_cells(0))):
781782
data[vertex] = []
@@ -1523,6 +1524,8 @@ def n_chains(self, n, base_ring=None, cochains=False):
15231524
sage: list(T.n_chains(1, QQ, cochains=True).basis())
15241525
[\chi_(0, (0, 0)), \chi_(1, (0, 0)), \chi_(2, (0, 0))]
15251526
"""
1527+
from sage.homology.chains import Chains, Cochains
1528+
15261529
n_cells = tuple(enumerate(self.n_cells(n)))
15271530
if cochains:
15281531
return Cochains(self, n, n_cells, base_ring)

src/sage/topology/simplicial_complex_morphism.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@
102102
#
103103
# ****************************************************************************
104104

105-
from .simplicial_complex import Simplex, SimplicialComplex
106-
from sage.matrix.constructor import matrix, zero_matrix
107-
from sage.rings.integer_ring import ZZ
108-
from sage.homology.chain_complex_morphism import ChainComplexMorphism
109-
from sage.combinat.permutation import Permutation
110-
from sage.algebras.steenrod.steenrod_algebra_misc import convert_perm
111-
from sage.categories.morphism import Morphism
112105
from sage.categories.homset import Hom
106+
from sage.categories.morphism import Morphism
113107
from sage.categories.simplicial_complexes import SimplicialComplexes
108+
from sage.matrix.constructor import matrix, zero_matrix
109+
from sage.rings.integer_ring import ZZ
110+
111+
from .simplicial_complex import Simplex, SimplicialComplex
114112

115113

116114
def is_SimplicialComplexMorphism(x):
@@ -252,6 +250,9 @@ def __call__(self,x,orientation=False):
252250
for j in tup:
253251
fx.append(self._vertex_dictionary[j])
254252
if orientation:
253+
from sage.algebras.steenrod.steenrod_algebra_misc import convert_perm
254+
from sage.combinat.permutation import Permutation
255+
255256
if len(set(fx)) == len(tup):
256257
oriented = Permutation(convert_perm(fx)).signature()
257258
else:
@@ -371,6 +372,8 @@ def associated_chain_complex_morphism(self,base_ring=ZZ,augmented=False,cochain=
371372
{0: [0 1]
372373
[1 0], 1: [-1]}
373374
"""
375+
from sage.homology.chain_complex_morphism import ChainComplexMorphism
376+
374377
max_dim = max(self.domain().dimension(),self.codomain().dimension())
375378
min_dim = min(self.domain().dimension(),self.codomain().dimension())
376379
matrices = {}

src/sage/topology/simplicial_set.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@
254254

255255
import copy
256256

257-
from sage.graphs.graph import Graph
258257
from sage.matrix.constructor import matrix
259258
from sage.misc.cachefunc import cached_method
260259
from sage.misc.fast_methods import WithEqualityById
@@ -263,9 +262,6 @@
263262
from sage.rings.rational_field import QQ
264263
from sage.structure.parent import Parent
265264
from sage.structure.sage_object import SageObject
266-
from sage.homology.algebraic_topological_model import algebraic_topological_model_delta_complex
267-
from sage.homology.chain_complex import ChainComplex
268-
from sage.homology.chains import Chains, Cochains
269265

270266
from .cell_complex import GenericCellComplex
271267
from .delta_complex import DeltaComplex
@@ -1686,6 +1682,8 @@ def graph(self):
16861682
sage: Sigma3.nerve().is_connected()
16871683
True
16881684
"""
1685+
from sage.graphs.graph import Graph
1686+
16891687
G = Graph(loops=True, multiedges=True)
16901688
for e in self.n_cells(1):
16911689
G.add_edge(self.face(e,0), self.face(e,1), e)
@@ -2153,6 +2151,9 @@ def n_chains(self, n, base_ring=ZZ, cochains=False):
21532151
return GenericCellComplex.n_chains(self, n=n,
21542152
base_ring=base_ring,
21552153
cochains=cochains)
2154+
2155+
from sage.homology.chains import Chains, Cochains
2156+
21562157
n_cells = tuple(self.n_cells(n))
21572158
if cochains:
21582159
return Cochains(self, n, n_cells, base_ring)
@@ -3634,6 +3635,8 @@ def chain_complex(self, dimensions=None, base_ring=ZZ, augmented=False,
36343635
sage: RP2.cohomology(base_ring=GF(2)) == SimplicialSet(RP2).cohomology(base_ring=GF(2))
36353636
True
36363637
"""
3638+
from sage.homology.chain_complex import ChainComplex
3639+
36373640
if dimensions is None:
36383641
if not self.cells(): # Empty
36393642
if cochain:
@@ -3782,6 +3785,8 @@ def algebraic_topological_model(self, base_ring=None):
37823785
1: Vector space of dimension 2 over Rational Field,
37833786
2: Vector space of dimension 1 over Rational Field}
37843787
"""
3788+
from sage.homology.algebraic_topological_model import algebraic_topological_model_delta_complex
3789+
37853790
if base_ring is None:
37863791
base_ring = QQ
37873792
return algebraic_topological_model_delta_complex(self, base_ring)

src/sage/topology/simplicial_set_constructions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474

7575
import itertools
7676

77-
from sage.graphs.graph import Graph
7877
from sage.misc.latex import latex
7978
from sage.sets.set import Set
8079
from sage.structure.parent import Parent
@@ -1417,6 +1416,8 @@ def __init__(self, maps=None, vertex_name=None):
14171416
sage: PushoutOfSimplicialSets_finite([T.base_point_map(), S2.base_point_map()], vertex_name='v').n_cells(0)[0]
14181417
v
14191418
"""
1419+
from sage.graphs.graph import Graph
1420+
14201421
# Import this here to prevent circular imports.
14211422
from sage.topology.simplicial_set_morphism import SimplicialSetMorphism
14221423
if maps and any(not isinstance(f, SimplicialSetMorphism) for f in maps):

src/sage/topology/simplicial_set_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from pyparsing import OneOrMore, nestedExpr
3535

3636
from sage.env import SAGE_ENV
37-
from sage.groups.abelian_gps.abelian_group import AbelianGroup
3837
from sage.misc.cachefunc import cached_method, cached_function
3938
from sage.misc.latex import latex
4039
from sage.rings.infinity import Infinity
@@ -363,6 +362,8 @@ def RealProjectiveSpace(n):
363362
RP^{\infty}
364363
"""
365364
if n == Infinity:
365+
from sage.groups.abelian_gps.abelian_group import AbelianGroup
366+
366367
X = AbelianGroup([2]).nerve()
367368
X.rename('RP^oo')
368369
X.rename_latex('RP^{\\infty}')

src/sage/topology/simplicial_set_morphism.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
from sage.misc.latex import latex
4040
from sage.rings.integer_ring import ZZ
4141

42-
from sage.homology.chain_complex_morphism import ChainComplexMorphism
43-
from sage.homology.homology_morphism import InducedHomologyMorphism
4442
from .simplicial_set import SimplicialSet_arbitrary
4543

4644
class SimplicialSetHomset(Homset):
@@ -1312,6 +1310,8 @@ def associated_chain_complex_morphism(self, base_ring=ZZ,
13121310
[-+-]
13131311
[0|0]
13141312
"""
1313+
from sage.homology.chain_complex_morphism import ChainComplexMorphism
1314+
13151315
# One or the other chain complex is trivial between these
13161316
# dimensions:
13171317
max_dim = max(self.domain().dimension(), self.codomain().dimension())
@@ -1394,6 +1394,8 @@ def induced_homology_morphism(self, base_ring=None, cohomology=False):
13941394
[-+-]
13951395
[0|2]
13961396
"""
1397+
from sage.homology.homology_morphism import InducedHomologyMorphism
1398+
13971399
return InducedHomologyMorphism(self, base_ring, cohomology)
13981400

13991401
def _repr_type(self):

0 commit comments

Comments
 (0)