Efficiently passing gmpy2 arbitrary precision numbers from Python to C++ functions exposed via PyBind11 #5061
Unanswered
wanfuse123
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm developing a project that necessitates seamless interaction between Python and C++, specifically for executing advanced arithmetic operations, including addition, subtraction, multiplication, division, exponentiation, and logarithms, on arbitrary precision numbers. I have chosen gmpy2 for its arbitrary precision capabilities in Python and am using PyBind11 to bind my C++ code to Python. Part of the project involves implementing root finding algorithms, where precision is paramount.
Environment:
OS: Debian 12 (bookworm)
Python Version: 3.11.2
PyBind11 Version: (Please add your version here)
gmpy2 Version: 2.1.5
GCC Version: (Debian 12.2.0-14) 12.2.0
The core of my query is about best practices for interfacing gmpy2's arbitrary precision numbers with C++ via PyBind11, especially for the operations mentioned. The challenges I'm facing include:
Efficiently passing gmpy2 arbitrary precision numbers from Python to C++ functions exposed via PyBind11.
Conducting precise arithmetic and root finding calculations in C++ and ensuring that the precision and speed of operations such as exponentiation and logarithms is maintained.
Returning the results to Python without losing precision, ensuring the integrity of the numbers for further computations.
I'm looking for guidance, examples, or references on how to effectively bridge gmpy2 and PyBind11 for these purposes. Insights into handling high-precision arithmetic operations across Python and C++ would be invaluable.
Thank you for your assistance and expertise.
Beta Was this translation helpful? Give feedback.
All reactions