-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change f90wrap generated variable names to enable use of n1, n2 varia…
…ble names
- Loading branch information
daniel
committed
Nov 18, 2024
1 parent
5fc2dcf
commit b4d6039
Showing
8 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#======================================================================= | ||
# define the compiler names | ||
#======================================================================= | ||
|
||
CC = gcc | ||
F90 = gfortran | ||
PYTHON = python | ||
CFLAGS = -fPIC | ||
F90FLAGS = -fPIC | ||
PY_MOD = pywrapper | ||
F90_SRC = main.f90 | ||
OBJ = $(F90_SRC:.f90=.o) | ||
F90WRAP_SRC = $(addprefix f90wrap_,${F90_SRC}) | ||
WRAPFLAGS = -v | ||
F2PYFLAGS = --build-dir build | ||
F90WRAP = f90wrap | ||
F2PY = f2py-f90wrap | ||
.PHONY: all clean | ||
|
||
all: test | ||
|
||
clean: | ||
rm -rf *.mod *.smod *.o f90wrap*.f90 ${PY_MOD}.py _${PY_MOD}*.so __pycache__/ .f2py_f2cmap build ${PY_MOD}/ | ||
|
||
main.o: ${F90_SRC} | ||
${F90} ${F90FLAGS} -c $< -o $@ | ||
|
||
%.o: %.f90 | ||
${F90} ${F90FLAGS} -c $< -o $@ | ||
|
||
${F90WRAP_SRC}: ${OBJ} | ||
${F90WRAP} -m ${PY_MOD} ${WRAPFLAGS} ${F90_SRC} | ||
|
||
f2py: ${F90WRAP_SRC} | ||
CFLAGS="${CFLAGS}" ${F2PY} -c -m _${PY_MOD} ${F2PYFLAGS} f90wrap_*.f90 *.o | ||
|
||
test: f2py | ||
${PYTHON} tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include ../make.meson.inc | ||
|
||
NAME := pywrapper | ||
|
||
test: build | ||
$(PYTHON) tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module m_intent_out | ||
|
||
implicit none | ||
public | ||
|
||
contains | ||
|
||
subroutine interpolation(n1,n2,a1,a2,output) | ||
! | ||
integer, intent(in) :: n1,n2 | ||
real,dimension(n1,n2), intent(in) :: a1,a2 | ||
real,dimension(n1,n2), intent(out) :: output | ||
|
||
integer :: i,j | ||
|
||
do j=1,n2 | ||
do i=1,n1 | ||
output(i,j)=(a1(i,j)+a2(i,j))/2 | ||
enddo | ||
enddo | ||
|
||
end subroutine interpolation | ||
|
||
end module m_intent_out | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
import numpy as np | ||
|
||
from pywrapper import m_intent_out | ||
|
||
class TestIntentOut(unittest.TestCase): | ||
|
||
def test_intent_out_size(self): | ||
|
||
a1 = np.array([[1,2], [3,4]], dtype=np.float32, order='F') | ||
a2 = np.array([[2,4], [6,8]], dtype=np.float32, order='F') | ||
output = np.zeros((2,2), dtype=np.float32, order='F') | ||
n1 = 2 | ||
n2 = 2 | ||
|
||
m_intent_out.interpolation(n1,n2,a1,a2,output) | ||
|
||
ref_out = np.array([[1.5,3.], [4.5,6.]], dtype=np.float32, order='F') | ||
|
||
np.testing.assert_array_equal(output, ref_out) | ||
|
||
if __name__ == '__main__': | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters