-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces.tex
21 lines (13 loc) · 3.04 KB
/
interfaces.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\section{Interface with compiled languages}
\label{sec:interface}
While we promote the advantages of Python as a numerical computing language, we also recognize the tremendous value and expertise already present in mature, battle-tested programs and libraries. In fact, the scientific Python community is the best example of how to combine both compiled and interpreted languages: since the very beginning, many Python libraries were written as wrappers to old FORTRAN or C++ code, using tools like f2py and SWIG (discussed below)\cite{Millman_2011}. It is therefore our intention to build on Python for new code and at the same time take advantage of available libraries written in different languages to avoid duplicating efforts.
\subsection{C and C++: ctypes, Cython, SWIG, CFFI}
Because of its historical importance and the fact that CPython, the reference Python implementation, is written in C, there are many projects that serve to communicate Python and C.
\subsection{Fortran: f2py}
Although we could use an intermediate C wrapper to easily call Fortran code using the ISO C binding capabilities introduced in version 2003, there is no reliable way of doing this with Fortran 95 and earlier due to the lack of standardization. To solve this problem, specially for FORTRAN 77 code, the \verb|f2py| project was created in the early days of the scientific Python community, which wraps FORTRAN 77 and a subset of Fortran 95 directly in Python\cite{peterson2009f2py}.
\subsection{Others: Java, MATLAB}
As we already said for the Fortran case, once we have solved the problem of the interoperability with C we could easily write intermediate wrappers to many other languages, as C is \textit{lingua franca} in the computing world. Fo the case of Java and MATLAB there are some tools that can help the developers with some parts of the process.
\begin{itemize}
\item To call Java libraries from Python programs one of the most visible options is \verb|JCC| (\url{http://lucene.apache.org/pylucene/jcc/}). According to its website, \verb|JCC| is "a C++ code generator that produces a C++ object interface wrapping a Java library via Java's Native Interface (JNI)". Besides, "\verb|JCC| also generates C++ wrappers that conform to Python's C type system making the instances of Java classes directly available to a Python interpreter". It is successfully used by the Orekit Python wrapper, which allows using the Orekit Java library from a Python program.
\item Regarding the MATLAB environment, the most modern alternative is \verb|pymatbridge| (\url{https://arokem.github.io/python-matlab-bridge/}), a communication layer between MATLAB and Python based on the \verb|ZeroMQ| socket library\cite{hintjens2013zeromq}. An equivalent tool for the GNU Octave project\cite{eaton1997gnu}, which allows running MATLAB-like programs using only free software, is \verb|oct2py| (\url{https://github.com/blink1073/oct2py}). The latter had been successfully tested in poliastro 0.1 before the Octave code was replaced by Fortran subroutines\footnote{https://github.com/poliastro/poliastro/tree/0.1.x}.
\end{itemize}