Questions tagged [gmpy]

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. GMPY2 adds support for fast, correctly rounded multiple-precision real and complex arithmetic.

About

GMPY is a legacy Python module that provides access to the GNU Multiple Precision (GMP) libary. GMP provides very fast and highly optimized routines for working with arbitrary precision integers (MPZ), rationals (MPQ), and (very limited) floating point numbers (MPF).

GMPY2 is the actively maintained replacement for GMPY. The limited floating point support from the GMP library has been replaced with correctly-rounded real arithmetic from the MPFR library. Correctly-rounded complex arithmetic from the MPC library is also available.

Links

73 questions
1
vote
1 answer

Python multi-precision rational comparison: Fraction, mpq and mpfr

I understand that floating-point calculation is not accurate due to its nature. I'm trying to find out the best library/way to do multi-precision ration comparison. I'm comparing Fraction, mpq and mpfr. The later two are from gmpy2 library. The…
pythonician_plus_plus
  • 1,244
  • 3
  • 15
  • 38
1
vote
2 answers

Efficiently convert gmpy2.mpz to numpy boolean array

I try to convert from gmpy2.mpz to a numpy boolean array, but can't quite get it right. (gmpy2: https://gmpy2.readthedocs.io) import gmpy2 import numpy as np x = gmpy2.mpz(int('1'*1000,2)) print("wrong conversion 1") y =…
rxu
  • 1,369
  • 1
  • 11
  • 29
1
vote
1 answer

Is this a bug in python's gmpy2?

A simple floating-point addition x+y in with precision 4 (i.e. IEEE mantissa width 3), with 3 bits for exponent (emax=3, emin=-4) for x = mpfr('0.75'), y = mpfr('0.03125') incorrectly gives mpfr('0.75') as result when it should be mpfr('0.8125').…
user1779685
  • 283
  • 2
  • 8
1
vote
1 answer

Python: reduced row echelon form (mod p) of a very large matrix

I want to find find a reduced a row echelon form (in field F_q) of a big matrix. I tried the following code. Although I used gmpy2 library to speed up, the program was still out of memory. because my input matrix is very large (100 x 2^15) and p is…
santa
  • 193
  • 10
1
vote
3 answers

Efficient multiple precision numerical arrays

Numpy is a library for efficient numerical arrays. mpmath, when backed by gmpy, is a library for efficient multiprecision numbers. How do I put them together efficiently? Or is it already efficient to just use a Numpy array with mpmath numbers? It…
leewz
  • 3,201
  • 1
  • 18
  • 38
1
vote
1 answer

GMPY2 install: DLL load failed: %1 is not a valid Win32 application

I tried to install gmpy2 on my python distribution (Anaconda 64bit) and I did this by downloading the precompiled .PYD file from http://www.lfd.uci.edu/~gohlke/pythonlibs and put the file in the site-packages folder (I tried this with both the 32…
Hadi Khan
  • 577
  • 2
  • 8
  • 30
1
vote
1 answer

Sympy polynomials with `mpfr` coefficients?

I want to use Sympy's polynomials, but I also want to use higher-precision coefficients. Just Doing It seems to give me polynomials with sympy.core.numbers.float coefficients. import sympy from sympy import Poly from sympy.abc import x from gmpy2…
leewz
  • 3,201
  • 1
  • 18
  • 38
1
vote
1 answer

How do I make gmpy array operations faster?

I've been having trouble with speed while trying to utilise the gmpy module. import numpy as np import gmpy2 as gm N = 1000 a = range(N) %timeit [gm.sin(x) for x in a] # 100 loops, best of 3: 7.39 ms per loop %timeit np.sin(a) # 10000 loops, best of…
evan54
  • 3,585
  • 5
  • 34
  • 61
1
vote
1 answer

python bigfloat installation issues

My Problem is similar to this poster and I'm using a MAC OsX 10.9.5 version: python 'bigfloat' package installation issues When I try to install the "mpc-1.0.2" package, it doesn't compile and gives this error: grep: /home/case/local/lib/libgmp.la:…
ML_Passion
  • 1,031
  • 3
  • 15
  • 33
1
vote
1 answer

how to install gmpy2 error: ‘MPFR_RNDU’ undeclared (first use in this function)

I install gmpy2 like this: yum install gmp-devel yum install mpfr-devel yum install libmpc-devel but show these errors: src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘real_round’ src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no…
Young Pan
  • 11
  • 1
  • 2
1
vote
3 answers

Is MPFR division faster than native integer division?

I've always made the assumption that integer division was faster than floating point division, but I did some tests that seemed to prove otherwise. import gmpy2, time, math digits = 100000 scale = 10**digits # Decimal…
qwr
  • 9,525
  • 5
  • 58
  • 102
0
votes
0 answers

Using Conda environment in Matlab on Windows (import DLL error)

The conda environment with numpy and gmpy2 packages was created using conda create --name py4mat python=3.9 numpy gmpy2 Created environment was tested using PS C:\_users\rad> conda activate py4mat (py4mat) PS C:\_users\rad> python Python 3.9.16 |…
rad
  • 157
  • 1
  • 9
0
votes
2 answers

Is there a more elegant way to read a Textfile containing mpz values into a list of integers?

I have a Textfile containing numbers that looks as follows: [mpz(0), mpz(0), mpz(0), mpz(0), mpz(4), mpz(54357303843626),...] Does there exist a simple way to parse it directly into an integer list? It doesn't matter whether the target data type is…
Eldar Sultanow
  • 205
  • 2
  • 9
0
votes
1 answer

Cannot open include file: 'gmp.h': No such file or directory (Python/Cython)

I was learning how to integrate gmpy2 with Cython. From the docs, I was provided with an example code. Since I am not really sure about what was going on, I felt that I can learn how to use gmpy in Cython by playing with the example code…
chdy
  • 11
  • 3
0
votes
1 answer

Generating random number of N-digits using gmpy2 library in Python

I want to generate a random number of N-digits using gmpy2 library in Python. I know that it is possible to do this using random library, but using gmpy2 is a requirement. mpz_random() function generates a random number from 0 to N-1. I am not sure…