galois
galois copied to clipboard
where argument doesn't work with np.reciprocal
Python: 3.11.6, galois version 0.3.5, numpy version 1.24
This code produces an error:
F = GF(2**8)
x = F([1, 1, 3])
x_invertible = x != 0
y = np.reciprocal(x, where=x_invertible)
Exception
self = <galois._domains._calculate.reciprocal_itoh_tsujii object at 0x7f020ad67d90>
ufunc = <ufunc 'reciprocal'>, method = '__call__'
inputs = [array([1, 1, 3], dtype=uint8)]
kwargs = {'casting': 'unsafe', 'where': array([ True, True, True])}
meta = {'dtype': dtype('uint8'), 'field_operands': [0], 'non_field_operands': [], 'operands': [0], ...}
def __call__(self, ufunc, method, inputs, kwargs, meta):
self._verify_unary_method_not_reduction(ufunc, method)
inputs, kwargs = self._view_inputs_as_ndarray(inputs, kwargs)
> output = getattr(self.ufunc, method)(*inputs, **kwargs)
E ValueError: Only one of the iterator flags READWRITE, READONLY, and WRITEONLY may be specified for an operand
../.venv/lib/python3.11/site-packages/galois/_domains/_ufunc.py:413: ValueError
Thanks for the report. I believe Numba doesn't support exotic keyword arguments, like where
, to numba.vectorize()
'd functions. If that's the case, there's nothing we can do.
Perhaps we should add better error reporting. I had this idea a long time ago in #34, but never completely implemented it.
Thanks for the fast reply! That makes sense, as a workaround I used
np.reciprocal.at(x, np.nonzero(x))
I think I'm going to close this. where
support is needed from Numba before it will be exposed in this library. Once Numba adds it, users will have access to it from galois
.