Skip to content

Commit eabe7e0

Browse files
Reworked coercion of evaluation pts and col mults and refined tests.
Now thematic tutorial tests pass again
1 parent 91e2e3b commit eabe7e0

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

src/sage/coding/grs.py

+46-30
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,31 @@ def __init__(self, evaluation_points, dimension, column_multipliers=None):
9494
sage: C = codes.GeneralizedReedSolomonCode([1,2,3], 1)
9595
Traceback (most recent call last):
9696
...
97-
ValueError: Evaluation points must be in a finite field
97+
ValueError: Evaluation points must be in a finite field (and Integer Ring is not one)
9898
9999
If the evaluation points are not from the same finite field, it raises an error::
100100
101101
sage: F2, F3 = GF(2) , GF(3)
102102
sage: C = codes.GeneralizedReedSolomonCode([F2.zero(),F2.one(),F3(2)], 1)
103103
Traceback (most recent call last):
104104
...
105-
ValueError: All evaluation points must be in the same finite field
105+
ValueError: Failed converting all evaluation points to the same field (unable to find a common ring for all elements)
106106
107-
If the column multipliers are not from a finite field, or not in the same
107+
If the column multipliers cannot be converted into the finite are not from a finite field, or cannot be not in the same
108108
finite field as the evaluation points, it raises an error::
109109
110110
sage: F = GF(59)
111111
sage: F2 = GF(61)
112112
sage: n, k = 40, 12
113-
sage: C = codes.GeneralizedReedSolomonCode(F.list()[:n], k, vector(range(1,n+1)) )
113+
sage: C = codes.GeneralizedReedSolomonCode(F.list()[:n], k, [.3]*n )
114114
Traceback (most recent call last):
115115
...
116-
ValueError: Column multipliers and evaluation points must be in the same field
116+
ValueError: Failed converting all evaluation points and column multipliers to the same field (unable to find a common ring for all elements)
117117
118118
sage: C = codes.GeneralizedReedSolomonCode(F.list()[:n], k, F2.list()[1:n+1])
119119
Traceback (most recent call last):
120120
...
121-
ValueError: Column multipliers and evaluation points must be in the same field
121+
ValueError: Failed converting all evaluation points and column multipliers to the same field (unable to find a common ring for all elements)
122122
123123
The number of column multipliers is checked as well::
124124
@@ -127,7 +127,7 @@ def __init__(self, evaluation_points, dimension, column_multipliers=None):
127127
sage: C = codes.GeneralizedReedSolomonCode(F.list()[:n], k, F.list()[1:n])
128128
Traceback (most recent call last):
129129
...
130-
ValueError: There must be exactly 40 column multipliers
130+
ValueError: There must be the same number of evaluation points as column multipliers
131131
132132
It is not allowed to have 0 as a column multiplier::
133133
@@ -138,35 +138,51 @@ def __init__(self, evaluation_points, dimension, column_multipliers=None):
138138
...
139139
ValueError: All column multipliers must be non-zero
140140
141-
And all the evaluation points must be different::
141+
And all the evaluation points must be different. Note that they should
142+
be different after converting into the same field::
142143
143-
sage: F = GF(59)
144-
sage: n, k = 40, 12
145-
sage: C = codes.GeneralizedReedSolomonCode([F.one()]*n, k)
144+
sage: F = GF(5)
145+
sage: C = codes.GeneralizedReedSolomonCode([ F(0), 1, 2, 3, 5 ], 3)
146146
Traceback (most recent call last):
147147
...
148148
ValueError: All evaluation points must be different
149+
150+
The dimension is not allowed to exceed the length::
151+
152+
sage: F = GF(59)
153+
sage: n, k = 40, 100
154+
sage: C = codes.GeneralizedReedSolomonCode(F.list()[:n], k)
155+
Traceback (most recent call last):
156+
...
157+
ValueError: The dimension must be a positive integer at most the length of the code.
149158
"""
150-
F = evaluation_points[0].base_ring()
151-
if F.is_finite() == False:
152-
raise ValueError("Evaluation points must be in a finite field")
153-
if not all(F == e.base_ring() for e in evaluation_points):
154-
raise ValueError("All evaluation points must be in the same finite field")
159+
if column_multipliers:
160+
if len(evaluation_points) != len(column_multipliers):
161+
raise ValueError("There must be the same number of evaluation points as column multipliers");
162+
try:
163+
common_points = vector(list(evaluation_points) + list(column_multipliers))
164+
F = common_points.base_ring()
165+
self._evaluation_points = common_points[:len(evaluation_points)]
166+
self._column_multipliers = common_points[len(evaluation_points):]
167+
except (TypeError, ValueError) as e:
168+
raise ValueError("Failed converting all evaluation points and column multipliers to the same field (%s)" % e.message)
169+
else:
170+
try:
171+
self._evaluation_points = vector(evaluation_points)
172+
F = self._evaluation_points.base_ring()
173+
self._column_multipliers = vector(F, [F.one()] * len(self._evaluation_points))
174+
except (TypeError, ValueError) as e:
175+
raise ValueError("Failed converting all evaluation points to the same field (%s)" % e.message)
176+
177+
if F.is_finite() == False or F.is_field() == False:
178+
raise ValueError("Evaluation points must be in a finite field (and %s is not one)" % F)
155179
super(GeneralizedReedSolomonCode, self).__init__(F, \
156-
len(evaluation_points), "EvaluationVector", "Syndrome")
157-
self._evaluation_points = tuple(evaluation_points)
180+
len(self._evaluation_points), "EvaluationVector", "Syndrome")
181+
182+
if dimension not in ZZ or dimension > self._length or dimension < 1:
183+
raise ValueError("The dimension must be a positive integer at most the length of the code.")
158184
self._dimension = dimension
159185

160-
if column_multipliers is None:
161-
self._column_multipliers = tuple(self.base_field().one() for i in range(self._length) )
162-
else:
163-
if not all(F == e.base_ring() for e in column_multipliers):
164-
raise ValueError("Column multipliers and evaluation points\
165-
must be in the same field")
166-
self._column_multipliers = tuple(column_multipliers)
167-
if len(self._column_multipliers) != self._length:
168-
raise ValueError("There must be exactly %s column multipliers"\
169-
% self._length)
170186
if 0 in self._column_multipliers:
171187
raise ValueError("All column multipliers must be non-zero")
172188
if len(self._evaluation_points) != len(set(self._evaluation_points)):
@@ -257,7 +273,7 @@ def minimum_distance(self):
257273

258274
def evaluation_points(self):
259275
r"""
260-
Returns the list of evaluation points of ``self``.
276+
Returns the evaluation points of ``self`` as a vector.
261277
262278
EXAMPLES::
263279
@@ -271,7 +287,7 @@ def evaluation_points(self):
271287

272288
def column_multipliers(self):
273289
r"""
274-
Returns the list of column multipliers of ``self``.
290+
Returns the column multipliers of ``self`` as a vector.
275291
276292
EXAMPLES::
277293

0 commit comments

Comments
 (0)