Skip to content

Commit

Permalink
Fix np.mod() in NumPy v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Jul 2, 2024
1 parent 3a8296d commit 3a19dfb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/galois/_domains/_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 3a19dfb

Please sign in to comment.