Skip to content

Conversation

remyoudompheng
Copy link
Contributor

@remyoudompheng remyoudompheng commented Mar 20, 2023

📚 Description

Native implementations in FLINT/NTL can outperform the generic Python implementation by up to 2x-3x depending on argument size.
In the case of the NTL implementation, composite moduli are already using the NTL functions.

📝 Checklist

  • I have made sure that the title is self-explanatory and the description concisely explains the PR.
  • I have linked an issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

Comment on lines 529 to 548
def _powmod(ntl_ZZ_pX self, n, ntl_ZZ_pX modulus):
"""
Compute the n-th power of self modulo a polynomial.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _powmod(ntl_ZZ_pX self, n, ntl_ZZ_pX modulus):
"""
Compute the n-th power of self modulo a polynomial.
cdef _powmod(ntl_ZZ_pX self, n, ntl_ZZ_pX modulus):
"""
Compute the n-th power of self modulo a polynomial.

although with making it a cdef, you would remove the doctests explicitly calling the method.

@remyoudompheng
Copy link
Contributor Author

Rebased on 10.0beta6

  • the ZZ_pEX were missing from the patch and are added in this version
  • the tests were incomplete regarding how coercions are handled and at least one method was not checking parents correctly so an attempt is made at handling this

@remyoudompheng
Copy link
Contributor Author

There is currently no way to specify that an implementation provide a specific __pow__ with 3 arguments where the exponent is an Integer. The generic Polynomial.__pow__ should probably handle that to avoid duplicating the coercion code. Or maybe some variant of the coercion_binop decorator.

Native implementations in FLINT/NTL can outperform the generic
Python implementation by up to 2x-3x depending on argument size.

In the case of the NTL implementation, only composite moduli
were using the NTL functions.
@GiacomoPope
Copy link
Contributor

@tscrim I noticed last night that we don't have NTL bindings for big integer exponents and was about to write my own patches but found this.

What's the status on your review here? It seemed like everything was done? Can I support you in getting this ready?

@tscrim
Copy link
Collaborator

tscrim commented Feb 23, 2024

@GiacomoPope @remyoudompheng Sorry, I lost track of this.

@GiacomoPope There are still methods that need doctests, but really they just need to be changed to cdef since they are internal and low-level.

It also seems to need a rebase. That might be it though.

From @remyoudompheng's last comment, I am not sure. It could make sense to take the modulus in some other ring that differs from self (say, something only supports modulus for base ring coefficients), but that is highly unlikely. A helper function would likely be the best course of action here to avoid duplication, but we can leave it for now since it is not currently used frequently.

@GiacomoPope
Copy link
Contributor

GiacomoPope commented Feb 23, 2024

I'm not sure Remy has much time to work on this so maybe I can make a PR to his branch and go from there. If I understand correctly that would then just require remy to accept my PR and it would automatically update here?

Do you have permissions to rebase from develop here, or should I do that locally?

@tscrim
Copy link
Collaborator

tscrim commented Feb 23, 2024

I'm not sure Remy has much time to work on this so maybe I can make a PR to his branch and go from there. If I understand correctly that would then just require remy to accept my PR and it would automatically update here?

That is one way to do it, where you do a PR on Remy's fork. The other option is to just create a separate PR and close this one afterwards (assuming Remy doesn't push anything further).

Do you have permissions to rebase from develop here, or should I do that locally?

Unless you have superpowers, you can't push to the branch here. (I strongly dislike this part of github.) I do have the power to push here, so I could push your branch as a final option (although I feel this is the most complicated one).

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.

5 participants