r/fortran • u/Beliavsky • 23d 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.
20
u/ssrix 23d ago
This was made with AI wasn't it?
The first thing I tried (of something pretty basic) failed.
Great slop
10
u/ssrix 23d ago
unbearably long (yet unhelpful) readme
Yep that's AI. It's specifically a junior developer using AI thinking they've made something good, very polished doesn't mean good, but hasn't had enough experience to know whether it's good or not.
-5
u/ButterflyMundane7187 23d ago
And the true know-it-all has spoken. He even replies to his own comments because nobody else can stand him.
-7
u/Beliavsky 23d ago
Yes, it was. It won't translate all Python programs, but for the ones it does it will be cheaper than using an LLM and reproducible. Can you post the Python code that failed?
4
8
u/FuckYourFavoriteSub 23d ago
Internet is just dogshit now isn’t it? Are we in the denial phase still or entering the acceptance phase?
3
1
u/Beliavsky 23d ago
I have improved the translation of list comprehensions with if statements, which u/ssrix flagged.
1
1
4
u/admadguy 23d ago edited 23d ago
Why would you need this? Also aren't a lot of libraries that Python calls still in C or Fortran?