Skip to content

Commit

Permalink
WIP: BLD: use a generator for f2py
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommers committed Apr 29, 2024
1 parent e15716b commit 86c5922
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 100 deletions.
32 changes: 4 additions & 28 deletions scipy/integrate/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,8 @@ py3.extension_module('_odepack',
subdir: 'scipy/integrate'
)

vode_module = custom_target('vode_module',
output: ['_vode-f2pywrappers.f', '_vodemodule.c'],
input: 'vode.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_vode',
vode_module,
f2py_gen.process('vode.pyf'),
link_with: [vode_lib],
c_args: [Wno_unused_variable],
link_args: version_link_args,
Expand All @@ -145,14 +139,8 @@ py3.extension_module('_vode',
subdir: 'scipy/integrate'
)

lsoda_module = custom_target('lsoda_module',
output: ['_lsoda-f2pywrappers.f', '_lsodamodule.c'],
input: 'lsoda.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_lsoda',
lsoda_module,
f2py_gen.process('lsoda.pyf'),
link_with: [lsoda_lib, mach_lib],
c_args: [Wno_unused_variable],
dependencies: [lapack_dep, fortranobject_dep],
Expand All @@ -162,14 +150,8 @@ py3.extension_module('_lsoda',
subdir: 'scipy/integrate'
)

_dop_module = custom_target('_dop_module',
output: ['_dop-f2pywrappers.f', '_dopmodule.c'],
input: 'dop.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_dop',
_dop_module,
f2py_gen.process('dop.pyf'),
link_with: [dop_lib],
c_args: [Wno_unused_variable],
dependencies: [fortranobject_dep],
Expand All @@ -186,14 +168,8 @@ py3.extension_module('_test_multivariate',
subdir: 'scipy/integrate'
)

_test_odeint_banded_module = custom_target('_test_odeint_banded_module',
output: ['_test_odeint_bandedmodule.c', '_test_odeint_banded-f2pywrappers.f'],
input: 'tests/banded5x5.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_test_odeint_banded',
['tests/banded5x5.f', _test_odeint_banded_module],
['tests/banded5x5.f', f2py_gen.process('tests/test_odeint_banded.pyf')],
link_with: [lsoda_lib, mach_lib],
fortran_args: _fflag_Wno_unused_dummy_argument,
link_args: version_link_args,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scipy/interpolate/_fitpack2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import numpy as np

from . import _fitpack_impl
from . import dfitpack
from . import _dfitpack as dfitpack


dfitpack_int = dfitpack.types.intvar.dtype
Expand Down
2 changes: 1 addition & 1 deletion scipy/interpolate/_fitpack_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

# Try to replace _fitpack interface with
# f2py-generated version
from . import dfitpack
from . import _dfitpack as dfitpack


dfitpack_int = dfitpack.types.intvar.dtype
Expand Down
2 changes: 1 addition & 1 deletion scipy/interpolate/_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from scipy.special import comb

from . import _fitpack_py
from . import dfitpack
from . import _dfitpack as dfitpack
from ._polyint import _Interpolator1D
from . import _ppoly
from .interpnd import _ndim_coords_from_arrays
Expand Down
10 changes: 2 additions & 8 deletions scipy/interpolate/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,9 @@ py3.extension_module('_fitpack',
subdir: 'scipy/interpolate'
)

dfitpack_module = custom_target('dfitpack_module',
output: ['dfitpack-f2pywrappers.f', 'dfitpackmodule.c'],
input: 'src/fitpack.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

# TODO: Add flags for 64 bit ints
py3.extension_module('dfitpack',
dfitpack_module,
py3.extension_module('_dfitpack',
f2py_gen.process('src/dfitpack.pyf'),
c_args: [Wno_unused_variable],
link_args: version_link_args,
dependencies: [lapack_dep, fortranobject_dep],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
! This limit can be overridden with -fmax-stack-var-size, or -frecursive can
! be used to force all local arrays to be allocated on the stack.
!
python module dfitpack ! in
python module _dfitpack ! in

usercode '''

Expand Down
2 changes: 1 addition & 1 deletion scipy/interpolate/tests/test_bsplines.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# XXX: move to the interpolate namespace
from scipy.interpolate._ndbspline import make_ndbspl

from scipy.interpolate import dfitpack
from scipy.interpolate import _dfitpack as dfitpack
from scipy.interpolate import _bsplines as _b


Expand Down
2 changes: 1 addition & 1 deletion scipy/interpolate/tests/test_fitpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from scipy.interpolate._fitpack_py import (splrep, splev, bisplrep, bisplev,
sproot, splprep, splint, spalde, splder, splantider, insert, dblint)
from scipy.interpolate.dfitpack import regrid_smth
from scipy.interpolate._dfitpack import regrid_smth
from scipy.interpolate._fitpack2 import dfitpack_int


Expand Down
8 changes: 1 addition & 7 deletions scipy/io/meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
_test_fortran_module = custom_target('_test_fortran_module',
output: ['_test_fortranmodule.c'],
input: '_test_fortran.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_test_fortran',
[
_test_fortran_module,
f2py_gen.process('test_fortran.pyf'),
'_test_fortran.f'
],
c_args: [Wno_unused_variable],
Expand Down
File renamed without changes.
9 changes: 1 addition & 8 deletions scipy/linalg/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ py3.extension_module('_flapack',

# TODO: cblas/clapack are built *only* for ATLAS. Why? Is it still needed?

# _interpolative
interpolative_module = custom_target('interpolative_module',
output: '_interpolativemodule.c',
input: 'interpolative.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

# id_dist contains a copy of FFTPACK, which has type mismatch warnings
# that are hard to fix. This code is terrible and noisy during the build,
# silence it completely.
Expand Down Expand Up @@ -159,7 +152,7 @@ py3.extension_module('_interpolative',
'src/id_dist/src/idzr_rid.f',
'src/id_dist/src/idzr_rsvd.f',
'src/id_dist/src/prini.f',
interpolative_module,
f2py_gen.process('interpolative.pyf'),
],
fortran_args: [fortran_ignore_warnings, _suppress_all_warnings],
link_args: version_link_args,
Expand Down
9 changes: 9 additions & 0 deletions scipy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ fortranobject_dep = declare_dependency(
compile_args: _f2py_c_args,
)

f2py = find_program('f2py')
# Note: cannot handle .pyf.src or targets with #include's (due to no
# `depend_files` - see feature request at meson#8295)
f2py_gen = generator(generate_f2pymod,
arguments : ['@INPUT@', '-o', '@BUILD_DIR@'],
output : ['_@[email protected]', '_@[email protected]'],
)


# TODO: 64-bit BLAS and LAPACK
#
# Note that this works as long as BLAS and LAPACK are detected properly via
Expand Down
32 changes: 4 additions & 28 deletions scipy/optimize/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,12 @@ py3.extension_module('_zeros',
subdir: 'scipy/optimize'
)

lbfgsb_module = custom_target('lbfgsb_module',
output: ['_lbfgsb-f2pywrappers.f', '_lbfgsbmodule.c'],
input: 'lbfgsb_src/lbfgsb.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_lbfgsb',
[
'lbfgsb_src/lbfgsb.f',
'lbfgsb_src/linpack.f',
'lbfgsb_src/timer.f',
lbfgsb_module,
f2py_gen.process('lbfgsb_src/lbfgsb.pyf'),
],
fortran_args: fortran_ignore_warnings,
link_args: version_link_args,
Expand All @@ -126,14 +120,8 @@ py3.extension_module('_moduleTNC',
subdir: 'scipy/optimize'
)

cobyla_module = custom_target('cobyla_module',
output: ['_cobylamodule.c'],
input: 'cobyla/cobyla.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_cobyla',
[cobyla_module, 'cobyla/cobyla2.f', 'cobyla/trstlp.f'],
[f2py_gen.process('cobyla/cobyla.pyf'), 'cobyla/cobyla2.f', 'cobyla/trstlp.f'],
c_args: [Wno_unused_variable],
fortran_args: fortran_ignore_warnings,
link_args: version_link_args,
Expand All @@ -143,14 +131,8 @@ py3.extension_module('_cobyla',
subdir: 'scipy/optimize'
)

minpack2_module = custom_target('minpack2_module',
output: ['_minpack2module.c'],
input: 'minpack2/minpack2.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_minpack2',
[minpack2_module, 'minpack2/dcsrch.f', 'minpack2/dcstep.f'],
[f2py_gen.process('minpack2/minpack2.pyf'), 'minpack2/dcsrch.f', 'minpack2/dcstep.f'],
fortran_args: fortran_ignore_warnings,
link_args: version_link_args,
dependencies: [fortranobject_dep],
Expand All @@ -160,14 +142,8 @@ py3.extension_module('_minpack2',
subdir: 'scipy/optimize'
)

slsqp_module = custom_target('slsqp_module',
output: ['_slsqpmodule.c'],
input: 'slsqp/slsqp.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_slsqp',
[slsqp_module, 'slsqp/slsqp_optmz.f'],
[f2py_gen.process('slsqp/slsqp.pyf'), 'slsqp/slsqp_optmz.f'],
fortran_args: fortran_ignore_warnings,
link_args: version_link_args,
dependencies: [fortranobject_dep],
Expand Down
8 changes: 1 addition & 7 deletions scipy/sparse/linalg/_propack/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,8 @@ foreach ele: elements
gnu_symbol_visibility: 'hidden',
)

propack_module = custom_target('propack_module' + ele[0],
output: [ele[0] + '-f2pywrappers.f', ele[0] + 'module.c'],
input: ele[2],
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

propacklib = py3.extension_module(ele[0],
propack_module,
f2py_gen.process(ele[2]),
link_with: propack_lib,
c_args: ['-U_OPENMP', _cpp_Wno_cpp],
fortran_args: _fflag_Wno_maybe_uninitialized,
Expand Down
9 changes: 2 additions & 7 deletions scipy/stats/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ py3.extension_module('_ansari_swilk_statistics',
subdir: 'scipy/stats'
)

mvn_module = custom_target('mvn_module',
output: ['_mvn-f2pywrappers.f', '_mvnmodule.c'],
input: 'mvn.pyf',
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
)

py3.extension_module('_mvn',
[mvn_module, 'mvndst.f'],
#[mvn_module, 'mvndst.f'],
[f2py_gen.process('mvn.pyf'), 'mvndst.f'],
# Wno-surprising is to suppress a pointless warning with GCC 10-12
# (see GCC bug 98411: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98411)
fortran_args: [fortran_ignore_warnings, _fflag_Wno_surprising],
Expand Down
2 changes: 1 addition & 1 deletion tools/generate_f2pymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def main():

# Now invoke f2py to generate the C API module file
if args.infile.endswith(('.pyf.src', '.pyf')):
p = subprocess.Popen([sys.executable, '-m', 'numpy.f2py', fname_pyf,
p = subprocess.Popen(['f2py', fname_pyf,
'--build-dir', outdir_abs], #'--quiet'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=os.getcwd())
Expand Down

0 comments on commit 86c5922

Please sign in to comment.