Skip to content

Commit

Permalink
Add more minimal_poly() unit tests for 0-D scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Feb 10, 2022
1 parent 4879587 commit 51c4362
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 386 deletions.
12 changes: 12 additions & 0 deletions scripts/generate_field_test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,18 @@ def make_luts(field, sub_folder, seed, sparse=False):
d = {"X": X, "Z": Z}
save_pickle(d, folder, "characteristic_poly_matrix.pkl")

set_seed(seed + 14)
X, _ = io_1d(0, order, sparse=sparse)
Z = []
for i in range(len(X)):
x = F(X[i])
p = x.minpoly()
z = np.array([I(e) for e in p.list()[::-1]], dtype=dtype).tolist()
z = z if z != [] else [0]
Z.append(z)
d = {"X": X, "Z": Z}
save_pickle(d, folder, "minimal_poly_element.pkl")

###############################################################################
# Polynomial arithmetic
###############################################################################
Expand Down
12 changes: 12 additions & 0 deletions tests/fields/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,15 @@ def field_characteristic_poly_matrix(field_folder):
d["X"] = [GF(x) for x in d["X"]]
d["Z"] = [galois.Poly(p, field=GF) for p in d["Z"]]
return d


@pytest.fixture(scope="session")
def field_minimal_poly_element(field_folder):
GF, folder = field_folder
with open(os.path.join(folder, "minimal_poly_element.pkl"), "rb") as f:
print(f"Loading {f}...")
d = pickle.load(f)
d["GF"] = GF
d["X"] = GF(d["X"])
d["Z"] = [galois.Poly(p, field=GF.prime_subfield) for p in d["Z"]]
return d
Binary file not shown.
Binary file added tests/fields/data/GF(2)/minimal_poly_element.pkl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/fields/data/GF(2^2)/minimal_poly_element.pkl
Binary file not shown.
Binary file added tests/fields/data/GF(2^3)/minimal_poly_element.pkl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/fields/data/GF(31)/minimal_poly_element.pkl
Binary file not shown.
Binary file added tests/fields/data/GF(3191)/minimal_poly_element.pkl
Binary file not shown.
Binary file not shown.
Binary file added tests/fields/data/GF(5)/minimal_poly_element.pkl
Binary file not shown.
Binary file added tests/fields/data/GF(7)/minimal_poly_element.pkl
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/fields/test_arithmetic_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,18 @@ def test_characteristic_poly_matrix(field_characteristic_poly_matrix):
with pytest.raises(ValueError):
A = GF.Random((2,3))
A.characteristic_poly()


def test_minimal_poly_element(field_minimal_poly_element):
GF, X, Z = field_minimal_poly_element["GF"], field_minimal_poly_element["X"], field_minimal_poly_element["Z"]
dtype = random.choice(GF.dtypes)
x = X.astype(dtype)

for i in range(x.size):
zi = x[i].minimal_poly()
assert zi == Z[i]

# Only 0-D arrays are allowed
with pytest.raises(ValueError):
A = GF.Random(5)
A.minimal_poly()
Loading

0 comments on commit 51c4362

Please sign in to comment.