[NumPy-Tickets] [NumPy] #1532: f2py does not respect assumed size arrays of fortran 90

NumPy Trac numpy-tickets@scipy....
Thu Jul 1 03:03:40 CDT 2010


#1532: f2py does not respect assumed size arrays of fortran 90
--------------------------+-------------------------------------------------
  Reporter:  ozn          |       Owner:  pearu 
      Type:  enhancement  |      Status:  closed
  Priority:  normal       |   Milestone:  2.0.0 
 Component:  numpy.f2py   |     Version:  1.3.0 
Resolution:  wontfix      |    Keywords:        
--------------------------+-------------------------------------------------
Changes (by pearu):

  * status:  new => closed
  * resolution:  => wontfix


Comment:

 First, a correction: the ticket is about assumed shape arrays, not assumed
 size arrays.

 Supporting assumed shape arrays as wished in this ticket would
 be highly compiler dependent: it will require the knowledge of how the
 description
 of an assumed size array is stored in memory so that f2py could construct
 a proper memory footprint (dope vector) for such arrays. This knowledge is
 not available
 for all popular Fortran compilers, also the Fortran standard does not
 specify
 this implementation detail.

 More explanation is given in
 http://www.ibiblio.org/pub/languages/fortran/ch2-4.html, for example.

 Interestingly, even gfortran cannot handle assumed shape arrays as one
 would expect.
 Consider the following example:
 {{{
 subroutine locpt_wrap(x0,y0,x,y,xd,yd,n,l,m)
         INTEGER, INTENT(IN)  :: xd,yd,n
         REAL, INTENT(IN)     :: x0, y0, x(xd), y(yd)
         INTEGER, INTENT(OUT) :: l, m
         print *, size(x), size(y)
         call locpt(x0,y0,x,y,n,l,m)
  end subroutine locpt_wrap

  subroutine locpt(x0,y0,x,y,n,l,m)
    IMPLICIT NONE
         INTEGER, INTENT(IN)  :: n
         REAL, INTENT(IN)     :: x0, y0, x(:), y(:)
         INTEGER, INTENT(OUT) :: l, m
         print *, x0
         print *, y0
         print *, size(x), size(y)
         print *, x
         print *, y
         print *, 'n', n
         call dsum(x0,x,n)
         print *, 'sum', x0
 END SUBROUTINE locpt
 }}}
 and when running it, one gets:
 {{{
 $ python -c 'import dsum;
 dsum.locpt_wrap(2.0,2.0,(2.0,1.0,3.0),(5.0,6.0,8.0),3)'
            3           3
    2.0000000
    2.0000000
       693657    17400081
 Segmentation fault
 }}}

 That is, while the sizes of x and y are well defined in locpt_wrap,
 then passing them as assumed shape arrays to locpt, the size information
 gets lost.

 On the other hand, when using assumed size arrays, everything works
 as expected:
 {{{
  subroutine locpt_wrap(x0,y0,x,y,xd,yd,n,l,m)
         INTEGER, INTENT(IN)  :: xd,yd,n
         REAL, INTENT(IN)     :: x0, y0, x(xd), y(yd)
         INTEGER, INTENT(OUT) :: l, m
         print *, size(x), size(y)
         call locpt(x0,y0,x,y,n,l,m)
  end subroutine locpt_wrap

  subroutine locpt(x0,y0,x,y,n,l,m)
    IMPLICIT NONE
         INTEGER, INTENT(IN)  :: n
         REAL, INTENT(IN)     :: x0, y0, x(*), y(*)
         INTEGER, INTENT(OUT) :: l, m
         print *, x0
         print *, y0
         !print *, size(x), size(y)
         !print *, x
         !print *, y
         print *, 'n', n
         call dsum(x0,x,n)
         print *, 'sum', x0
 END SUBROUTINE locpt
 }}}
 Test call:
 {{{
 $ python -c 'import dsum;
 dsum.locpt_wrap(2.0,2.0,(2.0,1.0,3.0),(5.0,6.0,8.0),3)'
            3           3
    2.0000000
    2.0000000
  n           3
  sum   6.0000000
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1532#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list