Hi, I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work. Here is what I am doing. PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8) FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0 Any Ideas? thanks, John
Hi, this probably does not help with your problem. However, I would recommend changing your fortran code to: subroutine print_bit_array(bits) use iso_fortran_env integer(kind=int8),intent(in),dimension(:)::bits print*,'bits = ',bits end subroutine print_bit_array In that way you could print shape(bits) to verify that you are getting an array of the size you are expecting. Also, you could compile with -fbounds-check (gfortran) or a similar flag for some extra debugging facilities. To get better help with your issues, I would recommend also posting your call to the fortran routine, and the compilation command used (f2py -m myfile.f90 -flags....). Cheers Paul On 17. apr. 2012, at 07:32, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8)
FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array
RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0
Any Ideas? thanks, John
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Tuesday 17 April 2012 11:02 AM, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8)
FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array
RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0
Any Ideas? thanks, John
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion It seems to work if "integer(kind=int8)" is replaced with "integer(8)" or "integer(1)". Don't know why, though.
Sameer
Thanks Sameer. I confirmed on my side as well. I will try to understand the why part now. Much appreciated. On Mon, Apr 16, 2012 at 11:58 PM, Sameer Grover <sameer.grover.1@gmail.com>wrote:
On Tuesday 17 April 2012 11:02 AM, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8)
FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array
RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0
Any Ideas? thanks, John
_______________________________________________ NumPy-Discussion mailing listNumPy-Discussion@scipy.orghttp://mail.scipy.org/mailman/listinfo/numpy-discussion
It seems to work if "integer(kind=int8)" is replaced with "integer(8)" or "integer(1)". Don't know why, though.
Sameer
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Ah, come to think of it, I think that f2py only supports literal kind values. Maybe that's your problem. Paul On 17. apr. 2012, at 07:58, Sameer Grover wrote:
On Tuesday 17 April 2012 11:02 AM, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8)
FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array
RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0
Any Ideas? thanks, John
_______________________________________________ NumPy-Discussion mailing list
NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion It seems to work if "integer(kind=int8)" is replaced with "integer(8)" or "integer(1)". Don't know why, though.
Sameer _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Thanks Paul. I suppose this is now going slightly out of bounds for f2py. What I am looking for is the fortran kind type for a byte. I thought that this was int8. I guess the question is how to identify the kind type. Although I have verified that integer(1) seems to work for me, I would really like to know why and your answer alludes to that. Please excuse my ignorance on this topic. Can you perhaps educate me a little on 'literal kind values'? I take you to mean that 'int8' is not a literal kind value while 1 and 8 are examples of literal kind values. Thanks, John On Tue, Apr 17, 2012 at 10:12 AM, Paul Anton Letnes < paul.anton.letnes@gmail.com> wrote:
Ah, come to think of it, I think that f2py only supports literal kind values. Maybe that's your problem.
Paul
On 17. apr. 2012, at 07:58, Sameer Grover wrote:
On Tuesday 17 April 2012 11:02 AM, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8)
FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array
RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0
Any Ideas? thanks, John
_______________________________________________ NumPy-Discussion mailing list
NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion It seems to work if "integer(kind=int8)" is replaced with "integer(8)" or "integer(1)". Don't know why, though.
Sameer _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Hi, 1, 2, 3 are integer literals. 1.0, 3.0e2, -42.0 are real (float) literals 'hello world' is a string literal. As far as I remember, f2py requires a literal variable for the kind. The solution I have landed on is to write a pure fortran module (using int8, or whatever), and then wrap this module either with an f2py compatible fortran module or an interface file. If you want to know what int8 corresponds to, run the following (pure fortran) program through your compiler of choice: program kind_values use iso_fortran_env implicit none print *, 'int8 kind value:', int8 print *, 'int16 kind value:', int16 end program kind_values Paul On 17. apr. 2012, at 19:47, John Mitchell wrote:
Thanks Paul.
I suppose this is now going slightly out of bounds for f2py. What I am looking for is the fortran kind type for a byte. I thought that this was int8. I guess the question is how to identify the kind type. Although I have verified that integer(1) seems to work for me, I would really like to know why and your answer alludes to that.
Please excuse my ignorance on this topic. Can you perhaps educate me a little on 'literal kind values'? I take you to mean that 'int8' is not a literal kind value while 1 and 8 are examples of literal kind values.
Thanks, John
On Tue, Apr 17, 2012 at 10:12 AM, Paul Anton Letnes <paul.anton.letnes@gmail.com> wrote: Ah, come to think of it, I think that f2py only supports literal kind values. Maybe that's your problem.
Paul
On 17. apr. 2012, at 07:58, Sameer Grover wrote:
On Tuesday 17 April 2012 11:02 AM, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F') b[0]=1 b[2]=1 b[3]=1 b array([1, 0, 1, 1, 0, 0, 0, 0, 0, 0], dtype=int8)
FORTRAN subroutine print_bit_array(bits,n) use iso_fortran_env integer,intent(in)::n integer(kind=int8),intent(in),dimension(n)::bits print*,'bits = ',bits end subroutine print_bit_array
RESULT when calling fortran from python bits = 1 0 0 0 0 0 0 0 1 0
Any Ideas? thanks, John
_______________________________________________ NumPy-Discussion mailing list
NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion It seems to work if "integer(kind=int8)" is replaced with "integer(8)" or "integer(1)". Don't know why, though.
Sameer _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 17.04.2012 07:32, John Mitchell wrote:
Hi,
I am using f2py to pass a numpy array of type numpy.int8 to fortran. It seems like I am misunderstanding something because I just can't make it work.
Here is what I am doing.
PYTHON b=numpy.array(numpy.zeros(shape=(10,),dtype=numpy.int8),order='F')
This returns an array with dtype int. You want: b = numpy.zeros(shape=(10,),dtype=numpy.int8,order='F') Sturla
participants (4)
-
John Mitchell -
Paul Anton Letnes -
Sameer Grover -
Sturla Molden