Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 9e0a265

Browse files
Release Managervbraun
authored andcommitted
Trac #20565: Fix LinearCode.wtdist_gap method
There are three main issues with the `wtdist_gap` method namely: 1) Name of the method 2) Poor documentation 3) It should be a private function URL: http://trac.sagemath.org/20565 Reported by: arpitdm Ticket author(s): Arpit Merchant Reviewer(s): David Lucas
2 parents ecfddf2 + 191d1c4 commit 9e0a265

File tree

1 file changed

+40
-43
lines changed

1 file changed

+40
-43
lines changed

src/sage/coding/linear_code.py

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -269,45 +269,12 @@ def code2leon(C):
269269
return file_loc
270270

271271
def wtdist_gap(Gmat, n, F):
272-
r"""
273-
INPUT:
274-
275-
- ``Gmat`` - String representing a GAP generator matrix G of a linear code
276-
277-
- ``n`` - Integer greater than 1, representing the number of columns of G
278-
(i.e., the length of the linear code)
279-
280-
- ``F`` - Finite field (in Sage), base field the code
281-
282-
OUTPUT:
283-
284-
- Spectrum of the associated code
285-
286-
EXAMPLES::
287-
288-
sage: Gstr = 'Z(2)*[[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]'
289-
sage: F = GF(2)
290-
sage: sage.coding.linear_code.wtdist_gap(Gstr, 7, F)
291-
[1, 0, 0, 7, 7, 0, 0, 1]
292-
293-
Here ``Gstr`` is a generator matrix of the Hamming [7,4,3] binary code.
294-
295-
ALGORITHM:
296-
297-
Uses C programs written by Steve Linton in the kernel of GAP, so is fairly
298-
fast.
299-
300-
AUTHORS:
301-
302-
- David Joyner (2005-11)
303-
"""
304-
G = gap(Gmat)
305-
q = F.order()
306-
k = gap(F)
307-
z = 'Z(%s)*%s'%(q, [0]*n) # GAP zero vector as a string
308-
_ = gap.eval("w:=DistancesDistributionMatFFEVecFFE("+Gmat+", GF("+str(q)+"),"+z+")")
309-
v = [eval(gap.eval("w["+str(i)+"]")) for i in range(1,n+2)] # because GAP returns vectors in compressed form
310-
return v
272+
from sage.misc.superseded import deprecation
273+
deprecation(20565, "wtdist_gap is now deprecated. Please use AbstractLinearCode._spectrum_from_gap instead.")
274+
G_gap = gap(Gmat)
275+
G = G_gap._matrix_(F)
276+
C = LinearCode(G)
277+
return C._spectrum_from_gap()
311278

312279
def min_wt_vec_gap(Gmat, n, k, F, algorithm=None):
313280
r"""
@@ -3214,6 +3181,38 @@ def shortened(self, L):
32143181
Cdp = Cd.punctured(set(L))
32153182
return Cdp.dual_code()
32163183

3184+
def _spectrum_from_gap(self):
3185+
r"""
3186+
Returns the weight distribution of the associated code. Uses the C programs
3187+
available in the kernel of GAP and thus is fairly fast.
3188+
3189+
The weight distribution of a code of length `n` is the sequence `A_0, A_1,..., A_n`
3190+
where `A_i` is the number of codewords of weight `i` (0 <= i <= n).
3191+
3192+
OUTPUT:
3193+
- a vector of integers, the weight distribution of the code
3194+
3195+
EXAMPLES::
3196+
sage: from sage.interfaces.all import gap
3197+
sage: MS = MatrixSpace(GF(2),4,7)
3198+
sage: G = MS([[1,1,1,0,0,0,0],[1,0,0,1,1,0,0],[0,1,0,1,0,1,0],[1,1,0,1,0,0,1]])
3199+
sage: C = LinearCode(G)
3200+
sage: C._spectrum_from_gap()
3201+
[1, 0, 0, 7, 7, 0, 0, 1]
3202+
3203+
AUTHORS:
3204+
3205+
- David Joyner (2005-11)
3206+
"""
3207+
Gmat = self.generator_matrix()._gap_init_()
3208+
G = gap(Gmat)
3209+
q = self.base_ring().order()
3210+
k = gap(self.base_ring())
3211+
z = 'Z(%s)*%s'%(q, [0]*self.length()) # GAP zero vector as a string
3212+
_ = gap.eval("w:=DistancesDistributionMatFFEVecFFE("+Gmat+", GF("+str(q)+"),"+z+")")
3213+
v = [eval(gap.eval("w["+str(i)+"]")) for i in range(1,self.length()+2)] # because GAP returns vectors in compressed form
3214+
return v
3215+
32173216
def spectrum(self, algorithm=None):
32183217
r"""
32193218
Returns the spectrum of ``self`` as a list.
@@ -3275,13 +3274,11 @@ def spectrum(self, algorithm=None):
32753274
algorithm = "binary"
32763275
else:
32773276
algorithm = "gap"
3278-
n = self.length()
32793277
F = self.base_ring()
3278+
n = self.length()
32803279
G = self.generator_matrix()
32813280
if algorithm=="gap":
3282-
Gstr = G._gap_init_()
3283-
spec = wtdist_gap(Gstr,n,F)
3284-
return spec
3281+
return self._spectrum_from_gap()
32853282
elif algorithm=="binary":
32863283
from sage.coding.binary_code import weight_dist
32873284
return weight_dist(self.generator_matrix())

0 commit comments

Comments
 (0)