Skip to main content

Just-in-time Fortran extension builder for Python

Project description

f2py-jit

pypi version license Binder pipeline status coverage report

Just-in-time compilation of Fortran code in Python via f2py.

Check out the documentation for full details.

Quick start

Start from a piece of Fortran code.f90

subroutine hello()
  print*, "Hello world!"
end subroutine

Compile the code, import it and execute it

from f2py_jit import jit
f90 = jit('code.f90')
f90.hello()

Do the same but from a python string containing the source block

source = """
subroutine hello()
  print*, "Hello world!"
end subroutine
"""
f90 = jit(source)
f90.hello()

If the Fortran source contains multiple subroutines calling each other, f2py will not perform interprocedural optimizations (at least not by default). f2py_jit can inline the source code before compiling it, and you will get a performace boost [This feature is experimental]

f90 = jit('code.f90', inline=True)

Features

  • Compilation of Fortran source blocks as Python strings
  • Caching of module builds across executions
  • Support for Fortran derived types via f90wrap
  • Inlining to improve performance (experimental)

Dependencies

  • numpy
  • Fortran compiler (ex. gfortran)

The package currently supports Python versions from 3.7 to 3.13.

Note that Python versions >= 3.12 will use the meson backend to build Fortran extensions, which has slower build times than distutils (used by default in versions < 3.12).

Installation

From pip

pip install f2py-jit

To install the package with support for derived types (courtesy of f90wrap

pip install f2py-jit[types]

Note that this requires Python >= 3.8.

From source

git clone https://framagit.org/coslo/f2py-jit.git
cd f2py_jit
pip install .

Credits

Part of this code is adapted from numpy.f2py module by Pearu Peterson, in accordance with the NumPy license.

Authors

Daniele Coslovich: https://www.units.it/daniele.coslovich/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

f2py_jit-1.2.1.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

f2py_jit-1.2.1-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file f2py_jit-1.2.1.tar.gz.

File metadata

  • Download URL: f2py_jit-1.2.1.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for f2py_jit-1.2.1.tar.gz
Algorithm Hash digest
SHA256 d1688c449d3ee850d9d109aa9c4f7fac491f21e59e265ea33e841fae5a9e5a97
MD5 b8dae74edc37a61c6f6cd811bacff05e
BLAKE2b-256 2a2f1a5f39e5126f9cfd67efa345686e991daeaef4f11f113e2a0f92dcd02e7e

See more details on using hashes here.

File details

Details for the file f2py_jit-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: f2py_jit-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for f2py_jit-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35c1a2a1dfa127b779a1ce0355125483945064cd4fd6f9ee11a53e897282f25e
MD5 ebad32d748c17e59fb56e3a21752d6ac
BLAKE2b-256 31a301ca0745765b5dd415f2a0feebcd45ed31e6233d40502a010e0131bd3dec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page