Skip to content

Commit 888b4bc

Browse files
committed
Make error strings more consistent
1 parent 6e21bb1 commit 888b4bc

6 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/galois/_codes/_linear.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def __init__(
3737
verify_isinstance(systematic, bool)
3838

3939
if not n >= k:
40-
raise ValueError(f"Argument `n` must be greater than or equal to `k`, {n} is not greater than {k}.")
40+
raise ValueError(f"Argument 'n' must be greater than or equal to 'k', {n} is not greater than {k}.")
4141
if not d >= 1:
42-
raise ValueError(f"Argument `d` must be at least 1, not {d}.")
42+
raise ValueError(f"Argument 'd' must be at least 1, not {d}.")
4343
if not type(G) is type(H):
44-
raise ValueError(f"Arguments `G` and `H` must be over the same field, not {type(G)} and {type(H)}.")
44+
raise ValueError(f"Arguments 'G' and 'H' must be over the same field, not {type(G)} and {type(H)}.")
4545
if not G.shape == (k, n):
46-
raise ValueError(f"Argument `G` must be have shape (k, n), {G.shape} is not ({k}, {n}).")
46+
raise ValueError(f"Argument 'G' must be have shape (k, n), {G.shape} is not ({k}, {n}).")
4747
if not H.shape == (n - k, n):
48-
raise ValueError(f"Argument `H` must be have shape (n - k, n), {H.shape} is not ({n - k}, {n}).")
48+
raise ValueError(f"Argument 'H' must be have shape (n - k, n), {H.shape} is not ({n - k}, {n}).")
4949

5050
self._n = n
5151
self._k = k
@@ -78,7 +78,7 @@ def encode(self, message: ArrayLike, output: Literal["codeword", "parity"] = "co
7878
verify_literal(output, ["codeword", "parity"])
7979

8080
if output == "parity" and not self.is_systematic:
81-
raise ValueError("Argument `output` may only be 'parity' for systematic codes.")
81+
raise ValueError("Argument 'output' may only be 'parity' for systematic codes.")
8282

8383
message, is_message_1d = self._check_and_convert_message(message)
8484
codeword = self._encode_message(message)
@@ -207,10 +207,10 @@ def _check_and_convert_message(self, message: ArrayLike) -> tuple[FieldArray, bo
207207
message = self.field(message)
208208

209209
if message.ndim > 2:
210-
raise ValueError(f"Argument `message` can be either 1-D or 2-D, not {message.ndim}-D.")
210+
raise ValueError(f"Argument 'message' can be either 1-D or 2-D, not {message.ndim}-D.")
211211
if not 1 <= message.shape[-1] <= self.k:
212212
raise ValueError(
213-
f"The `message` must be a 1-D or 2-D array with last dimension between 1 and {self.k}, "
213+
f"Argument 'message' must be a 1-D or 2-D array with last dimension between 1 and {self.k}, "
214214
f"not shape {message.shape}."
215215
)
216216

@@ -229,7 +229,7 @@ def _check_and_convert_codeword(self, codeword: FieldArray) -> FieldArray:
229229

230230
if not self.n - self.k + 1 <= codeword.shape[-1] <= self.n:
231231
raise ValueError(
232-
f"The argument `codeword` must be a 1-D or 2-D array with last dimension between {self.n - self.k + 1} "
232+
f"Argument 'codeword' must be a 1-D or 2-D array with last dimension between {self.n - self.k + 1} "
233233
f"and {self.n}, not shape {codeword.shape}."
234234
)
235235

src/galois/_domains/_linalg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def __call__(self, a: Array, b: Array) -> Array:
153153
return a * b
154154
if not a.shape[-1] == b.shape[-1]:
155155
raise ValueError(
156-
f"Operation 'inner' requires `a` and `b` to have the same last dimension, not {a.shape} and {b.shape}."
156+
f"Operation 'inner' requires 'a' and 'b' to have the same last dimension, not {a.shape} and {b.shape}."
157157
)
158158

159159
return np.sum(a * b, axis=-1)

src/galois/_fields/_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ def Vector(cls, array: ArrayLike, dtype: DTypeLike | None = None) -> FieldArray:
420420
x = x.view(np.ndarray) # Convert into an integer array
421421
if not x.shape[-1] == degree:
422422
raise ValueError(
423-
f"The last dimension of `array` must be the field extension dimension {cls.degree}, not {x.shape[-1]}."
423+
f"Argument 'array' must have last dimension equal to the field extension dimension {cls.degree}, "
424+
f"not {x.shape[-1]}."
424425
)
425426

426427
degrees = np.arange(degree - 1, -1, -1, dtype=dtype)

src/galois/_ntt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def ntt(
110110
"""
111111
verify_isinstance(x, (tuple, list, np.ndarray, FieldArray))
112112
if isinstance(x, FieldArray) and not type(x).is_prime_field:
113-
raise ValueError(f"If argument `x` is a FieldArray, it must be a prime field, not {type(x)}.")
113+
raise ValueError(f"If argument 'x' is a FieldArray, it must be a prime field, not {type(x)}.")
114114

115115
if modulus is None and isinstance(x, FieldArray):
116116
modulus = type(x).characteristic
@@ -228,7 +228,7 @@ def intt(
228228
"""
229229
verify_isinstance(X, (tuple, list, np.ndarray, FieldArray))
230230
if isinstance(X, FieldArray) and not type(X).is_prime_field:
231-
raise ValueError(f"If argument `X` is a FieldArray, it must be a prime field, not {type(X)}.")
231+
raise ValueError(f"If argument 'X' is a FieldArray, it must be a prime field, not {type(X)}.")
232232

233233
if modulus is None and isinstance(X, FieldArray):
234234
modulus = type(X).characteristic

src/galois/_polymorphic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def gcd(a, b):
9191
return int_gcd(a, b)
9292
if isinstance(a, Poly) and isinstance(b, Poly):
9393
return poly_gcd(a, b)
94-
raise TypeError(f"Arguments `a` and `b` must both be either int or galois.Poly, not {type(a)} and {type(b)}.")
94+
raise TypeError(f"Arguments 'a' and 'b' must both be either int or galois.Poly, not {type(a)} and {type(b)}.")
9595

9696

9797
@overload
@@ -169,7 +169,7 @@ def egcd(a, b):
169169
return int_egcd(a, b)
170170
if isinstance(a, Poly) and isinstance(b, Poly):
171171
return poly_egcd(a, b)
172-
raise TypeError(f"Arguments `a` and `b` must both be either int or galois.Poly, not {type(a)} and {type(b)}.")
172+
raise TypeError(f"Arguments 'a' and 'b' must both be either int or galois.Poly, not {type(a)} and {type(b)}.")
173173

174174

175175
@overload

src/galois/_polys/_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def gcd(a: Poly, b: Poly) -> Poly:
1212
This function is wrapped and documented in `_polymorphic.gcd()`.
1313
"""
1414
if not a.field is b.field:
15-
raise ValueError(f"Polynomials `a` and `b` must be over the same Galois field, not {a.field} and {b.field}.")
15+
raise ValueError(f"Polynomials 'a' and 'b' must be over the same Galois field, not {a.field} and {b.field}.")
1616

1717
r2, r1 = a, b
1818
while r1 != 0:
@@ -31,7 +31,7 @@ def egcd(a: Poly, b: Poly) -> tuple[Poly, Poly, Poly]:
3131
This function is wrapped and documented in `_polymorphic.egcd()`.
3232
"""
3333
if not a.field is b.field:
34-
raise ValueError(f"Polynomials `a` and `b` must be over the same Galois field, not {a.field} and {b.field}.")
34+
raise ValueError(f"Polynomials 'a' and 'b' must be over the same Galois field, not {a.field} and {b.field}.")
3535

3636
field = a.field
3737
zero = Poly([0], field=field)

0 commit comments

Comments
 (0)