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

pari/NTL conversions #39396

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft

Conversation

videlec
Copy link
Contributor

@videlec videlec commented Jan 27, 2025

We implement C conversions between pari and NTL for

  • integers
  • finite fields
  • univariate polynomials over the above

One of the goal is to make faster the coercion from the base ring with polynomials with coefficients in GF(p^e)

sage: p = random_prime(2**256)
sage: F.<i> = GF(p^2)
sage: R.<x> = PolynomialRing(F)
sage: a = F.random_element()
sage: %timeit R(a)
14.7 μs ± 727 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

📝 Checklist

  • I have linked a relevant issue or discussion.
  • I have updated the documentation and checked the documentation preview.

Copy link

github-actions bot commented Jan 27, 2025

Documentation preview for this PR (built with commit 6c6f5ab; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@user202729
Copy link
Contributor

user202729 commented Jan 29, 2025

You should run tools/update-meson.py. Running it results in the following patch:

diff --git a/src/sage/data_structures/meson.build b/src/sage/data_structures/meson.build
index 8c100328378..3cc243fe62a 100644
--- a/src/sage/data_structures/meson.build
+++ b/src/sage/data_structures/meson.build
@@ -42,9 +42,7 @@ foreach name, pyx : extension_data
   )
 endforeach
 
-extension_data_cpp = {
-  'pairing_heap' : files('pairing_heap.pyx'),
-}
+extension_data_cpp = {'pairing_heap' : files('pairing_heap.pyx')}
 
 foreach name, pyx : extension_data_cpp
   py.extension_module(
diff --git a/src/sage/libs/pari/meson.build b/src/sage/libs/pari/meson.build
index 5952060267c..a7bf079ffbe 100644
--- a/src/sage/libs/pari/meson.build
+++ b/src/sage/libs/pari/meson.build
@@ -3,6 +3,7 @@ py.install_sources(
   'all.py',
   'convert_flint.pxd',
   'convert_gmp.pxd',
+  'convert_ntl.pxd',
   'convert_sage.pxd',
   'convert_sage_complex_double.pxd',
   'convert_sage_real_double.pxd',
@@ -21,6 +22,7 @@ extension_data = {
   'convert_sage_real_double' : files('convert_sage_real_double.pyx'),
   'convert_sage_real_mpfr' : files('convert_sage_real_mpfr.pyx'),
   'misc' : files('misc.pyx'),
+  'convert_ntl' : files('convert_ntl.pyx'),
 }
 
 foreach name, pyx : extension_data

also,

  • is this sufficiently faster than round-tripping to SageMath's ZZ (which it uses mpz under the hood anyway?)
  • where is the sig_off()?

@videlec
Copy link
Contributor Author

videlec commented Jan 29, 2025

Thanks for your comments. I did update the meson configuration files.

Concerning conversion via ZZ the aim is precisely to avoid the creation of any Python objects. Note that the current branch is just experimental. One should not go via gmp at all when converting from pari to NTL.

Concerning sig_off it is in the new_gen function in cypari2 (stack.pyx)

cdef Gen new_gen(GEN x):
    """
    Create a new ``Gen`` from a ``GEN``. Except if `x` is ``gnil``, then
    return ``None`` instead.

    Also call ``sig_off``() and clear the PARI stack.
    """
    sig_off()
    if x is gnil:
        reset_avma()
        return None
    return new_gen_noclear(x)

@videlec videlec marked this pull request as draft January 29, 2025 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants