r/fortran • u/Beliavsky • 19d ago
Python to Fortran transpiler
At https://beliavsky.github.io/python-to-fortran-playground/run/ you can translate Python with NumPy to Fortran and run both codes. The transpiler used, which is in Python and which you can run locally, is at https://github.com/beliavsky/python-to-fortran
Fortran is a practical target for numerical Python: it combines native compilation with multidimensional arrays, whole-array expressions, array sections, and explicit procedure interfaces. Some translated programs run much faster, as discussed at https://github.com/Beliavsky/Python-to-Fortran/blob/main/TIMING_RESULTS.md
Pyccel https://github.com/pyccel/pyccel is a more established project that generates Fortran, C, or C++ extension modules from Python code with type annotations, which my project does not require.
4
u/admadguy 18d ago edited 18d ago
Why would you need this? Also aren't a lot of libraries that Python calls still in C or Fortran?
20
u/ssrix 19d ago
This was made with AI wasn't it?
The first thing I tried (of something pretty basic) failed.
Great slop
8
u/FuckYourFavoriteSub 19d ago
Internet is just dogshit now isn’t it? Are we in the denial phase still or entering the acceptance phase?
1
u/Beliavsky 19d ago
I have improved the translation of list comprehensions with if statements, which u/ssrix flagged.
1
u/Barnowl93 12d ago
I don't understand why i wouldn't have a pytnon wrapper for Fortran?
1
u/keithstellyes 12d ago
Cython but slop?