Skip to content
GitLab
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • lfortranlfortran
  • lfortranlfortran
  • Issues
  • #44

Bridge to Python and other languages

Use the approach explained here: https://eli.thegreenplace.net/2015/calling-back-into-python-from-llvmlite-jited-code/ to bridge with Python.

The syntax from Fortran side should be (thanks to @nncarlson for the suggestion):

use, external(python) :: numpy, only: sin
print *, sin(5)

For plotting, without lfortran knowing anything about matplotlib:

use, external(python) :: pylab, only: plot, savefig
call plot([1, 2, 3], [1, 2, 1])
call savefig("someplot.pdf")

For nested Python modules, we need some syntax to do that, here are three suggestions:

use, external(python) :: numpy.linalg, only: cholesky
use, external(python) :: numpy:linalg, only: cholesky
use, external(python) :: numpy%linalg, only: cholesky

Essentially this boils down to allowing Fortran modules to be nested (by convincing the Fortran committee to), and then reuse the syntax for that (whatever syntax the committee agrees upon).

Calling C++ could be something along the lines:

use, external(cpp) :: xtensor, only: sin

Calling C would be (see #48 for details):

use, external(c) :: math, only: sin
print *, sin(5._dp)
Edited Dec 05, 2018 by Ondřej Čertík
Assignee
Assign to
Time tracking