Skip to content

Commit a3e85a1

Browse files
committed
src/sage/graphs/generators: speed up Golay code graph construction
Reimplement shortened_000_111_extended_binary_Golay_code_graph() to load its vertices and edges from compressed, pickled data. This speeds up the construction significantly, and eliminates a persistent CI warning about the corresponding test being slow.
1 parent 2d5895b commit a3e85a1

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/sage/graphs/generators/distance_regular.pyx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -487,35 +487,46 @@ def shortened_000_111_extended_binary_Golay_code_graph():
487487
488488
EXAMPLES::
489489
490-
sage: # long time, needs sage.modules sage.rings.finite_rings
491-
sage: G = graphs.shortened_000_111_extended_binary_Golay_code_graph() # 25 s
490+
sage: # needs sage.modules sage.rings.finite_rings
491+
sage: G = graphs.shortened_000_111_extended_binary_Golay_code_graph()
492492
sage: G.is_distance_regular(True)
493493
([21, 20, 16, 9, 2, 1, None], [None, 1, 2, 3, 16, 20, 21])
494494
495495
ALGORITHM:
496496
497-
Compute the extended binary Golay code. Compute its subcode whose codewords
498-
start with 000 or 111. Remove the first 3 entries from all the codewords
499-
from the new linear code and compute its coset graph.
497+
The vertices and edges of this graph have been precomputed and
498+
pickled, so truthfully, we just unpickle them and pass them to the
499+
Graph constructor. But the algorithm used to compute those
500+
vertices and edges in the first place is,
501+
502+
#. Compute the extended binary Golay code.
503+
#. Compute its subcode whose codewords start with 000 or 111.
504+
#. Remove the first 3 entries from all the codewords from the
505+
new linear code and compute its coset graph.
506+
507+
This construction is tested in ``generators_test.py``, where the
508+
result is compared (up to isomorphism) with the result from this
509+
method.
500510
501511
REFERENCES:
502512
503-
Description and construction of this graph can be found in [BCN1989]_ p. 365.
513+
The description and construction of this graph can be found in
514+
[BCN1989]_, page 365.
504515
"""
505-
from sage.coding.linear_code import LinearCode
516+
import lzma
517+
from importlib.resources import as_file, files
518+
from pickle import load
506519

507-
code = codes.GolayCode(GF(2))
508-
C_basis = code.basis()
520+
# Path to the pickled-and-xz'd list of (vertices, edges)
521+
ppath = files('sage.graphs.generators').joinpath(
522+
"shortened_000_111_extended_binary_Golay_code_graph.pickle.xz"
523+
)
509524

510-
# now special shortening
511-
v = C_basis[0] + C_basis[1] + C_basis[2] # v has 111 at the start
512-
C_basis = C_basis[3:]
513-
C_basis.append(v)
514-
C_basis = list(map(lambda x: x[3:], C_basis))
525+
with as_file(ppath) as p:
526+
with lzma.open(p) as f:
527+
vs_and_es = load(f, fix_imports=False)
515528

516-
code = LinearCode(Matrix(GF(2), C_basis))
517-
518-
G = code.cosetGraph()
529+
G = Graph(vs_and_es, format='vertices_and_edges')
519530
G.name("Shortened 000 111 extended binary Golay code")
520531
return G
521532

0 commit comments

Comments
 (0)