[NumPy-Tickets] [NumPy] #1750: f2py breaks complex kind statements

NumPy Trac numpy-tickets@scipy....
Sat Feb 26 16:06:36 CST 2011


#1750: f2py breaks complex kind statements
------------------------+---------------------------------------------------
 Reporter:  lorenz      |       Owner:  pearu      
     Type:  defect      |      Status:  new        
 Priority:  normal      |   Milestone:  Unscheduled
Component:  numpy.f2py  |     Version:  1.5.1      
 Keywords:              |  
------------------------+---------------------------------------------------
 f2py apparently tries to translate kind statements it found earlier in the
 file, this seems to fail if they are not just a simple number. Consider
 the following example:
 {{{
 module precision
   integer, parameter :: rk = selected_real_kind(8)
 end module

 subroutine test(x, n, res)
   use precision

   implicit none

   real(kind=rk), intent(in) :: x(n)
   integer :: n
   real(kind=rk), intent(out) :: res

   integer :: i

   print *, "x =", x

   res = 0.0
   do i = 1, size(x)
     res = x(i)
   enddo

 end subroutine
 }}}

 Compiling this with f2py:
 {{{
 user@host:~/f2py_kind_test> f2py --build-dir build -c --fcompiler=gnu95 -m
 test test.f90
 running build
 running config_cc
 unifing config_cc, config, build_clib, build_ext, build commands
 --compiler options
 running config_fc
 unifing config_fc, config, build_clib, build_ext, build commands
 --fcompiler options
 running build_src
 build_src
 building extension "test" sources
 f2py options: []
 f2py:> build/src.linux-i686-2.6/testmodule.c
 Reading fortran codes...
         Reading file 'test.f90' (format:free)
 Post-processing...
         Block: test
                         Block: precision
 In: :test:test.f90:precision
 get_parameters: got "name 'selected' is not defined" on 'selected'
                         Block: test
 In: :test:test.f90:test
 get_parameters: got "name 'selected' is not defined" on 'selected'
 Post-processing (stage 2)...
         Block: test
                 Block: unknown_interface
                         Block: precision
                         Block: test
 Building modules...
         Building module "test"...
                 Constructing wrapper function "test"...
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
                   res = test(x,[n])
                 Constructing F90 module support for "precision"...
                   Variables: rk
         Wrote C/API module "test" to file
 "build/src.linux-i686-2.6/testmodule.c"
         Fortran 90 wrappers are saved to "build/src.linux-i686-2.6/test-
 f2pywrappers2.f90"
   adding 'build/src.linux-i686-2.6/fortranobject.c' to sources.
   adding 'build/src.linux-i686-2.6' to include_dirs.
   adding 'build/src.linux-i686-2.6/test-f2pywrappers2.f90' to sources.
 build_src: building npy-pkg config files
 running build_ext
 customize UnixCCompiler
 customize UnixCCompiler using build_ext
 customize Gnu95FCompiler
 Found /usr/bin/gfortran
 customize Gnu95FCompiler using build_ext
 building 'test' extension
 compiling C sources
 C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3
 -Wall -Wstrict-prototypes -fPIC

 compile options: '-Ibuild/src.linux-i686-2.6
 -I/afs/mpa/home/lorenz/sys/lib/python2.6/site-packages/numpy/core/include
 -I/usr/common/pdsoft/appl/pyapps/include/python2.6 -c'
 gcc: build/src.linux-i686-2.6/testmodule.c
 compiling Fortran 90 module sources
 Fortran f77 compiler: /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall
 -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
 Fortran f90 compiler: /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall
 -fno-second-underscore -fPIC -O3 -funroll-loops
 Fortran fix compiler: /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall
 -ffixed-form -fno-second-underscore -Wall -fno-second-underscore -fPIC -O3
 -funroll-loops
 compile options: '-Ibuild/src.linux-i686-2.6
 -I/afs/mpa/home/lorenz/sys/lib/python2.6/site-packages/numpy/core/include
 -I/usr/common/pdsoft/appl/pyapps/include/python2.6 -c'
 extra options: '-Jbuild/ -Ibuild/'
 gfortran:f90: test.f90
 compiling Fortran sources
 Fortran f77 compiler: /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall
 -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
 Fortran f90 compiler: /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall
 -fno-second-underscore -fPIC -O3 -funroll-loops
 Fortran fix compiler: /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall
 -ffixed-form -fno-second-underscore -Wall -fno-second-underscore -fPIC -O3
 -funroll-loops
 compile options: '-Ibuild/src.linux-i686-2.6
 -I/afs/mpa/home/lorenz/sys/lib/python2.6/site-packages/numpy/core/include
 -I/usr/common/pdsoft/appl/pyapps/include/python2.6 -c'
 extra options: '-Jbuild/ -Ibuild/'
 gfortran:f90: build/src.linux-i686-2.6/test-f2pywrappers2.f90
 /afs/mpa/@sys/system/MPA-6.00/usr/bin/gfortran -Wall -Wall -shared
 build/build/src.linux-i686-2.6/testmodule.o
 build/build/src.linux-i686-2.6/fortranobject.o build/test.o
 build/build/src.linux-i686-2.6/test-f2pywrappers2.o -lgfortran -o
 ./test.so
 running scons
 }}}

 Some parsing obviously fails, looking at the message
 {{{
 getctype: "real(kind=selected)" not supported (use .f2py_f2cmap).
 }}}

 Running the example produces wrong results, as apparently the arguments
 are interpreted as floats:
 {{{
 user@host:~/f2py_kind_test> python -c "import test; print
 test.test([1.0,2.0,3.0])"
  x =   2.0000004731118679       4.27053725193275668E-312
 0.0000000000000000
 1.0
 }}}

 Changing "selected_real_kind(8)" to "8" produces the expected result:
 {{{
 user@host:~/f2py_kind_test> python -c "import test; print
 test.test([1.0,2.0,3.0])"
  x =   1.0000000000000000        2.0000000000000000
 3.0000000000000000
 6.0
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1750>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list