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

check for __mpz__ and __mpq__ in New #134

merged 1 commit into from May 18, 2017


Copy link

videlec commented May 17, 2017

This would allow any object to implement their own conversion to gmpy2. The branch just make gmpy2.mpz(a) so that it calls a.__mpz__() when the method exists (and similar for mpq). With the branch applied one can do

>>> class A:
...    def __mpz__(self):
...        import gmpy2
...        return gmpy2.mpz('42')
...    def __mpq__(self):
...        import gmpy2
...        return gmpy2.mpq('13/12')
>>> import gmpy2
>>> gmpy2.mpq(A())
>>> gmpy2.mpz(A())

(fixes issue #123)


This comment has been minimized.

Copy link

casevh commented May 18, 2017


Slightly related question... When would you like me to release a 2.1 alpha release?


This comment has been minimized.

Copy link
Contributor Author

videlec commented May 18, 2017

This is on your side! But for me: as soon as possible!

Vincent K. has worked hard to experiment the integration in SageMath (see ticket 22927 and ticket 22928). What we are missing:

  • direct constructors GMPy_MPZ_From_mpz, GMPy_MPQ_From_mpq, GMPy_MPQ_From_mpz
  • a gmpy2.pxd file with relevant declarations (to be installed at the same place as gmpy2.h)
  • #136 robust header detection (ie what should the user do in her to find out where gmpy2.h/gmpy2.pxd are?)
@videlec videlec deleted the videlec:constructor branch May 18, 2017

This comment has been minimized.

Copy link

casevh commented May 19, 2017

I would like to get an alpha release of 2.1 out soon. Most of the changes between 2.0 and 2.1 are related to support for thread-specific contexts instead of a global context. The mpz and mpq related code hasn't changed much. So while I expect bugs with mpfr and mpc, it should be reasonably stable for mpz and mpq.

I'll review your PR and commit it assuming it looks reasonable. (I'm travelling so my abilities to test are limited.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.