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

Commit ee33302

Browse files
author
David Lucas
committedSep 2, 2015
Propaged comments got from #18376
1 parent f286a64 commit ee33302

File tree

2 files changed

+37
-47
lines changed

2 files changed

+37
-47
lines changed
 

‎src/sage/coding/decoder.py

+7-27
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,11 @@ class Decoder(SageObject):
2828
2929
Every decoder class should inherit from this abstract class.
3030
31-
This class provides:
32-
33-
- ``code``, the associated code of the decoder
34-
35-
- ``input_space``, the space of every input for the decoder
36-
37-
- ``connected_encoder_name``, the name of the encoder used to recover the original message
38-
from the word to decode
39-
40-
- ``decoder_type``, a set of keywords which describe the behaviour of the decoder.
41-
42-
- some methods for decoder objects
43-
4431
To implement an decoder, you need to:
4532
4633
- inherit from :class:`Decoder`
4734
48-
- call :class:`Decoder`'s :meth:`__init__` in the subclass constructor.
35+
- call ``Decoder.__init__`` in the subclass constructor.
4936
Example: ``super(SubclassName, self).__init__(code, input_space,
5037
connected_encoder_name, decoder_type)``.
5138
By doing that, your subclass will have all the parameters described above initialized.
@@ -61,13 +48,6 @@ class Decoder(SageObject):
6148
6249
As :class:`Decoder` is not designed to be implemented, it does not have any representation
6350
methods. You should implement ``_repr_`` and ``_latex_`` methods in the sublclass.
64-
65-
.. NOTE::
66-
67-
For consistency on decoders, please follow this convention on names for subclasses:
68-
for a new decoder named ``DecName``, for code family ``CodeFam``, call it
69-
``CodeFamDecNameDecoder``.
70-
7151
"""
7252

7353
def __init__(self, code, input_space, connected_encoder_name,\
@@ -145,7 +125,7 @@ def decode_to_code(self, r):
145125
Corrects the errors in ``r`` and returns a codeword.
146126
147127
This is a default implementation which assumes that the method
148-
:meth:`decode_to_message()` has been implemented, else it returns an exception.
128+
:meth:`decode_to_message` has been implemented, else it returns an exception.
149129
150130
INPUT:
151131
@@ -187,10 +167,10 @@ def connected_encoder(self):
187167

188168
def decode_to_message(self, r):
189169
r"""
190-
Decodes ``r`` to the message space of ``self.code()``.
170+
Decodes ``r`` to the message space of meth:`code`.
191171
192172
This is a default implementation, which assumes that the method
193-
:meth:`decode_to_code()` has been implemented, else it returns an exception.
173+
:meth:`decode_to_code` has been implemented, else it returns an exception.
194174
195175
EXAMPLES::
196176
@@ -207,7 +187,7 @@ def decode_to_message(self, r):
207187

208188
def code(self):
209189
r"""
210-
Returns the code in which ``self.decode_to_code()`` has its output.
190+
Returns the code in which :meth:`decode_to_code` has its output.
211191
212192
EXAMPLES::
213193
@@ -259,8 +239,8 @@ def decoding_radius(self, **kwargs):
259239
"""
260240
raise NotImplementedError
261241

262-
class DecodingFailure(Exception):
242+
class DecodingError(Exception):
263243
r"""
264-
Special exception class to indicate a failure during decoding.
244+
Special exception class to indicate an error during decoding.
265245
"""
266246
pass

‎src/sage/coding/linear_code.py

+30-20
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ class AbstractLinearCode(module.Module):
714714
715715
- ``length``, the length of the code
716716
717-
- ``decoder_default_name``, the name of the decoder that will be used if no encoder name is passed
717+
- ``default_decoder_name``, the name of the decoder that will be used if no encoder name is passed
718718
to an encoder-related method (``decode_to_code``, ``decode_to_message``)
719719
720720
- ``_registered_decoders``, a dictionary of all decoders available for this class
@@ -754,7 +754,7 @@ class AbstractLinearCode(module.Module):
754754

755755
_registered_decoders = {}
756756

757-
def __init__(self, base_field, length, decoder_default_name):
757+
def __init__(self, base_field, length, default_decoder_name):
758758
"""
759759
Initializes mandatory parameters for a Linear Code object.
760760
@@ -768,7 +768,7 @@ def __init__(self, base_field, length, decoder_default_name):
768768
769769
- ``length`` -- the length of ``self``
770770
771-
- ``decoder_default_name`` -- the name of the default decoder of ``self``
771+
- ``default_decoder_name`` -- the name of the default decoder of ``self``
772772
773773
EXAMPLES:
774774
@@ -842,10 +842,10 @@ def __init__(self, base_field, length, decoder_default_name):
842842
self._registered_decoders = copy(self._registered_decoders)
843843
if not isinstance(length, (int, Integer)):
844844
raise ValueError("length must be a Python int or a Sage Integer")
845-
if not decoder_default_name in self._registered_decoders:
845+
if not default_decoder_name in self._registered_decoders:
846846
raise ValueError("You must set a valid decoder as default decoder for this code")
847847
self._length = Integer(length)
848-
self._decoder_default_name = decoder_default_name
848+
self._default_decoder_name = default_decoder_name
849849
cat = Modules(base_field).FiniteDimensional().WithBasis().Finite()
850850
facade_for = VectorSpace(base_field, self._length)
851851
self.Element = type(facade_for.an_element()) #for when we made this a non-facade parent
@@ -929,7 +929,7 @@ def add_decoder(self, name, decoder):
929929
ValueError: There is already a registered decoder with this name
930930
"""
931931
reg_dec = self._registered_decoders
932-
if(name in reg_dec.keys()):
932+
if(name in reg_dec):
933933
raise ValueError("There is already a registered decoder with this name")
934934
reg_dec[name] = decoder
935935

@@ -1503,7 +1503,7 @@ def decode(self, right, algorithm="syndrome"):
15031503
else:
15041504
return self.decode_to_code(right, name=algorithm)
15051505

1506-
def decode_to_code(self, word, name=None, **kwargs):
1506+
def decode_to_code(self, word, decoder_name=None, **kwargs):
15071507
r"""
15081508
Correct the errors in word and returns a codeword.
15091509
@@ -1512,10 +1512,12 @@ def decode_to_code(self, word, name=None, **kwargs):
15121512
- ``word`` -- a vector of the same length as ``self`` over test
15131513
the base field of ``self``
15141514
1515-
- ``name`` -- (default: ``None``) Name of the decoder which will be used
1515+
- ``decoder_name`` -- (default: ``None``) Name of the decoder which will be used
15161516
to decode ``word``. The default decoder of ``self`` will be used if
15171517
default value is kept.
15181518
1519+
- ``kwargs`` -- all additional arguments are forwarded to :meth:`decoder`
1520+
15191521
OUTPUT:
15201522
15211523
- A vector of ``self``.
@@ -1539,7 +1541,7 @@ def decode_to_code(self, word, name=None, **kwargs):
15391541
D = self.decoder(name, **kwargs)
15401542
return D.decode_to_code(word)
15411543

1542-
def decode_to_message(self, word, name=None, **kwargs):
1544+
def decode_to_message(self, word, decoder_name=None, **kwargs):
15431545
r"""
15441546
Correct the errors in word and decodes it to the message space.
15451547
@@ -1548,10 +1550,12 @@ def decode_to_message(self, word, name=None, **kwargs):
15481550
- ``word`` -- a vector of the same length as ``self`` over the
15491551
base field of ``self``
15501552
1551-
- ``name`` -- (default: ``None``) Name of the decoder which will be used
1553+
- ``decoder_name`` -- (default: ``None``) Name of the decoder which will be used
15521554
to decode ``word``. The default decoder of ``self`` will be used if
15531555
default value is kept.
15541556
1557+
- ``kwargs`` -- all additional arguments are forwarded to :meth:`decoder`
1558+
15551559
OUTPUT:
15561560
15571561
- A vector of the message space of ``self``.
@@ -1574,16 +1578,19 @@ def decode_to_message(self, word, name=None, **kwargs):
15741578
return self.unencode(self.decode_to_code(word, name, **kwargs), **kwargs)
15751579

15761580
@cached_method
1577-
def decoder(self, name=None, **kwargs):
1581+
def decoder(self, decoder_name=None, **kwargs):
15781582
r"""
15791583
Return a decoder of ``self``.
15801584
15811585
INPUT:
15821586
1583-
- ``name`` -- (default: ``None``) name of the decoder which will be
1587+
- ``decoder_name`` -- (default: ``None``) name of the decoder which will be
15841588
returned. The default decoder of ``self`` will be used if
15851589
default value is kept.
15861590
1591+
- ``kwargs`` -- all additional arguments will be forwarded to the constructor of the decoder
1592+
that will be returned by this method
1593+
15871594
OUTPUT:
15881595
15891596
- a decoder object
@@ -1609,11 +1616,11 @@ def decoder(self, name=None, **kwargs):
16091616
...
16101617
ValueError: Passed Decoder name not known
16111618
"""
1612-
if name is None:
1613-
name = self._decoder_default_name
1614-
return self.decoder(name, **kwargs)
1615-
if name in self._registered_decoders:
1616-
decClass = self._registered_decoders[name]
1619+
if decoder_name is None:
1620+
name = self._default_decoder_name
1621+
return self.decoder(decoder_name, **kwargs)
1622+
if decoder_name in self._registered_decoders:
1623+
decClass = self._registered_decoders[decoder_name]
16171624
D = decClass(self, **kwargs)
16181625
return D
16191626
else:
@@ -1630,7 +1637,10 @@ def decoders_available(self):
16301637
sage: C.decoders_available()
16311638
['Syndrome', 'NearestNeighbor']
16321639
"""
1640+
if values == True:
1641+
return copy(self._registered_decoders)
16331642
return self._registered_decoders.keys()
1643+
16341644
def divisor(self):
16351645
r"""
16361646
Returns the divisor of a code, which is the smallest integer `d_0 > 0`
@@ -2538,7 +2548,7 @@ def permutation_automorphism_group(self, algorithm="partition"):
25382548
print "\n Using the %s codewords of weight %s \n Supergroup size: \n %s\n "%(wts[wt],wt,size)
25392549
gap.eval("Cwt:=Filtered(eltsC,c->WeightCodeword(c)=%s)"%wt) # bottleneck 2 (repeated
25402550
gap.eval("matCwt:=List(Cwt,c->VectorCodeword(c))") # for each i until stop = 1)
2541-
if gap("Length(matCwt)") > 0:
2551+
if gap("Length(matCwt)") > 0:
25422552
A = gap("MatrixAutomorphisms(matCwt)")
25432553
G2 = gap("Intersection2(%s,%s)"%(str(A).replace("\n",""),str(Gp).replace("\n",""))) # bottleneck 3
25442554
Gp = G2
@@ -3020,7 +3030,7 @@ def spectrum(self, algorithm=None):
30203030
input = code2leon(self) + "::code"
30213031
import os, subprocess
30223032
lines = subprocess.check_output([os.path.join(guava_bin_dir, 'wtdist'), input])
3023-
import StringIO # to use the already present output parser
3033+
import StringIO # to use the already present output parser
30243034
wts = [0]*(n+1)
30253035
s = 0
30263036
for L in StringIO.StringIO(lines).readlines():
@@ -3538,7 +3548,7 @@ def generator_matrix(self):
35383548

35393549

35403550
####################### decoders ###############################
3541-
from decoder import Decoder, DecodingFailure
3551+
from decoder import Decoder, DecodingError
35423552
class LinearCodeSyndromeDecoder(Decoder):
35433553
r"""
35443554
Construct a decoder for Linear Codes. This decoder will use a syndrome

0 commit comments

Comments
 (0)
This repository has been archived.