Skip to content

Commit 4d198fd

Browse files
author
Release Manager
committed
gh-35908: some pep8 fixes in homology/ <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description This fixes all pycodestyle warnings except `E226` in the `homology` folder. <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35908 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Matthias Köppe
2 parents e237c66 + 3dc4ac3 commit 4d198fd

20 files changed

+122
-113
lines changed

src/sage/homology/algebraic_topological_model.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from .chain_homotopy import ChainContraction
3434
from sage.rings.rational_field import QQ
3535

36+
3637
def algebraic_topological_model(K, base_ring=None):
3738
r"""
3839
Algebraic topological model for cell complex ``K``
@@ -336,6 +337,7 @@ def algebraic_topological_model(K, base_ring=None):
336337
phi = ChainContraction(phi_data, pi, iota)
337338
return phi, M
338339

340+
339341
def algebraic_topological_model_delta_complex(K, base_ring=None):
340342
r"""
341343
Algebraic topological model for cell complex ``K``
@@ -486,7 +488,7 @@ def conditionally_sparse(m):
486488
iota_cols = {}
487489
pi_cols_old = pi_cols
488490
pi_cols = []
489-
phi_old = MatrixSpace(base_ring, rank, old_rank, sparse=(base_ring==QQ)).zero()
491+
phi_old = MatrixSpace(base_ring, rank, old_rank, sparse=(base_ring == QQ)).zero()
490492
phi_old_cols = phi_old.columns()
491493
phi_old = conditionally_sparse(phi_old)
492494
to_be_deleted = []
@@ -543,8 +545,8 @@ def conditionally_sparse(m):
543545
# The matrices involved have many zero entries. For
544546
# such matrices, using sparse matrices is faster over
545547
# the rationals, slower over finite fields.
546-
phi_old = matrix(base_ring, phi_old_cols, sparse=(base_ring==QQ)).transpose()
547-
keep = vector(base_ring, pi_nrows, {i:1 for i in range(pi_nrows)
548+
phi_old = matrix(base_ring, phi_old_cols, sparse=(base_ring == QQ)).transpose()
549+
keep = vector(base_ring, pi_nrows, {i: 1 for i in range(pi_nrows)
548550
if i not in to_be_deleted})
549551
cols = [v.pairwise_product(keep) for v in pi_cols_old]
550552
pi_old = MS_pi_t.matrix(cols).transpose()

src/sage/homology/cell_complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
import sage.topology.cell_complex
1010

1111
GenericCellComplex = deprecated_function_alias(31925,
12-
sage.topology.cell_complex.GenericCellComplex)
12+
sage.topology.cell_complex.GenericCellComplex)

src/sage/homology/chain_complex.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from sage.misc.superseded import deprecation
6565
from sage.rings.fast_arith import prime_range
6666
from sage.homology.homology_group import HomologyGroup
67+
from sage.misc.persist import register_unpickle_override
6768

6869

6970
def _latex_module(R, m):
@@ -248,7 +249,7 @@ def ChainComplex(data=None, base_ring=None, grading_group=None,
248249
data_dict = {}
249250
elif isinstance(data, dict): # data is dictionary
250251
data_dict = data
251-
else: # data is list/tuple/iterable
252+
else: # data is list/tuple/iterable
252253
data_matrices = [x for x in data if isinstance(x, Matrix)]
253254
if degree != 1:
254255
raise ValueError('degree must be +1 if the data argument is a list or tuple')
@@ -667,8 +668,8 @@ def __init__(self, grading_group, degree_of_differential, base_ring, differentia
667668
sage: TestSuite(C).run()
668669
"""
669670
if any(d.base_ring() != base_ring or not d.is_immutable() or
670-
(d.ncols(), d.nrows()) == (0, 0)
671-
for d in differentials.values()):
671+
(d.ncols(), d.nrows()) == (0, 0)
672+
for d in differentials.values()):
672673
raise ValueError('invalid differentials')
673674
if degree_of_differential.parent() is not grading_group:
674675
raise ValueError('the degree_of_differential.parent() must be grading_group')
@@ -1349,15 +1350,15 @@ def change_ring(X):
13491350
d_out_nullity = d_out.ncols() - d_out_rank
13501351

13511352
if d_in.is_zero():
1352-
if generators: #Include the generators of the nullspace
1353-
return [(HomologyGroup(1, base_ring), self({deg:gen}))
1353+
if generators: # Include the generators of the nullspace
1354+
return [(HomologyGroup(1, base_ring), self({deg: gen}))
13541355
for gen in d_out.right_kernel().basis()]
13551356
else:
13561357
return HomologyGroup(d_out_nullity, base_ring)
13571358

13581359
if generators:
13591360
orders, gens = self._homology_generators_snf(d_in, d_out, d_out_rank)
1360-
answer = [(HomologyGroup(1, base_ring, [order]), self({deg:gen}))
1361+
answer = [(HomologyGroup(1, base_ring, [order]), self({deg: gen}))
13611362
for order, gen in zip(orders, gens)]
13621363
else:
13631364
if base_ring.is_field():
@@ -1552,7 +1553,7 @@ def torsion_list(self, max_prime, min_prime=2):
15521553
for i in diff_dict:
15531554
if diff_dict[i] != 0:
15541555
differences.append(i)
1555-
answer.append((p,differences))
1556+
answer.append((p, differences))
15561557
return answer
15571558

15581559
def _Hom_(self, other, category=None):
@@ -1690,7 +1691,7 @@ def _chomp_repr_(self):
16901691
deprecation(33777, "the CHomP interface is deprecated; hence so is this function")
16911692
deg = self.degree_of_differential()
16921693
if (self.grading_group() != ZZ or
1693-
(deg != 1 and deg != -1)):
1694+
(deg != 1 and deg != -1)):
16941695
raise ValueError('CHomP only works on Z-graded chain complexes with '
16951696
'differential of degree 1 or -1')
16961697
base_ring = self.base_ring()
@@ -1702,7 +1703,7 @@ def _chomp_repr_(self):
17021703
diffs = self._flip_().differential()
17031704

17041705
if len(diffs) == 0:
1705-
diffs = {0: matrix(ZZ, 0,0)}
1706+
diffs = {0: matrix(ZZ, 0, 0)}
17061707

17071708
maxdim = max(diffs)
17081709
mindim = min(diffs)
@@ -2017,7 +2018,7 @@ def cartesian_product(self, *factors, **kwds):
20172018
diffs = [D.differential() for D in factors]
20182019
keys = reduce(lambda X, d: X.union(d.keys()), diffs, set())
20192020
ret = {k: matrix.block_diagonal([d.get(k, zero) for d in diffs],
2020-
subdivide=subdivide)
2021+
subdivide=subdivide)
20212022
for k in keys}
20222023
return ChainComplex(ret, degree_of_differential=deg_diff,
20232024
grading_group=self._grading_group)
@@ -2182,32 +2183,32 @@ def scalar(a):
21822183
# Our choice for tensor products will be x # y = x1 * y + x2 * y + ...
21832184

21842185
# Generate the data for the differential
2185-
for a,r in deg:
2186-
for b,s in degD:
2186+
for a, r in deg:
2187+
for b, s in degD:
21872188
rp = d[a].nrows()
21882189
sp = dD[b].nrows()
21892190
if a+b not in diff:
21902191
diff[a+b] = {}
21912192
mor = diff[a+b]
21922193
cur = {}
2193-
cur[(a+deg_diff,b)] = []
2194-
cur[(a,b+deg_diff)] = []
2194+
cur[(a+deg_diff, b)] = []
2195+
cur[(a, b+deg_diff)] = []
21952196

21962197
for i in range(r):
21972198
for j in range(s):
21982199
# \partial x_i \otimes y_j
21992200
vec = [zero]*(rp*s)
2200-
for k,val in enumerate(d[a].column(i)):
2201+
for k, val in enumerate(d[a].column(i)):
22012202
vec[s*k+j] += val
2202-
cur[(a+deg_diff,b)].append(vec)
2203+
cur[(a+deg_diff, b)].append(vec)
22032204

22042205
# (-1)^a x_i \otimes \partial y_j
22052206
vec = [zero]*(r*sp)
2206-
for k,val in enumerate(dD[b].column(j)):
2207+
for k, val in enumerate(dD[b].column(j)):
22072208
vec[sp*i+k] += scalar(a) * val
2208-
cur[(a,b+deg_diff)].append(vec)
2209+
cur[(a, b+deg_diff)].append(vec)
22092210

2210-
mor[a,b] = cur
2211+
mor[a, b] = cur
22112212

22122213
# Parse the data into matrices
22132214
to_delete = []
@@ -2250,5 +2251,5 @@ def scalar(a):
22502251

22512252
return ret
22522253

2253-
from sage.misc.persist import register_unpickle_override
2254+
22542255
register_unpickle_override('sage.homology.chain_complex', 'ChainComplex', ChainComplex_class)

src/sage/homology/chain_complex_homspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
8787
"""
8888

89-
#*****************************************************************************
89+
# ****************************************************************************
9090
# Copyright (C) 2009 D. Benjamin Antieau <[email protected]>
9191
#
9292
# Distributed under the terms of the GNU General Public License (GPL)
@@ -100,7 +100,7 @@
100100
#
101101
# https://www.gnu.org/licenses/
102102
#
103-
#*****************************************************************************
103+
# ****************************************************************************
104104

105105
import sage.categories.homset
106106
from sage.homology.chain_complex_morphism import ChainComplexMorphism

src/sage/homology/chain_complex_morphism.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
[0 0 0]}
3636
"""
3737

38-
#*****************************************************************************
38+
# ****************************************************************************
3939
# Copyright (C) 2009 D. Benjamin Antieau <[email protected]>
4040
#
4141
# Distributed under the terms of the GNU General Public License (GPL)
@@ -49,7 +49,7 @@
4949
#
5050
# https://www.gnu.org/licenses/
5151
#
52-
#*****************************************************************************
52+
# ****************************************************************************
5353

5454
from sage.matrix.constructor import block_diagonal_matrix, zero_matrix
5555
from sage.categories.morphism import Morphism
@@ -165,8 +165,8 @@ def __init__(self, matrices, C, D, check=True):
165165
# Check sizes of matrices.
166166
for i in matrices:
167167
if (matrices[i].nrows() != D.free_module_rank(i) or
168-
matrices[i].ncols() != C.free_module_rank(i)):
169-
raise ValueError('matrix in degree {} is not the right size'.format(i))
168+
matrices[i].ncols() != C.free_module_rank(i)):
169+
raise ValueError(f'matrix in degree {i} is not the right size')
170170
# Check commutativity.
171171
for i in degrees:
172172
if i - d not in degrees:
@@ -187,7 +187,7 @@ def __init__(self, matrices, C, D, check=True):
187187
# Use immutable matrices because they're hashable.
188188
m.set_immutable()
189189
self._matrix_dictionary[i] = m
190-
Morphism.__init__(self, Hom(C,D, ChainComplexes(C.base_ring())))
190+
Morphism.__init__(self, Hom(C, D, ChainComplexes(C.base_ring())))
191191

192192
def in_degree(self, n):
193193
"""
@@ -324,7 +324,7 @@ def __neg__(self):
324324
f[i] = -self._matrix_dictionary[i]
325325
return ChainComplexMorphism(f, self.domain(), self.codomain())
326326

327-
def __add__(self,x):
327+
def __add__(self, x):
328328
"""
329329
Return ``self + x``.
330330
@@ -431,21 +431,21 @@ def __mul__(self, x):
431431
sage: g._matrix_dictionary
432432
{1: [], 2: []}
433433
"""
434-
if not isinstance(x,ChainComplexMorphism) or self.domain() != x.codomain():
434+
if not isinstance(x, ChainComplexMorphism) or self.domain() != x.codomain():
435435
try:
436436
y = self.domain().base_ring()(x)
437437
except TypeError:
438438
raise TypeError("multiplication is not defined")
439439
f = dict()
440440
for i in self._matrix_dictionary:
441441
f[i] = self._matrix_dictionary[i] * y
442-
return ChainComplexMorphism(f,self.domain(),self.codomain())
443-
f = dict()
442+
return ChainComplexMorphism(f, self.domain(), self.codomain())
443+
f = {}
444444
for i in self._matrix_dictionary:
445445
f[i] = self._matrix_dictionary[i]*x.in_degree(i)
446-
return ChainComplexMorphism(f,x.domain(),self.codomain())
446+
return ChainComplexMorphism(f, x.domain(), self.codomain())
447447

448-
def __rmul__(self,x):
448+
def __rmul__(self, x):
449449
"""
450450
Return ``x * self`` if ``x`` is an element of the base ring.
451451
@@ -465,11 +465,11 @@ def __rmul__(self,x):
465465
except TypeError:
466466
raise TypeError("multiplication is not defined")
467467
f = dict()
468-
for i in self._matrix_dictionary.keys():
468+
for i in self._matrix_dictionary:
469469
f[i] = y * self._matrix_dictionary[i]
470-
return ChainComplexMorphism(f,self.domain(),self.codomain())
470+
return ChainComplexMorphism(f, self.domain(), self.codomain())
471471

472-
def __sub__(self,x):
472+
def __sub__(self, x):
473473
"""
474474
Return ``self - x``.
475475
@@ -498,7 +498,7 @@ def __sub__(self,x):
498498
"""
499499
return self + (-x)
500500

501-
def __eq__(self,x):
501+
def __eq__(self, x):
502502
"""
503503
Return ``True`` if and only if ``self == x``.
504504
@@ -518,12 +518,12 @@ def __eq__(self,x):
518518
sage: x == y # optional - sage.graphs
519519
True
520520
"""
521-
return isinstance(x,ChainComplexMorphism) \
522-
and self.codomain() == x.codomain() \
523-
and self.domain() == x.domain() \
524-
and self._matrix_dictionary == x._matrix_dictionary
521+
return isinstance(x, ChainComplexMorphism) \
522+
and self.codomain() == x.codomain() \
523+
and self.domain() == x.domain() \
524+
and self._matrix_dictionary == x._matrix_dictionary
525525

526-
def is_identity(self):
526+
def is_identity(self) -> bool:
527527
"""
528528
Return ``True`` if this is the identity map.
529529
@@ -538,7 +538,7 @@ def is_identity(self):
538538
"""
539539
return self.to_matrix().is_one()
540540

541-
def is_surjective(self):
541+
def is_surjective(self) -> bool:
542542
"""
543543
Return ``True`` if this map is surjective.
544544

src/sage/homology/chain_homotopy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def _repr_(self):
385385
s += '\n and {}'.format('\n '.join(self._g._repr_().split('\n')))
386386
return s
387387

388+
388389
class ChainContraction(ChainHomotopy):
389390
r"""
390391
A chain contraction.

src/sage/homology/chains.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
complex.
1111
"""
1212

13-
#*****************************************************************************
13+
# ****************************************************************************
1414
# Copyright (C) 2016 Volker Braun <[email protected]>
1515
#
1616
# Distributed under the terms of the GNU General Public License (GPL)
1717
# as published by the Free Software Foundation; either version 2 of
1818
# the License, or (at your option) any later version.
19-
# http://www.gnu.org/licenses/
20-
#*****************************************************************************
19+
# https://www.gnu.org/licenses/
20+
# ****************************************************************************
2121

2222

2323
from sage.combinat.free_module import CombinatorialFreeModule
@@ -672,9 +672,9 @@ def cup_product(self, cochain):
672672
accumulator = codomain.zero()
673673
for cell in codomain.indices():
674674
for (coeff, left_cell, right_cell) in cx.alexander_whitney(cell, left_deg):
675-
if not coeff:
676-
continue
677-
left = left_chains(left_cell)
678-
right = right_chains(right_cell)
679-
accumulator += codomain(cell) * coeff * self.eval(left) * cochain.eval(right)
675+
if not coeff:
676+
continue
677+
left = left_chains(left_cell)
678+
right = right_chains(right_cell)
679+
accumulator += codomain(cell) * coeff * self.eval(left) * cochain.eval(right)
680680
return accumulator

src/sage/homology/cubical_complex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
Cube = deprecated_function_alias(31925, sage.topology.cubical_complex.Cube)
1212
CubicalComplex = deprecated_function_alias(31925,
13-
sage.topology.cubical_complex.CubicalComplex)
13+
sage.topology.cubical_complex.CubicalComplex)
1414
CubicalComplexExamples = deprecated_function_alias(31925,
15-
sage.topology.cubical_complex.CubicalComplexExamples)
15+
sage.topology.cubical_complex.CubicalComplexExamples)
1616
cubical_complexes = deprecated_function_alias(31925,
17-
sage.topology.cubical_complex.cubical_complexes)
17+
sage.topology.cubical_complex.cubical_complexes)

src/sage/homology/delta_complex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import sage.topology.delta_complex
99

1010
DeltaComplex = deprecated_function_alias(31925,
11-
sage.topology.delta_complex.DeltaComplex)
11+
sage.topology.delta_complex.DeltaComplex)
1212
DeltaComplexExamples = deprecated_function_alias(31925,
13-
sage.topology.delta_complex.DeltaComplexExamples)
13+
sage.topology.delta_complex.DeltaComplexExamples)
1414
delta_complexes = deprecated_function_alias(31925,
15-
sage.topology.delta_complex.delta_complexes)
15+
sage.topology.delta_complex.delta_complexes)

0 commit comments

Comments
 (0)