param icon indicating copy to clipboard operation
param copied to clipboard

Upgrade gmpy support to gmpy2

Open maximlt opened this issue 3 years ago • 0 comments

gmpy is on longer maintained, in favor of gmpy2:

GMPY and GMPY2 are C-coded Python extension modules that support fast multiple-precision arithmetic.

GMPY only supports the GMP library and provides fast multiple-precision integer and rational arithmetic. The limited mpf type from GMP is also supported. GMPY is no longer being maintained.

GMPY2 supports the GMP library for integer and rational arithmetic but GMPY2 adds support for multiple-precision real and complex arithmetic as provided by the MPFR and MPC libraries. GMPY2 is being actively developed.

In https://github.com/holoviz/param/pull/658 (https://github.com/holoviz/param/pull/658/commits/c08ea2640a7e7ca2bb6bb34def1e99e80564e7e7) I attempted to simply replace all the gmpy imports by gmpy2 imports. On Linux there was a failing test and some warnings:

   __________ TestTimeDependentDynamic.test_time_hashing_rationals_gmpy2 __________
  
  self = <tests.API1.testtimedependent.TestTimeDependentDynamic testMethod=test_time_hashing_rationals_gmpy2>
  
      @pytest.mark.skipif(gmpy2 is None, reason="gmpy2 is not installed")
      def test_time_hashing_rationals_gmpy2(self):
          """
          Check that hashes of fractions and gmpy2 mpqs match for some
          reasonable rational numbers.
          """
          pi = "3.141592"
          hashfn = numbergen.Hash("test", input_count=1)
          self.assertEqual(hashfn(0.5), hashfn(gmpy2.mpq(0.5)))
  >       self.assertEqual(hashfn(pi), hashfn(gmpy2.mpq(3.141592)))
  E       AssertionError: 238769760 != 243050811
  
  tests/API1/testtimedependent.py:317: AssertionError
  ----------------------------- Captured stderr call -----------------------------
  WARNING:param.main: Casting type 'float' to Fraction.fraction
  WARNING:param.main: Casting type 'mpq' to Fraction.fraction
  WARNING:param.main: Casting type 'str' to Fraction.fraction
  WARNING:param.main: Casting type 'mpq' to Fraction.fraction
  ------------------------------ Captured log call -------------------------------
  WARNING  param.main:parameterized.py:2529 Casting type 'float' to Fraction.fraction
  WARNING  param.main:parameterized.py:2529 Casting type 'mpq' to Fraction.fraction
  WARNING  param.main:parameterized.py:2529 Casting type 'str' to Fraction.fraction
  WARNING  param.main:parameterized.py:2529 Casting type 'mpq' to Fraction.fraction

Also at the time I tried it it wouldn't install on Linux/Python 3.11 and fail with:

        In file included from src/gmpy2.c:500:
        src/gmpy2.h:82:10: fatal error: mpfr.h: No such file or directory
           82 | #include <mpfr.h>
              |          ^~~~~~~~
        compilation terminated.
        error: command '/usr/bin/gcc' failed with exit code 1
        [end of output]

maximlt avatar Nov 18 '22 11:11 maximlt