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

Commit 4d7f14d

Browse files
author
David Lucas
committed
New method: _init_linear_code
1 parent 4087964 commit 4d7f14d

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

src/sage/coding/linear_code.py

+53-5
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,58 @@ class LinearCode(module.Module):
762762
# 3
763763
# sage: C.minimum_distance_why() # optional (net connection)
764764
# Ub(7,4) = 3 follows by the Griesmer bound.
765+
766+
def _init_linear_code(self, base_field, length):
767+
"""
768+
Initialize mandatory parameters for a Linear Code object.
769+
770+
This is a private method, which should be called by the constructor of
771+
every linear code as it automatically initializes the some
772+
mandatory parameters of a Linear Code object, and sets this object as
773+
a valid member of the Sage category framework.
774+
775+
INPUT:
776+
777+
- ``base_field`` -- the base field of ``self``
778+
779+
- ``length`` -- the length of ``self``
780+
781+
EXAMPLES:
782+
783+
We first create a new LinearCode subclass
784+
::
785+
786+
sage: class CodeExample(LinearCode):
787+
....: def __init__(self, field, length, dimension):
788+
....: self._init_linear_code(field, length)
789+
....: self._dimension = dimension
790+
791+
We now create a member of our newly made class
792+
::
793+
794+
sage: C = CodeExample(GF(17), 10, 5)
795+
796+
We can check its existence and parameters
797+
::
798+
799+
sage: C
800+
Linear code of length 10, dimension 5 over Finite Field of size 17
801+
802+
And we can check that it is truly a part of the framework category
803+
::
804+
805+
sage: C.parent()
806+
<class '__main__.CodeExample_with_category'>
807+
sage: C.category()
808+
Category of facade finite dimensional vector spaces with basis over Finite Field of size 17
809+
"""
810+
self._base_field = base_field
811+
self._length = length
812+
cat = Modules(base_field).FiniteDimensional().WithBasis().Finite()
813+
facade_for = VectorSpace(self._base_field, self._length)
814+
self.Element = type(facade_for.an_element()) # for when we make this a non-facade parent
815+
Parent.__init__(self, base=base_field, facade=facade_for, category=cat)
816+
765817
def __init__(self, generator_matrix, d=None):
766818
r"""
767819
See the docstring for :meth:`LinearCode`.
@@ -823,13 +875,9 @@ def __init__(self, generator_matrix, d=None):
823875
if generator_matrix.nrows() == 0:
824876
raise ValueError("this linear code contains no non-zero vector")
825877

826-
cat = Modules(base_ring).FiniteDimensional().WithBasis().Finite()
827-
facade_for = generator_matrix.row(0).parent()
828-
self.Element = type(generator_matrix.row(0)) # for when we make this a non-facade parent
829-
Parent.__init__(self, base=base_ring, facade=facade_for, category=cat)
878+
self._init_linear_code(base_ring, generator_matrix.ncols())
830879
self._gens = generator_matrix.rows()
831880
self._generator_matrix = generator_matrix
832-
self._length = generator_matrix.ncols()
833881
self._dimension = generator_matrix.rank()
834882
self._minimum_distance = d
835883

0 commit comments

Comments
 (0)