From 01498bdf6516ebc454cdae17b898be18f6cc441d Mon Sep 17 00:00:00 2001 From: mhostetter Date: Sat, 22 Jun 2024 10:57:19 -0400 Subject: [PATCH 1/6] Bump NumPy to v2.0 and Numba to v0.61 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3640b344d..0186afb48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,8 +50,8 @@ classifiers = [ ] requires-python = ">=3.7" dependencies = [ - "numpy >= 1.21.0, < 1.27", # v1.21.0 is needed for dtype support of ufuncs, see https://numpy.org/devdocs/release/1.21.0-notes.html#ufunc-signature-and-dtype-generalization-and-casting - "numba >= 0.55, < 0.60", # v0.55 is needed for support of NumPy 1.21 + "numpy >= 1.21.0, < 2.1", # v1.21.0 is needed for dtype support of ufuncs, see https://numpy.org/devdocs/release/1.21.0-notes.html#ufunc-signature-and-dtype-generalization-and-casting + "numba >= 0.55, < 0.61", # v0.55 is needed for support of NumPy 1.21 "typing_extensions >= 4.0.0", # v4.0.0 is needed for use of Self (Python 3.11+) and Literal (Python 3.8+) ] dynamic = ["version"] From 45d2ef08c2f4de34ce961c07bba56d4656fc756b Mon Sep 17 00:00:00 2001 From: mhostetter Date: Sat, 22 Jun 2024 11:02:54 -0400 Subject: [PATCH 2/6] Replace `np.round_()` with `np.round()` --- src/galois/_domains/_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/galois/_domains/_function.py b/src/galois/_domains/_function.py index 0460043cd..eaf7d4a9f 100644 --- a/src/galois/_domains/_function.py +++ b/src/galois/_domains/_function.py @@ -308,7 +308,7 @@ class FunctionMixin(np.ndarray, metaclass=ArrayMeta): np.unpackbits, np.unwrap, np.around, - np.round_, + np.round, np.fix, np.gradient, np.trapz, From b1864614ffe33e822b875c5d61ac53389a4a17d3 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Sat, 22 Jun 2024 14:27:28 -0400 Subject: [PATCH 3/6] Fix `np.mod()` in NumPy v2 --- src/galois/_domains/_ufunc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/galois/_domains/_ufunc.py b/src/galois/_domains/_ufunc.py index 72168b6da..e89d2456e 100644 --- a/src/galois/_domains/_ufunc.py +++ b/src/galois/_domains/_ufunc.py @@ -394,7 +394,11 @@ def __call__(self, ufunc, method, inputs, kwargs, meta): self._verify_operands_in_field_or_int(ufunc, inputs, meta) inputs, kwargs = self._view_inputs_as_ndarray(inputs, kwargs) i = meta["non_field_operands"][0] # Scalar multiplicand - inputs[i] = np.mod(inputs[i], self.field.characteristic) + if meta["dtype"] == np.object_: + # Need to explicitly cast to np.object_ in NumPy v2.0 or the integer will overflow + inputs[i] = np.mod(inputs[i], self.field.characteristic, dtype=np.object_) + else: + inputs[i] = np.mod(inputs[i], self.field.characteristic) inputs, kwargs = self._view_inputs_as_ndarray(inputs, kwargs) output = getattr(self.ufunc, method)(*inputs, **kwargs) output = self._view_output_as_field(output, self.field, meta["dtype"]) From 33dc35c460d430e548a13dd755422a10b7e19047 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Mon, 1 Jul 2024 17:09:23 -0400 Subject: [PATCH 4/6] Fix root multiplicity of 0 in JIT function --- src/galois/_polys/_dense.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/galois/_polys/_dense.py b/src/galois/_polys/_dense.py index b1b3e289c..91b6050fe 100644 --- a/src/galois/_polys/_dense.py +++ b/src/galois/_polys/_dense.py @@ -487,7 +487,7 @@ def implementation(nonzero_degrees, nonzero_coeffs, primitive_element): # pragm # Test if 0 is a root if nonzero_degrees[-1] != 0: roots.append(0) - powers.append(-1) + powers.append(nonzero_degrees[-1]) # 0 has multiplicity equal to the lowest degree of x that is non-zero # Test if 1 is a root _sum = 0 From a043f0d7c53105d68ba2db45080fed3e29a253c3 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Mon, 1 Jul 2024 17:10:06 -0400 Subject: [PATCH 5/6] Make `dtype` arbitrary so negative integers aren't force-cast into uints --- src/galois/_polys/_dense.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/galois/_polys/_dense.py b/src/galois/_polys/_dense.py index 91b6050fe..6edd1e80e 100644 --- a/src/galois/_polys/_dense.py +++ b/src/galois/_polys/_dense.py @@ -510,4 +510,4 @@ def implementation(nonzero_degrees, nonzero_coeffs, primitive_element): # pragm if len(roots) == degree: break - return np.array([roots, powers], dtype=nonzero_coeffs.dtype) + return np.array([roots, powers]) From 9821b23b0d400582d4c8717414e9cff2edaf54d2 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Mon, 1 Jul 2024 17:18:53 -0400 Subject: [PATCH 6/6] Use max dtype for integer dtype, either `np.int64` or `np.object_` NumPy 2.0 raises an OverflowError instead of casting to dtype np.object_ as in previous versions. This can happen here if field.charactersitic is to large to fit in a np.int64. --- src/galois/_fields/_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/galois/_fields/_array.py b/src/galois/_fields/_array.py index 9f1173f32..2895a4563 100644 --- a/src/galois/_fields/_array.py +++ b/src/galois/_fields/_array.py @@ -989,7 +989,7 @@ def additive_order(self) -> int | np.ndarray: if x.ndim == 0: order = 1 if x == 0 else field.characteristic else: - order = field.characteristic * np.ones(x.shape, dtype=np.int64) + order = field.characteristic * np.ones(x.shape, dtype=field.dtypes[-1]) order[np.where(x == 0)] = 1 return order