@@ -762,6 +762,58 @@ class LinearCode(module.Module):
762
762
# 3
763
763
# sage: C.minimum_distance_why() # optional (net connection)
764
764
# 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
+
765
817
def __init__ (self , generator_matrix , d = None ):
766
818
r"""
767
819
See the docstring for :meth:`LinearCode`.
@@ -823,13 +875,9 @@ def __init__(self, generator_matrix, d=None):
823
875
if generator_matrix .nrows () == 0 :
824
876
raise ValueError ("this linear code contains no non-zero vector" )
825
877
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 ())
830
879
self ._gens = generator_matrix .rows ()
831
880
self ._generator_matrix = generator_matrix
832
- self ._length = generator_matrix .ncols ()
833
881
self ._dimension = generator_matrix .rank ()
834
882
self ._minimum_distance = d
835
883
0 commit comments