Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NumPy 1.23 #414

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix code coverage
Some sections must be ignored because they aren't invoked from `"python-calculate"` ufuncs. They *are* tested, but Numba doesn't provide coverage info.
mhostetter committed Sep 2, 2022
commit df4f38a8ca2e5cfd6896e312a5975bf15c39d3dd
50 changes: 26 additions & 24 deletions src/galois/_domains/_calculate.py
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ def vector_to_int(a_vec: np.ndarray, characteristic: int, degree: int) -> int:


@numba.jit(["int64[:](int64, int64)"], nopython=True, cache=True)
def egcd(a: int, b: int) -> np.ndarray:
def egcd(a: int, b: int) -> np.ndarray: # pragma: no cover
"""
Computes the Extended Euclidean Algorithm. Returns (d, s, t).

@@ -79,7 +79,7 @@ def egcd(a: int, b: int) -> np.ndarray:
EGCD = egcd

@numba.jit(["int64(int64[:], int64[:])"], nopython=True, cache=True)
def crt(remainders: np.ndarray, moduli: np.ndarray) -> int:
def crt(remainders: np.ndarray, moduli: np.ndarray) -> int: # pragma: no cover
"""
Computes the simultaneous solution to the system of congruences xi == ai (mod mi).
"""
@@ -405,29 +405,31 @@ def calculate(a: int) -> int:
return t2


class reciprocal_fermat(_lookup.reciprocal_ufunc):
"""
A ufunc dispatcher that provides the multiplicative inverse using Fermat's Little Theorem.
# NOTE: Commented out because it's not currently being used. This prevents it from being
# flagged as "not covered".
# class reciprocal_fermat(_lookup.reciprocal_ufunc):
# """
# A ufunc dispatcher that provides the multiplicative inverse using Fermat's Little Theorem.

Algorithm:
a in GF(p^m)
a^(p^m - 1) = 1
# Algorithm:
# a in GF(p^m)
# a^(p^m - 1) = 1

a * a^-1 = 1
a * a^-1 = a^(p^m - 1)
a^-1 = a^(p^m - 2)
"""
def set_calculate_globals(self):
global ORDER, POSITIVE_POWER
ORDER = self.field.order
POSITIVE_POWER = self.field._positive_power.ufunc
# a * a^-1 = 1
# a * a^-1 = a^(p^m - 1)
# a^-1 = a^(p^m - 2)
# """
# def set_calculate_globals(self):
# global ORDER, POSITIVE_POWER
# ORDER = self.field.order
# POSITIVE_POWER = self.field._positive_power.ufunc

@staticmethod
def calculate(a: int) -> int:
if a == 0:
raise ZeroDivisionError("Cannot compute the multiplicative inverse of 0 in a Galois field.")
# @staticmethod
# def calculate(a: int) -> int:
# if a == 0:
# raise ZeroDivisionError("Cannot compute the multiplicative inverse of 0 in a Galois field.")

return POSITIVE_POWER(a, ORDER - 2)
# return POSITIVE_POWER(a, ORDER - 2)


class reciprocal_itoh_tsujii(_lookup.reciprocal_ufunc):
@@ -584,7 +586,7 @@ def set_calculate_globals(self):
MULTIPLY = self.field._multiply.ufunc

@staticmethod
def calculate(beta: int, alpha: int) -> int:
def calculate(beta: int, alpha: int) -> int: # pragma: no cover
"""
beta is an element of GF(p^m)
alpha is a primitive element of GF(p^m)
@@ -615,7 +617,7 @@ def set_calculate_globals(self):
set_helper_globals(self.field)

@staticmethod
def calculate(beta: int, alpha: int) -> int:
def calculate(beta: int, alpha: int) -> int: # pragma: no cover
"""
beta is an element of GF(p^m)
alpha is a primitive element of GF(p^m)
@@ -701,7 +703,7 @@ def set_calculate_globals(self):
MULTIPLICITIES = np.array(MULTIPLICITIES, dtype=DTYPE)

@staticmethod
def calculate(beta: int, alpha: int) -> int:
def calculate(beta: int, alpha: int) -> int: # pragma: no cover
"""
beta is an element of GF(p^m)
alpha is a primitive element of GF(p^m)