[f2py] pass numpy.memmap object in fortran-order to f2py extension

Steve Schmerler elcorto at gmx.net
Thu Aug 14 16:25:01 EEST 2008


Hi all

I have a numpy.memmap'ed a file (3d array) in Fortran order and pass this to a
f2py-generated extension. I wonder why the wrapper makes a copy of the array
even if it's in F-order already. Please see attached files. 

This is with numpy 1.1.0 and it's f2py 2_5237. Thanks for any hints! 

    $ make -f Makefile.foo
    $ python foo.py

Result is:

    a.shape: (8, 200, 3)
    a.flags:   C_CONTIGUOUS : True
      F_CONTIGUOUS : False
      OWNDATA : True
      WRITEABLE : True
      ALIGNED : True
      UPDATEIFCOPY : False
    ---------------
    b.shape: (8, 200, 3)
    b.flags:   C_CONTIGUOUS : False
      F_CONTIGUOUS : True
      OWNDATA : False
      WRITEABLE : False
      ALIGNED : True
      UPDATEIFCOPY : False
    ---------------
    foo(a)
    copied an array: size=4800, elsize=8
    ---------------
    foo(N.array(a, order='F'))
    ---------------
    foo(b)
    copy here on my machine, why?           <<<<<<<<<<<<<<<<<
    copied an array: size=4800, elsize=8
    ---------------

best,
steve
-------------- next part --------------
! vim:let fortran_more_precise=1:let fortran_free_source=1

subroutine foo(a, nx, ny, nz)
    implicit none
    integer, intent(in) :: nx, ny, nz
    double precision, intent(in) :: a(nx, ny, nz)
    return
end subroutine foo


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.py
Type: text/x-python
Size: 684 bytes
Desc: not available
Url : http://cens.ioc.ee/pipermail/f2py-users/attachments/20080814/6945d61b/foo.py
-------------- next part --------------
!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module _foo ! in 
    interface  ! in :_foo
        subroutine foo(a,nx,ny,nz) ! in :_foo:foo.f90
            double precision dimension(nx,ny,nz),intent(in) :: a
            integer optional,intent(in),check(shape(a,0)==nx),depend(a) :: nx=shape(a,0)
            integer optional,intent(in),check(shape(a,1)==ny),depend(a) :: ny=shape(a,1)
            integer optional,intent(in),check(shape(a,2)==nz),depend(a) :: nz=shape(a,2)
        end subroutine foo
    end interface 
end python module _foo

! This file was auto-generated with f2py (version:2_5237).
! See http://cens.ioc.ee/projects/f2py2e/
-------------- next part --------------
all:
	f2py -h foo.pyf foo.f90 -m _foo --overwrite-signature
	f2py -c foo.pyf foo.f90 --opt='-O2' -DF2PY_REPORT_ON_ARRAY_COPY=1


More information about the f2py-users mailing list