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

Refactor Poly class and its inheritance #320

Merged
merged 5 commits into from
Mar 27, 2022
Merged

Conversation

mhostetter
Copy link
Owner

@mhostetter mhostetter commented Mar 27, 2022

This PR implements #176. As a consequence of removing DensePoly, BinaryPoly, and SparsePoly and consolidating them into Poly, binary array arithmetic/creation is much faster. Below are some examples.

Polynomial arithmetic over GF(2)

In [1]: import galois

In [2]: f = galois.Poly.Random(20, seed=1); f
Out[2]: Poly(x^20 + x^19 + x^16 + x^15 + x^13 + x^11 + x^9 + x^8 + x^7 + x^5 + x^4 + x^2 + 1, GF(2))

In [3]: g = galois.Poly.Random(10, seed=1); g
Out[3]: Poly(x^10 + x^9 + x^6 + x^5 + x^3 + x, GF(2))

In [4]: f * g
Out[4]: Poly(x^30 + x^28 + x^22 + x^20 + x^19 + x^13 + x^11 + x^10 + x^9 + x^8 + x^5 + x, GF(2))
# Before
In [5]: %timeit f * g
196 µs ± 11.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

# After
In [5]: %timeit f * g
2.66 µs ± 13 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

Polynomial search routines in GF(2)

# Before
In [4]: %timeit galois.primitive_polys(2, 12)
10.1 s ± 123 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# After
In [2]: %timeit galois.primitive_polys(2, 12)
783 ms ± 1.53 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

@mhostetter mhostetter added performance Affects speed/performance poly Related to polynomials labels Mar 27, 2022
@codecov
Copy link

codecov bot commented Mar 27, 2022

Codecov Report

Merging #320 (c8a753d) into master (a454532) will decrease coverage by 0.61%.
The diff coverage is 86.08%.

@@            Coverage Diff             @@
##           master     #320      +/-   ##
==========================================
- Coverage   93.73%   93.11%   -0.62%     
==========================================
  Files          30       30              
  Lines        5156     5128      -28     
==========================================
- Hits         4833     4775      -58     
- Misses        323      353      +30     
Impacted Files Coverage Δ
galois/_fields/_main.py 90.67% <84.47%> (-2.18%) ⬇️
galois/_poly_conversion.py 97.22% <95.74%> (-0.96%) ⬇️
galois/_fields/_functions.py 88.27% <100.00%> (ø)
galois/_fields/_poly_functions.py 100.00% <100.00%> (ø)
galois/_fields/_ufuncs.py 88.55% <0.00%> (-0.61%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a454532...c8a753d. Read the comment docs.

@mhostetter mhostetter merged commit 1a81be4 into master Mar 27, 2022
@mhostetter mhostetter deleted the refactor-poly-classes branch March 27, 2022 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Affects speed/performance poly Related to polynomials
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant