Skip to content

Commit 8ee4592

Browse files
committed
DOC: Reword f2py docs
1 parent 6caae88 commit 8ee4592

File tree

7 files changed

+607
-551
lines changed

7 files changed

+607
-551
lines changed

doc/source/f2py/advanced.rst

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
======================
2-
Advanced F2PY usages
3-
======================
1+
========================
2+
Advanced F2PY use cases
3+
========================
44

5-
Adding self-written functions to F2PY generated modules
6-
=======================================================
5+
Adding user-defined functions to F2PY generated modules
6+
=========================================================
77

8-
Self-written Python C/API functions can be defined inside
8+
User-defined Python C/API functions can be defined inside
99
signature files using ``usercode`` and ``pymethoddef`` statements
1010
(they must be used inside the ``python module`` block). For
1111
example, the following signature file ``spam.pyf``
@@ -17,32 +17,30 @@ wraps the C library function ``system()``::
1717

1818
f2py -c spam.pyf
1919

20-
In Python:
20+
In Python this can then be used as:
2121

22-
.. include:: ./code/results/spam_session.dat
23-
:literal:
24-
25-
Modifying the dictionary of a F2PY generated module
26-
===================================================
22+
.. literalinclude:: ./code/results/spam_session.dat
23+
:language: python
2724

28-
The following example illustrates how to add user-defined
29-
variables to a F2PY generated extension module. Given the following
30-
signature file
25+
Adding user-defined variables
26+
==============================
3127

32-
.. include:: ./code/var.pyf
33-
:literal:
28+
The following example illustrates how to add user-defined variables to a F2PY
29+
generated extension module by modifying the dictionary of a F2PY generated
30+
module. Consider the following signature file (compiled with ``f2py -c var.pyf``):
3431

35-
compile it as ``f2py -c var.pyf``.
32+
.. literalinclude:: ./code/var.pyf
33+
:language: fortran
3634

3735
Notice that the second ``usercode`` statement must be defined inside
38-
an ``interface`` block and where the module dictionary is available through
39-
the variable ``d`` (see ``f2py var.pyf``-generated ``varmodule.c`` for
36+
an ``interface`` block and the module dictionary is available through
37+
the variable ``d`` (see ``varmodule.c`` generated by ``f2py var.pyf`` for
4038
additional details).
4139

42-
In Python:
40+
Usage in Python:
4341

44-
.. include:: ./code/results/var_session.dat
45-
:literal:
42+
.. literalinclude:: ./code/results/var_session.dat
43+
:language: python
4644

4745

4846
Dealing with KIND specifiers
@@ -70,7 +68,7 @@ Use the ``--f2cmap`` command-line option to pass the file name to F2PY.
7068
By default, F2PY assumes file name is ``.f2py_f2cmap`` in the current
7169
working directory.
7270

73-
Or more generally, the f2cmap file must contain a dictionary
71+
More generally, the f2cmap file must contain a dictionary
7472
with items::
7573

7674
<Fortran typespec> : {<selector_expr>:<C type>}
@@ -79,7 +77,7 @@ that defines mapping between Fortran type::
7977

8078
<Fortran typespec>([kind=]<selector_expr>)
8179

82-
and the corresponding <C type>. <C type> can be one of the following::
80+
and the corresponding <C type>. The <C type> can be one of the following::
8381

8482
char
8583
signed_char
@@ -94,4 +92,4 @@ and the corresponding <C type>. <C type> can be one of the following::
9492
complex_long_double
9593
string
9694

97-
For more information, see F2Py source code ``numpy/f2py/capi_maps.py``.
95+
For more information, see the F2Py source code ``numpy/f2py/capi_maps.py``.

doc/source/f2py/distutils.rst

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ Using via `numpy.distutils`
44

55
.. currentmodule:: numpy.distutils.core
66

7-
:mod:`numpy.distutils` is part of NumPy extending standard Python ``distutils``
8-
to deal with Fortran sources and F2PY signature files, e.g. compile Fortran
9-
sources, call F2PY to construct extension modules, etc.
7+
:mod:`numpy.distutils` is part of NumPy; and extends the standard Python
8+
``distutils`` module to deal with Fortran sources and F2PY signature files, e.g.
9+
compile Fortran sources, call F2PY to construct extension modules, etc.
1010

1111
.. topic:: Example
1212

13-
Consider the following `setup file`__:
13+
Consider the following `setup file`__ for the ``fib`` examples in the previous
14+
section:
1415

1516
.. literalinclude:: ./code/setup_example.py
1617
:language: python
@@ -26,30 +27,32 @@ sources, call F2PY to construct extension modules, etc.
2627

2728
__ setup_example.py
2829

30+
Extensions to ``distutils``
31+
===========================
32+
2933
:mod:`numpy.distutils` extends ``distutils`` with the following features:
3034

3135
* :class:`Extension` class argument ``sources`` may contain Fortran source
3236
files. In addition, the list ``sources`` may contain at most one
33-
F2PY signature file, and then the name of an Extension module must
34-
match with the ``<modulename>`` used in signature file. It is
37+
F2PY signature file; in this case, the name of an Extension module must
38+
match with the ``<modulename>`` used in signature file. It is
3539
assumed that an F2PY signature file contains exactly one ``python
3640
module`` block.
3741

38-
If ``sources`` does not contain a signature files, then F2PY is used
39-
to scan Fortran source files for routine signatures to construct the
40-
wrappers to Fortran codes.
42+
If ``sources`` do not contain a signature file, then F2PY is used to scan
43+
Fortran source files to construct wrappers to the Fortran codes.
4144

42-
Additional options to F2PY process can be given using :class:`Extension`
43-
class argument ``f2py_options``.
45+
Additional options to the F2PY executable can be given using the
46+
:class:`Extension` class argument ``f2py_options``.
4447

4548
* The following new ``distutils`` commands are defined:
4649

4750
``build_src``
4851
to construct Fortran wrapper extension modules, among many other things.
4952
``config_fc``
50-
to change Fortran compiler options
53+
to change Fortran compiler options.
5154

52-
as well as ``build_ext`` and ``build_clib`` commands are enhanced
55+
as well as ``build_ext`` and ``build_clib`` commands which are also enhanced
5356
to support Fortran sources.
5457

5558
Run
@@ -60,14 +63,14 @@ sources, call F2PY to construct extension modules, etc.
6063

6164
to see available options for these commands.
6265

63-
* When building Python packages containing Fortran sources, then one
64-
can choose different Fortran compilers by using ``build_ext``
66+
* When building Python packages containing Fortran sources, one
67+
can choose different Fortran compilers by using the ``build_ext``
6568
command option ``--fcompiler=<Vendor>``. Here ``<Vendor>`` can be one of the
6669
following names::
6770

6871
absoft sun mips intel intelv intele intelev nag compaq compaqv gnu vast pg hpux
6972

70-
See ``numpy_distutils/fcompiler.py`` for up-to-date list of
73+
See ``numpy_distutils/fcompiler.py`` for an up-to-date list of
7174
supported compilers or run
7275

7376
::

0 commit comments

Comments
 (0)