2021年4月6日星期二

Is there a way to pass arbitrary precision numbers between fortran and python?

I am currently writing a program that is heavy on finite differencing. The problem is that to get the accuracy I'd need, I need to use arbitrary precision arithmetic. I have a purely Python script that does the job, but it's rather slow so I'm thinking of passing the task of calculating the finite differences to a compiled Fortran code.

The current implementation I'm working on is that I use SymPy and mpmath to generate multiple precision initial data in Python, save it on some text file that then gets read by F2PY'd Fortran code, who then does most of the work in arbitrary precision. Fortran saves the data in some other file, and Python reads it for some post-processing.

It would be useful to me if I can just freely pass arbitrary precision numbers between Fortran and Python, instead of going through the trouble of reading and writing multiple precision data. If this is possible with other languages instead, like C, I'd be interested to know also. Or maybe there's a better way to do this?

https://stackoverflow.com/questions/66978517/is-there-a-way-to-pass-arbitrary-precision-numbers-between-fortran-and-python April 07, 2021 at 09:45AM

没有评论:

发表评论