[SciPy-dev] Python/Fortran multi-dimensional array issues

eric eric at scipy.org
Wed Jan 16 12:51:00 CST 2002


Hey Pearu,

This is big news!  Could you post the wrapper code that f2py generates for
this?

thanks,
eric

----- Original Message -----
From: "Pearu Peterson" <pearu at cens.ioc.ee>
To: <scipy-dev at scipy.org>
Cc: <f2py-users at cens.ioc.ee>
Sent: Wednesday, January 16, 2002 2:38 PM
Subject: Re: [SciPy-dev] Python/Fortran multi-dimensional array issues


>
> Hi!
>
> I have implemented a novel multi-dimensional array support for f2py. The
> snapshot is available in
>
> http://cens.ioc.ee/projects/f2py2e/2.x/
>
> Basically, from now on there is no visible difference for arrays in
> Python or Fortran. f2py generated modules will deal with this rather
> confusing issue (that is due the difference how matrices are stored in
> arrays for C and Fortran programming languages) in a very efficient way.
>
> Note that this is quite a big news for f2py as this new approach finally
> solves the long lasted dilemma of Fortran and C storage orders and how to
> deal with it from Python.
>
> An example of a signature file with comments below illustrates all that
> with source files included to the attachment.
>
> Enjoy!
> Pearu
>
> !%f90 -*- f90 -*-
>
> !  Example:
> !    Using f2py for wrapping multi-dimensional Fortran and C arrays
> !    [NEW APPROACH, use it with f2py higher than 2.9.x]
> !    See also files foo.f and bar.c.
> !
> !  $Id: fun.pyf,v 1.2 2002/01/16 18:57:33 pearu Exp $
>
> ! Usage (with gcc compiler):
> !   f2py -c fun.pyf foo.f bar.c
>
> python module fun ! in
>     interface  ! in :fun
>
> ! >>> from Numeric import *
> ! >>> import fun
> ! >>> a=array([[1,2,3],[4,5,6]])
>
>         subroutine foo(a,m,n) ! in :fun:foo.f
>           integer dimension(m,n) :: a
>           intent(in,out) :: a
>           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)
>         end subroutine foo
>
> ! >>> print fun.foo.__doc__
> ! foo - Function signature:
> !   a = foo(a,[m,n])
> ! Required arguments:
> !   a : input rank-2 array('i') with bounds (m,n)
> ! Optional arguments:
> !   m := shape(a,0) input int
> !   n := shape(a,1) input int
> ! Return objects:
> !   a : rank-2 array('i') with bounds (m,n)
>
> ! >>> print fun.foo(a)
> !  F77:
> !  m= 2, n= 3
> !  Row  1:
> !  a(i= 1,j= 1) =  1
> !  a(i= 1,j= 2) =  2
> !  a(i= 1,j= 3) =  3
> !  Row  2:
> !  a(i= 2,j= 1) =  4
> !  a(i= 2,j= 2) =  5
> !  a(i= 2,j= 3) =  6
> ! [[77777     2     3]
> !  [    4     5     6]]
>
>
>         subroutine bar(a,m,n)
>           intent(c)
>           intent(c) bar
>           integer dimension(m,n) :: a
>           intent(in,out) :: a
>           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)
>           intent(in) m,n
>         end subroutine bar
>
> ! >>> print fun.bar.__doc__
> ! bar - Function signature:
> !   a = bar(a,[m,n])
> ! Required arguments:
> !   a : input rank-2 array('i') with bounds (m,n)
> ! Optional arguments:
> !   m := shape(a,0) input int
> !   n := shape(a,1) input int
> ! Return objects:
> !   a : rank-2 array('i') with bounds (m,n)
>
> ! >>> print fun.bar(a)
> ! C:m=2, n=3
> ! Row 1:
> ! a(i=0,j=0)=1
> ! a(i=0,j=1)=2
> ! a(i=0,j=2)=3
> ! Row 2:
> ! a(i=1,j=0)=4
> ! a(i=1,j=1)=5
> ! a(i=1,j=2)=6
> ! [[7777    2    3]
> !  [   4    5    6]]
>
>     end interface
> end python module fun
>
>





More information about the Scipy-dev mailing list