Skip to content

Commit

Permalink
Rename poly1 to poly in preferred_pairs()
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Jul 5, 2024
1 parent c6329c4 commit 62cba35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/sdr/_sequence/_maximum.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ def m_sequence(
@export
def preferred_pairs(
degree: int,
poly1: PolyLike | None = None,
poly: PolyLike | None = None,
) -> Iterator[tuple[Poly, Poly]]:
r"""
Generates primitive polynomials of degree $m$ that produce preferred pair $m$-sequences.
Arguments:
degree: The degree $m$ of the $m$-sequences.
poly1: The first polynomial $f(x)$ in the preferred pair. If `None`, all primitive polynomials of degree $m$
poly: The first polynomial $f(x)$ in the preferred pair. If `None`, all primitive polynomials of degree $m$
that yield preferred pair $m$-sequences are returned.
Returns:
Expand Down Expand Up @@ -208,13 +208,13 @@ def preferred_pairs(
.. ipython:: python
next(sdr.preferred_pairs(5, poly1="x^5 + x^3 + 1"))
next(sdr.preferred_pairs(5, poly="x^5 + x^3 + 1"))
Generate all preferred pairs with $f(x) = x^5 + x^3 + 1$.
.. ipython:: python
list(sdr.preferred_pairs(5, poly1="x^5 + x^3 + 1"))
list(sdr.preferred_pairs(5, poly="x^5 + x^3 + 1"))
Generate all preferred pairs with degree 5.
Expand Down Expand Up @@ -250,7 +250,7 @@ def preferred_pairs(
# Determine the valid cross-correlation values for preferred pairs, Page 799
valid_values = [-1, -t_m, t_m - 2]

if poly1 is None:
if poly is None:
# Find all combinations of primitive polynomials of degree m
for poly1, poly2 in itertools.combinations(galois.primitive_polys(2, degree), 2):
# Create first m-sequence with the first polynomial
Expand All @@ -269,7 +269,7 @@ def preferred_pairs(
yield poly1, poly2
else:
# Find all combinations of the first polynomial with all primitive polynomials of degree m
poly1 = Poly._PolyLike(poly1, field=galois.GF(2))
poly1 = Poly._PolyLike(poly, field=galois.GF(2))
if not poly1.degree == degree:
raise ValueError(f"Argument 'poly1' must be a polynomial of degree {degree}, not {poly1.degree}.")
if not poly1.is_primitive():
Expand Down
8 changes: 4 additions & 4 deletions tests/sequences/test_preferred_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def test_exceptions():

with pytest.raises(TypeError):
# Polynomial must be polynomial like
next(sdr.preferred_pairs(6, poly1=1.0))
next(sdr.preferred_pairs(6, poly=1.0))
with pytest.raises(ValueError):
# Polynomial must be a primitive polynomial
next(sdr.preferred_pairs(6, poly1=galois.Poly([1, 0, 0, 0, 0, 0, 1])))
next(sdr.preferred_pairs(6, poly=galois.Poly([1, 0, 0, 0, 0, 0, 1])))
with pytest.raises(ValueError):
# Polynomial must have correct degree
next(sdr.preferred_pairs(6, poly1=galois.Poly.Degrees([4, 1, 0])))
next(sdr.preferred_pairs(6, poly=galois.Poly.Degrees([4, 1, 0])))


def test_degree_divides_4():
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_degree_5():


def test_degree_5_specific():
assert list(sdr.preferred_pairs(5, poly1="x^5 + x^2 + 1")) == [
assert list(sdr.preferred_pairs(5, poly="x^5 + x^2 + 1")) == [
(galois.Poly.Str("x^5 + x^2 + 1"), galois.Poly.Str("x^5 + x^3 + x^2 + x + 1")),
(galois.Poly.Str("x^5 + x^2 + 1"), galois.Poly.Str("x^5 + x^4 + x^2 + x + 1")),
(galois.Poly.Str("x^5 + x^2 + 1"), galois.Poly.Str("x^5 + x^4 + x^3 + x + 1")),
Expand Down

0 comments on commit 62cba35

Please sign in to comment.