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

Commit

Permalink
Merged trac #20840, fixed conflicts and broken doctets
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lucas committed Jun 17, 2016
2 parents 7248f40 + ad1cadd commit 2887ee1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/doc/en/thematic_tutorials/coding_theory.rst
Expand Up @@ -297,7 +297,7 @@ Let us see how one can explore this::

sage: C = codes.GeneralizedReedSolomonCode(GF(59).list()[:40], 12, GF(59).list()[1:41])
sage: C.encoders_available()
['EvaluationPolynomial', 'EvaluationVector']
['EvaluationPolynomial', 'EvaluationVector', 'Systematic', 'ParityCheck']
sage: C.decoders_available()
['Syndrome',
'NearestNeighbor',
Expand Down
19 changes: 19 additions & 0 deletions src/doc/en/thematic_tutorials/structures_in_coding_theory.rst
Expand Up @@ -252,6 +252,15 @@ To do that, just add the following line at the end of your file::

BinaryRepetitionCode._registered_encoders["RepetitionGeneratorMatrixEncoder"] = BinaryRepetitionCodeGeneratorMatrixEncoder

.. NOTE::

In case you are implementing a generic encoder (an encoder which works
with any family of linear codes), please add the following statement in
``AbstractLinearCode``'s constructor instead:
``self._registered_encoders["EncName"] = MyGenericEncoder``.
This will make it immediately available to any code
class which inherits from `AbstractLinearCode`.

Summary of the implementation for encoders
------------------------------------------

Expand Down Expand Up @@ -375,6 +384,16 @@ Also put this line to set ``decoder_type``::

BinaryRepetitionCode._decoder_type = {"hard-decision", "unique"}


.. NOTE::

In case you are implementing a generic decoder (a decoder which works
with any family of linear codes), please add the following statement in
``AbstractLinearCode``'s constructor instead:
``self._registered_decoders["DecName"] = MyGenericDecoder``.
This will make it immediately available to any code
class which inherits from `AbstractLinearCode`.

Summary of the implementation for decoders
------------------------------------------

Expand Down
3 changes: 0 additions & 3 deletions src/sage/coding/grs.py
Expand Up @@ -2147,9 +2147,6 @@ def decoding_radius(self):
GeneralizedReedSolomonCode._registered_encoders["EvaluationVector"] = GRSEvaluationVectorEncoder
GeneralizedReedSolomonCode._registered_encoders["EvaluationPolynomial"] = GRSEvaluationPolynomialEncoder

GeneralizedReedSolomonCode._registered_decoders["Syndrome"] = LinearCodeSyndromeDecoder
GeneralizedReedSolomonCode._registered_decoders["NearestNeighbor"] = LinearCodeNearestNeighborDecoder

GeneralizedReedSolomonCode._registered_decoders["BerlekampWelch"] = GRSBerlekampWelchDecoder
GRSBerlekampWelchDecoder._decoder_type = {"hard-decision", "unique", "always-succeed"}
GeneralizedReedSolomonCode._registered_decoders["Gao"] = GRSGaoDecoder
Expand Down
6 changes: 0 additions & 6 deletions src/sage/coding/hamming_code.py
Expand Up @@ -169,9 +169,3 @@ def minimum_distance(self):
3
"""
return 3

####################### registration ###############################

HammingCode._registered_encoders["ParityCheck"] = LinearCodeParityCheckEncoder
HammingCode._registered_decoders["Syndrome"] = LinearCodeSyndromeDecoder
HammingCode._registered_decoders["NearestNeighbor"] = LinearCodeNearestNeighborDecoder
25 changes: 16 additions & 9 deletions src/sage/coding/linear_code.py
Expand Up @@ -803,6 +803,14 @@ def __init__(self, base_field, length, default_encoder_name, default_decoder_nam
...
ValueError: 'generator' must be defined on a field (not a ring)
"""
### Add here any generic encoder/decoder ###
#This allows any class which inherits from AbstractLinearCode
#to use generic decoders/encoders
self._registered_encoders["ParityCheck"] = LinearCodeParityCheckEncoder
self._registered_encoders["Systematic"] = LinearCodeSystematicEncoder
self._registered_decoders["Syndrome"] = LinearCodeSyndromeDecoder
self._registered_decoders["NearestNeighbor"] = LinearCodeNearestNeighborDecoder

if not isinstance(length, (int, Integer)):
raise ValueError("length must be a Python int or a Sage Integer")
if not base_field.is_field():
Expand All @@ -811,6 +819,7 @@ def __init__(self, base_field, length, default_encoder_name, default_decoder_nam
raise ValueError("You must set a valid encoder as default encoder for this code, by filling in the dictionary of registered encoders")
if not default_decoder_name in self._registered_decoders:
raise ValueError("You must set a valid decoder as default decoder for this code, by filling in the dictionary of registered decoders")

self._length = Integer(length)
self._default_decoder_name = default_decoder_name
self._default_encoder_name = default_encoder_name
Expand Down Expand Up @@ -946,13 +955,13 @@ def add_encoder(self, name, encoder):
sage: C.add_encoder("MyEncoder", MyEncoder)
sage: C.encoders_available()
['MyEncoder', 'ParityCheck']
['MyEncoder', 'ParityCheck', 'Systematic']
We can verify that any new code will not know MyEncoder::
sage: C2 = codes.HammingCode(GF(2), 3)
sage: C2.encoders_available()
['ParityCheck']
['Systematic', 'ParityCheck']
TESTS:
Expand Down Expand Up @@ -1903,7 +1912,7 @@ def encode(self, word, encoder_name=None, **kwargs):
It is possible to manually choose the encoder amongst the list of the available ones::
sage: C.encoders_available()
['GeneratorMatrix', 'Systematic']
['GeneratorMatrix', 'Systematic', 'ParityCheck']
sage: word = vector((0, 1, 1, 0))
sage: C.encode(word, 'GeneratorMatrix')
(1, 1, 0, 0, 1, 1, 0)
Expand Down Expand Up @@ -1956,7 +1965,7 @@ def encoder(self, encoder_name=None, **kwargs):
an exception will be raised::
sage: C.encoders_available()
['GeneratorMatrix', 'Systematic']
['GeneratorMatrix', 'Systematic', 'ParityCheck']
sage: C.encoder('NonExistingEncoder')
Traceback (most recent call last):
...
Expand Down Expand Up @@ -1985,10 +1994,11 @@ def encoders_available(self, classes=False):
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]])
sage: C = LinearCode(G)
sage: C.encoders_available()
['GeneratorMatrix', 'Systematic']
['GeneratorMatrix', 'Systematic', 'ParityCheck']
sage: C.encoders_available(True)
{'GeneratorMatrix': <class 'sage.coding.linear_code.LinearCodeGeneratorMatrixEncoder'>,
'Systematic': <class 'sage.coding.linear_code.LinearCodeSystematicEncoder'>}
'ParityCheck': <class 'sage.coding.linear_code.LinearCodeParityCheckEncoder'>,
'Systematic': <class 'sage.coding.linear_code.LinearCodeSystematicEncoder'>}
"""
if classes == True:
return copy(self._registered_encoders)
Expand Down Expand Up @@ -4724,9 +4734,6 @@ def decoding_radius(self):
####################### registration ###############################

LinearCode._registered_encoders["GeneratorMatrix"] = LinearCodeGeneratorMatrixEncoder
LinearCode._registered_encoders["Systematic"] = LinearCodeSystematicEncoder

LinearCode._registered_decoders["Syndrome"] = LinearCodeSyndromeDecoder
LinearCodeSyndromeDecoder._decoder_type = {"hard-decision", "unique", "dynamic"}
LinearCode._registered_decoders["NearestNeighbor"] = LinearCodeNearestNeighborDecoder
LinearCodeNearestNeighborDecoder._decoder_type = {"hard-decision", "unique", "always-succeed", "complete"}
2 changes: 0 additions & 2 deletions src/sage/coding/punctured_code.py
Expand Up @@ -718,5 +718,3 @@ def decoding_radius(self, number_erasures = None):
PuncturedCode._registered_encoders["PuncturedMatrix"] = PuncturedCodePuncturedMatrixEncoder
PuncturedCode._registered_decoders["OriginalCode"] = PuncturedCodeOriginalCodeDecoder
PuncturedCodeOriginalCodeDecoder._decoder_type = {"dynamic"}
PuncturedCode._registered_decoders["Syndrome"] = LinearCodeSyndromeDecoder
PuncturedCode._registered_decoders["NearestNeighbor"] = LinearCodeNearestNeighborDecoder

0 comments on commit 2887ee1

Please sign in to comment.