多精度Python库可以与boost :: multiprecision或其他选项配合使用吗? [英] Multiprecision Python library that plays well with boost::multiprecision or other options?

查看:155
本文介绍了多精度Python库可以与boost :: multiprecision或其他选项配合使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个围绕多精度复杂"数字的项目,特别是基于Mandelbrot Set的应用程序,但是需要一个(快速的)C ++ py扩展模块(提升, cython或其他...)以及可能要使用它的纯python模块.

现在,我正在使用boost :: multiprecision来包装MPFR原始类型,是的,如果我只是想将mpfr_t传递给python,那将是一回事.但是,对于这个应用程序,我需要将C ++模块的结果存储为字符串,稍后将由Python模块对其进行解释,并且需要提供相同的数字.

BigFloat应该是MPFR python包装器,但它并不能像boost :: multiprecision的data()方法一样完全解释X精度浮点数的字符串常量./p>

是否有人知道库的组合以及 会导致C ++和任意精度浮点数的Python字符串文字之间的确切对应关系的方法?

如果需要,我可以提供代码摘录来说明问题,但他认为这很神秘,以至于如果有人得到答案,他们就会确切地知道我的意思以及如何解决.

解决方案

我维护 gmpy2 这是MPFR和MPC(以及GMP)的Python包装器.如果您可以提供示例,我可能会提供帮助.

I am working on a project that revolves around multiprecision "complex" numbers, specifically it's a Mandelbrot Set-based app, but with a twist that requires decent correspondence between the output of a (fast) C++ py extension module (boost, cython, or other...) and the pure python modules that might want to use it.

Right now, I'm using boost::multiprecision to wrap the MPFR raw type, and yeah if I just wanted to pass an mpfr_t to python that'd be one thing. However, for this app I need to store the C++ module's result as a string which will be interpreted later by a Python module, and needs to give the same number.

BigFloat is supposed to be an MPFR python wrapper, but it doesn't interpret a string literal of an X-precision float exactly the same way as boost::multiprecision's data() method.

Does anybody know of a combination of libraries plus an approach that does result in an exact correspondence between C++ and Python string literals of arbitrary-precision floating-point numbers?

I can provide code excerpts if needed to illustrate the problem, but figured it was arcane enough that if anybody had the answer, they'd know exactly what I mean and how to fix it.

解决方案

I maintain gmpy2 which is a Python wrapper for both MPFR and MPC (and GMP). If you can provide an example, I may be able to help.

这篇关于多精度Python库可以与boost :: multiprecision或其他选项配合使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆