Skip to content

Commit 34d05c6

Browse files
committed
Merge branch 'main' of https://github.com/fortran-lang/minpack into test-refactoring
2 parents a7759da + ab3722b commit 34d05c6

File tree

21 files changed

+2084
-13
lines changed

21 files changed

+2084
-13
lines changed

.github/workflows/CI.yml

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ jobs:
2424
with:
2525
submodules: recursive
2626

27+
- name: Cache GFortran install
28+
if: ${{ contains(matrix.os, 'windows') }}
29+
id: cache
30+
uses: actions/cache@v2
31+
with:
32+
path: ./mingw-w64
33+
key: gcc-${{ matrix.gcc }}-${{ matrix.os }}
34+
2735
- name: Install GFortran (MacOS)
2836
if: ${{ contains(matrix.os, 'macos') }}
2937
run: |
@@ -40,7 +48,7 @@ jobs:
4048
--slave /usr/bin/gcov gcov /usr/bin/gcov-${{ matrix.gcc }}
4149
4250
- name: Install GFortran (Windows)
43-
if: ${{ contains(matrix.os, 'windows') }}
51+
if: ${{ contains(matrix.os, 'windows') && steps.cache.outputs.cache-hit != 'true' }}
4452
run: |
4553
Invoke-WebRequest -Uri ${{ env.DOWNLOAD }} -OutFile mingw-w64.zip
4654
Expand-Archive mingw-w64.zip
@@ -90,6 +98,7 @@ jobs:
9098
if: ${{ matrix.build == 'meson' }}
9199
run: >-
92100
meson setup _build
101+
--libdir=lib
93102
--prefix=${{ contains(matrix.os, 'windows') && '$pwd\_dist' || '$PWD/_dist' }}
94103
95104
- name: Compile project (meson)
@@ -104,6 +113,146 @@ jobs:
104113
if: ${{ matrix.build == 'meson' }}
105114
run: meson install -C _build --no-rebuild
106115

116+
- name: Create package (Unix)
117+
if: ${{ matrix.build == 'meson' && ! contains(matrix.os, 'windows') }}
118+
run: |
119+
tar cvf ${{ env.OUTPUT }} _dist
120+
xz -T0 ${{ env.OUTPUT }}
121+
echo "MINPACK_OUTPUT=${{ env.OUTPUT }}.xz" >> $GITHUB_ENV
122+
env:
123+
OUTPUT: minpack-${{ matrix.os }}.tar
124+
125+
- name: Create package (Windows)
126+
if: ${{ matrix.build == 'meson' && contains(matrix.os, 'windows') }}
127+
run: |
128+
tar cvf ${{ env.OUTPUT }} _dist
129+
xz -T0 ${{ env.OUTPUT }}
130+
echo "MINPACK_OUTPUT=${{ env.OUTPUT }}.xz" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
131+
env:
132+
OUTPUT: minpack-${{ matrix.os }}.tar
133+
134+
- name: Upload package
135+
if: ${{ matrix.build == 'meson' }}
136+
uses: actions/upload-artifact@v2
137+
with:
138+
name: ${{ env.MINPACK_OUTPUT }}
139+
path: ${{ env.MINPACK_OUTPUT }}
140+
141+
142+
Python:
143+
needs:
144+
- Build
145+
runs-on: ${{ matrix.os }}
146+
defaults:
147+
run:
148+
shell: ${{ contains(matrix.os, 'windows') && 'powershell' || 'bash -l {0}' }}
149+
strategy:
150+
fail-fast: false
151+
matrix:
152+
build: [meson]
153+
os: [ubuntu-latest, macos-latest]
154+
gcc: [10]
155+
python: ['3.7', '3.8', '3.9']
156+
157+
# Additional test for setuptools build
158+
include:
159+
- build: setuptools
160+
os: ubuntu-latest
161+
gcc: 10
162+
python: '3.9'
163+
164+
env:
165+
FC: gfortran
166+
CC: gcc
167+
MINPACK_OUTPUT: minpack-${{ matrix.os }}.tar.xz
168+
169+
steps:
170+
- name: Checkout code
171+
uses: actions/checkout@v2
172+
173+
- name: Cache GFortran install
174+
if: ${{ contains(matrix.os, 'windows') }}
175+
id: cache
176+
uses: actions/cache@v2
177+
with:
178+
path: ./mingw-w64
179+
key: gcc-${{ matrix.gcc }}-${{ matrix.os }}
180+
181+
- name: Install dependencies
182+
uses: mamba-org/provision-with-micromamba@main
183+
with:
184+
environment-file: config/ci/python-env.yaml
185+
extra-specs: |
186+
python=${{ matrix.python }}
187+
188+
- name: Install GFortran (MacOS)
189+
if: ${{ contains(matrix.os, 'macos') }}
190+
run: |
191+
brew install gcc@${{ matrix.gcc }}
192+
ln -s /usr/local/bin/gfortran-${{ matrix.gcc }} /usr/local/bin/gfortran
193+
ln -s /usr/local/bin/gcc-${{ matrix.gcc }} /usr/local/bin/gcc
194+
195+
- name: Install GFortran (Linux)
196+
if: ${{ contains(matrix.os, 'ubuntu') }}
197+
run: |
198+
sudo update-alternatives \
199+
--install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100 \
200+
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${{ matrix.gcc }} \
201+
--slave /usr/bin/gcov gcov /usr/bin/gcov-${{ matrix.gcc }}
202+
203+
- name: Install GFortran (Windows)
204+
if: ${{ contains(matrix.os, 'windows') && steps.cache.outputs.cache-hit != 'true' }}
205+
run: |
206+
Invoke-WebRequest -Uri ${{ env.DOWNLOAD }} -OutFile mingw-w64.zip
207+
Expand-Archive mingw-w64.zip
208+
echo "$pwd\mingw-w64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
209+
shell: pwsh
210+
env:
211+
DOWNLOAD: "https://github.com/brechtsanders/winlibs_mingw/releases/download/10.3.0-12.0.0-9.0.0-r2/winlibs-x86_64-posix-seh-gcc-10.3.0-mingw-w64-9.0.0-r2.zip"
212+
213+
- name: Download package
214+
uses: actions/download-artifact@v2
215+
with:
216+
name: ${{ env.MINPACK_OUTPUT }}
217+
218+
- name: Unpack package (Unix)
219+
if: ${{ ! contains(matrix.os, 'windows') }}
220+
run: |
221+
tar xvf ${{ env.MINPACK_OUTPUT }}
222+
echo "MINPACK_PREFIX=$PWD/_dist" >> $GITHUB_ENV
223+
224+
- name: Unpack package (Windows)
225+
if: ${{ contains(matrix.os, 'windows') }}
226+
run: |
227+
tar xvf ${{ env.MINPACK_OUTPUT }}
228+
echo "MINPACK_OUTPUT=${{ env.OUTPUT }}.xz" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
229+
230+
- name: Install Python extension module (pip)
231+
if: ${{ matrix.build == 'setuptools' }}
232+
run: pip3 install . -vv
233+
working-directory: python
234+
env:
235+
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}:${{ env.MINPACK_PREFIX }}/lib/pkgconfig
236+
LD_RUNPATH_SEARCH_PATH: ${{ env.MINPACK_PREFIX }}/lib
237+
238+
- name: Install Python extension module (meson)
239+
if: ${{ matrix.build == 'meson' }}
240+
run: |
241+
set -ex
242+
meson setup _build --prefix=$CONDA_PREFIX --libdir=lib
243+
meson compile -C _build
244+
meson install -C _build
245+
working-directory: python
246+
env:
247+
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}:${{ env.MINPACK_PREFIX }}/lib/pkgconfig
248+
249+
- name: Test Python API
250+
run: pytest --doctest-modules --pyargs minpack --cov=minpack -vv
251+
env:
252+
LD_LIBRARY_PATH: ${{ env.LD_LIBRARY_PATH }}:${{ env.MINPACK_PREFIX }}/lib
253+
DYLD_LIBRARY_PATH: ${{ env.DYLD_LIBRARY_PATH }}:${{ env.MINPACK_PREFIX }}/lib
254+
255+
107256
Docs:
108257
runs-on: ubuntu-latest
109258
defaults:

config/ci/python-env.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: python
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python
6+
- pip
7+
- pkgconfig
8+
- pytest
9+
- pytest-cov
10+
- coverage
11+
- cffi
12+
- numpy
13+
- meson
14+
- ninja

include/minpack.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ typedef void (*minpack_func)(
1919
int* /* iflag */,
2020
void* /* udata */);
2121

22+
#ifdef MINPACK_CFFI
23+
extern "Python" void MINPACK_CALL
24+
func(
25+
int /* n */,
26+
const double* /* x */,
27+
double* /* fvec */,
28+
int* /* iflag */,
29+
void* /* udata */);
30+
#endif
31+
2232
/*
2333
* the purpose of hybrd is to find a zero of a system of
2434
* n nonlinear functions in n variables by a modification
@@ -84,6 +94,18 @@ typedef void (*minpack_fcn_hybrj)(
8494
int* /* iflag */,
8595
void* /* udata */);
8696

97+
#ifdef MINPACK_CFFI
98+
extern "Python" void MINPACK_CALL
99+
fcn_hybrj(
100+
int /* n */,
101+
const double* /* x */,
102+
double* /* fvec */,
103+
double* /* fjac */,
104+
int /* ldfjac */,
105+
int* /* iflag */,
106+
void* /* udata */);
107+
#endif
108+
87109
/*
88110
* the purpose of hybrj is to find a zero of a system of
89111
* n nonlinear functions in n variables by a modification
@@ -148,6 +170,19 @@ typedef void (*minpack_fcn_lmder)(
148170
int* /* iflag */,
149171
void* /* udata */);
150172

173+
#ifdef MINPACK_CFFI
174+
extern "Python" void MINPACK_CALL
175+
fcn_lmder(
176+
int /* m */,
177+
int /* n */,
178+
const double* /* x */,
179+
double* /* fvec */,
180+
double* /* fjac */,
181+
int /* ldfjac */,
182+
int* /* iflag */,
183+
void* /* udata */);
184+
#endif
185+
151186
/*
152187
* the purpose of lmder is to minimize the sum of the squares of
153188
* m nonlinear functions in n variables by a modification of
@@ -213,6 +248,17 @@ typedef void (*minpack_func2)(
213248
int* /* iflag */,
214249
void* /* udata */);
215250

251+
#ifdef MINPACK_CFFI
252+
extern "Python" void MINPACK_CALL
253+
func2(
254+
int /* m */,
255+
int /* n */,
256+
const double* /* x */,
257+
double* /* fvec */,
258+
int* /* iflag */,
259+
void* /* udata */);
260+
#endif
261+
216262
/*
217263
* the purpose of lmdif is to minimize the sum of the squares of
218264
* m nonlinear functions in n variables by a modification of
@@ -279,6 +325,18 @@ typedef void (*minpack_fcn_lmstr)(
279325
int* /* iflag */,
280326
void* /* udata */);
281327

328+
#ifdef MINPACK_CFFI
329+
extern "Python" void MINPACK_CALL
330+
fcn_lmstr(
331+
int /* m */,
332+
int /* n */,
333+
const double* /* x */,
334+
double* /* fvec */,
335+
double* /* fjrow */,
336+
int* /* iflag */,
337+
void* /* udata */);
338+
#endif
339+
282340
/*
283341
* the purpose of lmstr is to minimize the sum of the squares of
284342
* m nonlinear functions in n variables by a modification of

meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(
88
'buildtype=debugoptimized',
99
],
1010
)
11+
has_cc = add_languages('c', required: get_option('python'), native: false)
1112

1213
minpack_lib = library(
1314
meson.project_name(),
@@ -59,3 +60,7 @@ subdir('examples')
5960

6061
# add the testsuite
6162
subdir('test')
63+
64+
if get_option('python')
65+
subdir('python/minpack')
66+
endif

meson_options.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
option(
2+
'python',
3+
type: 'boolean',
4+
value: false,
5+
description: 'Build Python extension module',
6+
)
7+
option(
8+
'python_version',
9+
type: 'string',
10+
value: 'python3',
11+
description: 'Python version to link against.',
12+
)

0 commit comments

Comments
 (0)