f90wrap icon indicating copy to clipboard operation
f90wrap copied to clipboard

32 / 64 bits array strikes again

Open MrYann opened this issue 8 years ago • 1 comments

Hello. I'm working again on my fortran to python wrapping and come across the 32/64 bit problem again: I initialize variables in python with numpy.zeros, which produces 64bit floats by default. When the array is of size 1, this works for fortran integer or real transparently. However, with size > 1 I have to explicitly use zeros(xxx, int32) (or float32) to be accepted by fortran. Note that I use in/out arrays, courtesy to the --default-to-inout flag. In the simple (in) mode, there is no problem but I don't recover any value ;)

Is this a f90-wrap internal conversion issue, or an f2py conversion issue ? Or maybe should we compile all fortran sources with some flag to enforce 64 bit fortran variables, to be compatible with their python counterparts ?

FORTRAN file

module module_test

INTEGER,PARAMETER :: n=12

	contains

	subroutine testf(x)
		integer, dimension(n) :: x
		x(2) = 4
	end subroutine testf

	subroutine testf2(x)
		integer :: x
		x = 4
	end subroutine testf2

end module module_test

PYTHON file

import test3_python
from numpy import zeros, int32

b = zeros(1)
test3_python.module_test.testf2(b)
assert b == 4

a = zeros(12, int32)
test3_python.module_test.testf(a)
assert all(a == [0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

MAKE file

test3 : clean
	gfortran -c -O3 -fPIC test3.f90
	f90wrap --default-to-inout -m test3_python test3.f90
	f2py-f90wrap -c -m _test3_python f90wrap_* *.o
	python test3.py
clean :
	rm -rf *.o *.mod *.so *python.py f90wrap* ./build

MrYann avatar Dec 17 '16 18:12 MrYann

I saw the same issue. For some reason, GCC doesn't have this issue, but Intel has.

I was trying to set the kind_map to long_int, but it doesn't work.

zhucaoxiang avatar Dec 08 '20 11:12 zhucaoxiang