[SciPy-dev] f2py + f90 file

Pearu Peterson pearu@cens.ioc...
Tue Feb 26 04:16:59 CST 2008

On Tue, February 26, 2008 12:01 pm, dmitrey wrote:
> I have seen the pyf-files appearing from time to time, but now they are
> absent (in the directory where I have used f2py), and do not appear
> after f2py using.
> As for commands, I have used
> f2py -c -m bvls bvls.f
> and
> f2py -c -m bvls bvls.f90 --fcompiler=gnu95

Ok, thanks for the info. In general, it is recommended to use
a modified .pyf when wrapping Fortran functions with longish
argument list that may contain output-type arguments.
See f2py users guide for more information.

Below follows the content of a .pyf file that I have modified to
meet the docs of bvls.f (there are some room for improvements).
Then I used the following command line

  f2py -c bvls.pyf bvls.f

to build the bvls extension module. In test_bvls.py file I changed
the bvls.bvls call to

  xf,w,istate,loopa = bvls.bvls(a,b,bl,bu)

And, most importantly, set inf=100. Now I get the correct results:

using bvls.f
Type: float32 ;
xf= [ 15.  15.] ; type(xf[0])= <type 'numpy.float64'>
Type: float64 ;
xf= [ 15.  15.] ; type(xf[0])= <type 'numpy.float64'>
Type: float128 ;
xf= [ 15.  15.] ; type(xf[0])= <type 'numpy.float64'>

Btw, I believe that your approach of not using .pyf file
would also worked when not using inf as an bound parameter
- obviosly the underlying Fortran code is not designed
to handle float infinities.


!    -*- f90 -*-
! Note: the context of this file is case sensitive.
!FILE: bvls.pyf

python module bvls ! in
    interface  ! in :bvls
        subroutine bvls(key,m,n,a,b,bl,bu,x,w,act,zz,istate,loopa) ! in
            integer :: key = 0
            integer optional,check(shape(a,0)==m),depend(a) :: m=shape(a,0)
            integer optional,check(shape(a,1)==n),depend(a) :: n=shape(a,1)
            double precision dimension(m,n) :: a
            double precision dimension(m),depend(m) :: b
            double precision dimension(n),depend(n) :: bl
            double precision dimension(n),depend(n) :: bu
            double precision dimension(n),depend(n),intent(out) :: x
            double precision dimension(n),depend(n),intent(out) :: w
            double precision dimension(m,m + 2),depend(m), intent(cache),
optional :: act
            double precision dimension(m),depend(m), intent(cache),
optional :: zz
            integer dimension(n + 1),depend(n),intent(out) :: istate
            integer intent(out) :: loopa
        end subroutine bvls
    end interface
end python module bvls

! This file was auto-generated with f2py (version:2_3744).
! See http://cens.ioc.ee/projects/f2py2e/

More information about the Scipy-dev mailing list