Skip to content

Commit ad4981c

Browse files
committed
Simple example of f2py
1 parent 3f204ab commit ad4981c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

demos/interface/fortran/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Building the extension
2+
3+
Fortran source can be built into a C-extension as
4+
```
5+
f2py -c add.f90 -m add
6+
```
7+
(For Python 3 use f2py3)
8+

demos/interface/fortran/add.f90

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
subroutine add(a, b, n)
2+
3+
implicit none
4+
5+
! f2py understands only limited number of kind parameters
6+
real(kind=8), intent(inout) :: a(n)
7+
real(kind=8), intent(inout) :: b(n)
8+
integer :: n
9+
10+
a = a + b
11+
12+
end subroutine

demos/interface/fortran/example.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import add
2+
import numpy as np
3+
4+
a = np.random.random(10)
5+
b = np.ones_like(a)
6+
print(a)
7+
add.add(a, b)
8+
print(a)

0 commit comments

Comments
 (0)