Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-36097: Add additional bindings from NTL to
Polynomial_ZZ_pEX
There are current cython bindings to NTL methods which are not made available to polynomial rings over extension fields. For some of these bindings, their introduction does not offer much speed up, but there is a 50x improvement for using NTL reverse over that of the current implementation, and about a 20% speed up using the NTL `ZZ_pEX_InvTrunc` over what is currently implemented. Method names and functionalities have been preserved, so this simply improves performance for the `Polynomial_ZZ_pEX` type without effecting other polynomial ring classes. #### Before Patch ```py sage: p = next_prime(2**1024) sage: F.<i> = GF(p^2) sage: R.<x> = PolynomialRing(F, implementation="NTL") sage: sage: f = R([p for p in primes(10)]) sage: %timeit f.reverse() 125 µs ± 582 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) sage: %timeit f.inverse_series_trunc(500) 4.96 ms ± 81.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) sage: sage: f = R([p for p in primes(100)]) sage: %timeit f.reverse() 681 µs ± 4.21 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each) sage: %timeit f.inverse_series_trunc(500) 7.1 ms ± 62.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) sage: sage: f = R([p for p in primes(1000)]) sage: %timeit f.reverse() 4.57 ms ± 77 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) sage: %timeit f.inverse_series_trunc(500) 10.9 ms ± 82.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) ``` #### After Patch ```py sage: p = next_prime(2**1024) sage: F.<i> = GF(p^2) sage: R.<x> = PolynomialRing(F, implementation="NTL") sage: sage: f = R([p for p in primes(10)]) sage: %timeit f.reverse() 836 ns ± 9.91 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each) sage: %timeit f.inverse_series_trunc(500) 1.84 ms ± 77.1 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each) sage: sage: f = R([p for p in primes(100)]) sage: %timeit f.reverse() 3.63 µs ± 103 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each) sage: %timeit f.inverse_series_trunc(500) 6.66 ms ± 441 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) sage: f = R([p for p in primes(1000)]) sage: %timeit f.reverse() 26.8 µs ± 1.48 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each) sage: %timeit f.inverse_series_trunc(500) 8.75 ms ± 432 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) ``` ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies The only additional import is `sig_on()` and `sig_off()` into the `Polynomial_ZZ_pEX.pyx` ### Warning! This is my first attempt to contribute new functions to sagemath, and it's also my first few weeks of playing with cython. I have done my best to do what is needed, but maybe I have done something incorrect. Please let me know if there's more I can do. In particular, I know an alternative edit to the one I proposed is to modify the child `Polynomial_template` class instead of the `Polynomial_ZZ_pEX` class, but I know less about all the other parents of this class and I was concerned I may make breaking changes somewhere downstream. Currently, this just adds the NTL methods when I know they are avaialble and they simply do what is done currently, but faster. URL: #36097 Reported by: Giacomo Pope Reviewer(s): Frédéric Chapoton
- Loading branch information