Skip to content

Commit 03f68f4

Browse files
author
Release Manager
committed
Trac #34737: less use of gap.eval in linear code
but there remains some uses in the same file URL: https://trac.sagemath.org/34737 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Kwankyu Lee
2 parents 96c4ae9 + d86dd0c commit 03f68f4

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=d0ac37033390866cb25261e906a5d89893009e1b
3-
md5=025f27345a627f6c966ca892f3cb8f9c
4-
cksum=983804627
2+
sha1=5c6eda541f708e7bbb272abbf285a492fa743128
3+
md5=b7fe25797f79a090262df39cc0a93c0c
4+
cksum=1970835260
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a74fc78822cb450592cbe86188a08ed719ecc597
1+
e063389aa995fb79f79f5e4cf2bb413f2a1e0b35

src/sage/coding/linear_code.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -586,17 +586,17 @@ def assmus_mattson_designs(self, t, mode=None):
586586
if mode=="verbose":
587587
for w in nonzerowts:
588588
print("The weight w={} codewords of C* form a t-(v,k,lambda) design, where\n \
589-
t={}, v={}, k={}, lambda={}. \nThere are {} block of this design.".format(\
590-
w,t,n,w,wts[w]*binomial(w,t)//binomial(n,t),wts[w]))
589+
t={}, v={}, k={}, lambda={}. \nThere are {} block of this design.".format(
590+
w,t,n,w,wts[w]*binomial(w,t)//binomial(n,t),wts[w]))
591591
wtsp = Cp.weight_distribution()
592592
dp = min([i for i in range(1,len(wtsp)) if wtsp[i]!=0])
593593
nonzerowtsp = [i for i in range(len(wtsp)) if wtsp[i]!=0 and i<=n-t and i>=dp]
594594
s = len([i for i in range(1,n) if wtsp[i]!=0 and i<=n-t and i>0])
595595
if mode=="verbose":
596596
for w in nonzerowtsp:
597597
print("The weight w={} codewords of C* form a t-(v,k,lambda) design, where\n \
598-
t={}, v={}, k={}, lambda={}. \nThere are {} block of this design.".format(\
599-
w,t,n,w,wts[w]*binomial(w,t)//binomial(n,t),wts[w]))
598+
t={}, v={}, k={}, lambda={}. \nThere are {} block of this design.".format(
599+
w,t,n,w,wts[w]*binomial(w,t)//binomial(n,t),wts[w]))
600600
if s<=d-t:
601601
des = [[t,(n,w,wts[w]*binomial(w,t)//binomial(n,t))] for w in nonzerowts]
602602
ans = ans + ["weights from C: ",nonzerowts,"designs from C: ",des]
@@ -1370,7 +1370,7 @@ def minimum_distance(self, algorithm=None):
13701370
# This is done only if algorithm is None.
13711371
if algorithm not in (None, "gap", "guava"):
13721372
raise ValueError("The algorithm argument must be one of None, "
1373-
"'gap' or 'guava'; got '{0}'".format(algorithm))
1373+
"'gap' or 'guava'; got '{0}'".format(algorithm))
13741374

13751375
F = self.base_ring()
13761376
q = F.order()
@@ -1380,14 +1380,14 @@ def minimum_distance(self, algorithm=None):
13801380
"of size at most 256")
13811381

13821382
G = self.generator_matrix()
1383-
if (q == 2 or q == 3) and algorithm=="guava":
1383+
if (q == 2 or q == 3) and algorithm == "guava":
13841384
gap.load_package("guava")
13851385
C = gap(G).GeneratorMatCode(gap(F))
13861386
d = C.MinimumWeight()
13871387
return ZZ(d)
13881388
return self._minimum_weight_codeword(algorithm).hamming_weight()
13891389

1390-
def _minimum_weight_codeword(self, algorithm = None):
1390+
def _minimum_weight_codeword(self, algorithm=None):
13911391
r"""
13921392
Return a minimum weight codeword of ``self``.
13931393
@@ -1431,7 +1431,7 @@ def _minimum_weight_codeword(self, algorithm = None):
14311431

14321432
current_randstate().set_seed_gap()
14331433

1434-
if algorithm=="guava":
1434+
if algorithm == "guava":
14351435
GapPackage("guava", spkg="gap_packages").require()
14361436
gap.load_package("guava")
14371437
from sage.interfaces.gap import gfq_gap_to_sage
@@ -1464,34 +1464,41 @@ def _minimum_weight_codeword(self, algorithm = None):
14641464

14651465
def module_composition_factors(self, gp):
14661466
r"""
1467-
Prints the GAP record of the Meataxe composition factors module in
1468-
Meataxe notation. This uses GAP but not Guava.
1467+
Print the GAP record of the Meataxe composition factors module.
1468+
1469+
This is displayed in Meataxe notation.
1470+
1471+
This uses GAP but not Guava.
14691472
14701473
EXAMPLES::
14711474
14721475
sage: MS = MatrixSpace(GF(2),4,8)
14731476
sage: G = MS([[1,0,0,0,1,1,1,0],[0,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,1],[0,0,0,0,0,1,0,0]])
14741477
sage: C = LinearCode(G)
14751478
sage: gp = C.permutation_automorphism_group()
1476-
1477-
Now type "C.module_composition_factors(gp)" to get the record printed.
1479+
sage: C.module_composition_factors(gp)
1480+
[ rec(
1481+
IsIrreducible := true,
1482+
IsOverFiniteField := true,
1483+
...) ]
14781484
"""
1485+
from sage.libs.gap.libgap import libgap
14791486
F = self.base_ring()
1480-
q = F.order()
14811487
gens = gp.gens()
14821488
G = self.generator_matrix()
14831489
n = len(G.columns())
1484-
MS = MatrixSpace(F,n,n)
1485-
mats = [] # initializing list of mats by which the gens act on self
1490+
MS = MatrixSpace(F, n, n)
1491+
mats = [] # initializing list of mats by which the gens act on self
14861492
Fn = VectorSpace(F, n)
1487-
W = Fn.subspace_with_basis(G.rows()) # this is self
1493+
W = Fn.subspace_with_basis(G.rows()) # this is self
14881494
for g in gens:
14891495
p = MS(g.matrix())
1490-
m = [W.coordinate_vector(r*p) for r in G.rows()]
1496+
m = [W.coordinate_vector(r * p) for r in G.rows()]
14911497
mats.append(m)
1492-
mats_str = str(gap([[list(r) for r in m] for m in mats]))
1493-
gap.eval("M:=GModuleByMats("+mats_str+", GF("+str(q)+"))")
1494-
print(gap("MTX.CompositionFactors( M )"))
1498+
mats_gap = libgap(mats)
1499+
M_gap = mats_gap.GModuleByMats(F)
1500+
compo = libgap.function_factory('MTX.CompositionFactors')
1501+
print(compo(M_gap))
14951502

14961503
def permutation_automorphism_group(self, algorithm="partition"):
14971504
r"""
@@ -1619,7 +1626,7 @@ def permutation_automorphism_group(self, algorithm="partition"):
16191626
gap.eval("matCwt:=List(Cwt,c->VectorCodeword(c))") # for each i until stop = 1)
16201627
if gap("Length(matCwt)") > 0:
16211628
A = gap("MatrixAutomorphisms(matCwt)")
1622-
G2 = gap("Intersection2(%s,%s)"%(str(A).replace("\n",""),str(Gp).replace("\n",""))) # bottleneck 3
1629+
G2 = gap("Intersection2(%s,%s)"%(str(A).replace("\n",""),str(Gp).replace("\n",""))) # bottleneck 3
16231630
Gp = G2
16241631
if Gp.Size()==1:
16251632
return PermutationGroup([()])
@@ -1830,7 +1837,7 @@ def weight_distribution(self, algorithm=None):
18301837
q = self.base_ring().order()
18311838
z = 'Z(%s)*%s'%(q, [0]*self.length()) # GAP zero vector as a string
18321839
_ = gap.eval("w:=DistancesDistributionMatFFEVecFFE("+Gmat+", GF("+str(q)+"),"+z+")")
1833-
v = [eval(gap.eval("w["+str(i)+"]")) for i in range(1,self.length()+2)] # because GAP returns vectors in compressed form
1840+
v = [eval(gap.eval("w["+str(i)+"]")) for i in range(1,self.length()+2)] # because GAP returns vectors in compressed form
18341841
return v
18351842
elif algorithm=="binary":
18361843
from sage.coding.binary_code import weight_dist
@@ -2144,7 +2151,7 @@ def e(i):
21442151
return G
21452152

21462153

2147-
############################ linear codes python class ########################
2154+
# ########################### linear codes python class ########################
21482155

21492156
class LinearCode(AbstractLinearCode):
21502157
r"""
@@ -2773,7 +2780,7 @@ def _build_lookup_table(self):
27732780
# distance 1 gracefully
27742781
zero_syndrome = vector(F,[F.zero()]*(n-k))
27752782
zero_syndrome.set_immutable()
2776-
lookup = { zero_syndrome : vector(F,[F.zero()]*n) }
2783+
lookup = {zero_syndrome: vector(F,[F.zero()]*n)}
27772784
error_position_tables = [cartesian_product([l]*i) for i in range(1, t+1)]
27782785
first_collision = True
27792786
#Filling the lookup table
@@ -2814,15 +2821,14 @@ def _build_lookup_table(self):
28142821
# Update decoder types depending on whether we are decoding beyond d/2
28152822
if self._code_minimum_distance:
28162823
if self._maximum_error_weight == (self._code_minimum_distance-1)//2:
2817-
self._decoder_type.update({"minimum-distance","always-succeed"})
2824+
self._decoder_type.update({"minimum-distance", "always-succeed"})
28182825
else:
28192826
# then t > (d-1)/2
28202827
self._decoder_type.add("might-error")
28212828
else:
28222829
self._decoder_type.add("always-succeed")
28232830
return lookup
28242831

2825-
28262832
def decode_to_code(self, r):
28272833
r"""
28282834
Corrects the errors in ``word`` and returns a codeword.

0 commit comments

Comments
 (0)