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

Commit

Permalink
Updated __call__ method with a proper behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lucas committed Mar 31, 2016
1 parent e8d7b58 commit 872f5d7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/sage/coding/grs.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,27 @@ def encode(self, p):
c = vector(C.base_ring(), [col_mults[i]*p(alphas[i]) for i in range(C.length())])
return c

#Alias for encode method
__call__ = encode
def __call__(self, m):
r"""
Returns either ``m`` if it is a codeword or ``self.encode(m)``
if it is an element of the message space of the encoder used by
``encode``.
EXAMPLES::
sage: C = codes.GeneralizedReedSolomonCode(GF(11).list()[:10], 5)
sage: word = vector((0, 1, 3, 5, 4))
sage: C(word)
(0, 2, 8, 5, 10, 4, 9, 0, 4, 1)
sage: c = C.random_element()
sage: C(c) == c
True
"""
if m in self:
return m
else:
return self.encode(m)

def unencode_nocheck(self, c):
r"""
Expand Down
24 changes: 22 additions & 2 deletions src/sage/coding/linear_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,8 +1976,28 @@ def encode(self, word, encoder_name=None, **kwargs):
E = self.encoder(encoder_name, **kwargs)
return E.encode(word)

#Alias for encode method
__call__ = encode
def __call__(self, m):
r"""
Returns either ``m`` if it is a codeword or ``self.encode(m)``
if it is an element of the message space of the encoder used by
``encode``.
EXAMPLES::
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: word = vector((0, 1, 1, 0))
sage: C(word)
(1, 1, 0, 0, 1, 1, 0)
sage: c = C.random_element()
sage: C(c) == c
True
"""
if m in self:
return m
else:
return self.encode(m)

@cached_method
def encoder(self, encoder_name=None, **kwargs):
Expand Down

0 comments on commit 872f5d7

Please sign in to comment.