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

Commit 2cc4c72

Browse files
committed
Reverted base_field and length to be only in linear_code.py
1 parent f4767e0 commit 2cc4c72

File tree

2 files changed

+80
-32
lines changed

2 files changed

+80
-32
lines changed

src/sage/coding/abstract_code.py

+55-32
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,63 @@
66
77
Any class inheriting from AbstractCode can use the encode/decode framework.
88
"""
9+
#TODO: imports
10+
from sage.modules.module import Module
911

1012
#TODO: credits?
11-
#TODO: is module the correct thing?
12-
class AbstractCode(module):
13-
14-
def __init__(self, base_field, length, default_encoder_name, \
15-
default_decoder_name, metric='Hamming'):
16-
13+
#TODO: is Module the correct thing?
14+
15+
def _explain_constructor(cl):
16+
r"""
17+
Internal function for use error messages when constructing encoders and decoders.
18+
19+
EXAMPLES::
20+
21+
sage: from sage.coding.linear_code import _explain_constructor, LinearCodeSyndromeDecoder
22+
sage: cl = LinearCodeSyndromeDecoder
23+
sage: _explain_constructor(cl)
24+
"The constructor requires no arguments.\nIt takes the optional arguments ['maximum_error_weight'].\nSee the documentation of sage.coding.linear_code.LinearCodeSyndromeDecoder for more details."
25+
26+
sage: from sage.coding.information_set_decoder import LinearCodeInformationSetDecoder
27+
sage: cl = LinearCodeInformationSetDecoder
28+
sage: _explain_constructor(cl)
29+
"The constructor requires the arguments ['number_errors'].\nIt takes the optional arguments ['algorithm'].\nIt accepts unspecified arguments as well.\nSee the documentation of sage.coding.information_set_decoder.LinearCodeInformationSetDecoder for more details."
30+
"""
31+
if inspect.isclass(cl):
32+
argspec = sage_getargspec(cl.__init__)
33+
skip = 2 # skip the self and code arguments
34+
else:
35+
# Not a class, assume it's a factory function posing as a class
36+
argspec = sage_getargspec(cl)
37+
skip = 1 # skip code argument
38+
if argspec.defaults:
39+
args = argspec.args[skip:-len(argspec.defaults)]
40+
kwargs = argspec.args[-len(argspec.defaults):]
41+
opts = "It takes the optional arguments {}.".format(kwargs)
42+
else:
43+
args = argspec.args[skip:]
44+
opts = "It takes no optional arguments."
45+
if args:
46+
reqs = "The constructor requires the arguments {}.".format(args)
47+
else:
48+
reqs = "The constructor requires no arguments."
49+
if argspec.varargs or argspec.keywords:
50+
var = "It accepts unspecified arguments as well.\n"
51+
else:
52+
var = ""
53+
return("{}\n{}\n{}See the documentation of {}.{} for more details."\
54+
.format(reqs, opts, var, cl.__module__, cl.__name__))
55+
56+
57+
class AbstractCode(Module):
58+
59+
def __init__(self, default_encoder_name, default_decoder_name, metric='Hamming'):
1760
"""
1861
"""
62+
_registered_encoders = {}
63+
_registered_decoders = {}
64+
65+
self._metric = metric
1966

2067
def __getstate__(self):
2168
"""
@@ -122,31 +169,6 @@ def _latex_(self):
122169
"""
123170
raise RuntimeError("Please override _latex_ in the implementation of {}".format(self.parent()))
124171

125-
def base_field(self):
126-
r"""
127-
Return the base field of ``self``.
128-
129-
EXAMPLES::
130-
131-
sage: G = Matrix(GF(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]])
132-
sage: C = LinearCode(G)
133-
sage: C.base_field()
134-
Finite Field of size 2
135-
"""
136-
return self.base_ring()
137-
138-
def length(self):
139-
r"""
140-
Returns the length of this code.
141-
142-
EXAMPLES::
143-
144-
sage: C = codes.HammingCode(GF(2), 3)
145-
sage: C.length()
146-
7
147-
"""
148-
return self._length
149-
150172
def list(self):
151173
r"""
152174
Return a list of all elements of this linear code.
@@ -173,7 +195,8 @@ def metric(self):
173195
"""
174196
return self._metric
175197

176-
#Encoding/decoding stuff
198+
###################### Encoding-Decoding #######################################
199+
177200
def add_decoder(self, name, decoder):
178201
r"""
179202
Adds an decoder to the list of registered decoders of ``self``.

src/sage/coding/linear_code.py

+25
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,19 @@ def assmus_mattson_designs(self, t, mode=None):
704704
return ans
705705
return 0
706706

707+
def base_field(self):
708+
r"""
709+
Return the base field of ``self``.
710+
711+
EXAMPLES::
712+
713+
sage: G = Matrix(GF(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]])
714+
sage: C = LinearCode(G)
715+
sage: C.base_field()
716+
Finite Field of size 2
717+
"""
718+
return self.base_ring()
719+
707720
def basis(self):
708721
r"""
709722
Returns a basis of `self`.
@@ -1874,6 +1887,18 @@ def cardinality(self):
18741887

18751888
__len__ = cardinality
18761889

1890+
def length(self):
1891+
r"""
1892+
Returns the length of this code.
1893+
1894+
EXAMPLES::
1895+
1896+
sage: C = codes.HammingCode(GF(2), 3)
1897+
sage: C.length()
1898+
7
1899+
"""
1900+
return self._length
1901+
18771902
def _magma_init_(self, magma):
18781903
r"""
18791904
Retun a string representation in Magma of this linear code.

0 commit comments

Comments
 (0)