Skip to content

Commit

Permalink
Fix code coverage
Browse files Browse the repository at this point in the history
Some sections must be ignored because they aren't invoked from `"python-calculate"` ufuncs. They *are* tested, but Numba doesn't provide coverage info.
  • Loading branch information
mhostetter committed Sep 2, 2022
1 parent 36c2413 commit ac57fc4
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/galois/_domains/_calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ac57fc4

Please sign in to comment.