[Numpy-discussion] f2py with allocatable arrays

Casey W. Stark caseywstark at gmail.com
Tue Jul 3 14:38:36 EDT 2012


Hi all.

Thanks for the speedy responses! I'll try to respond to all...

The first idea is to split up the routine into two -- one to compute the
final size of the arrays, and the second to fill them in. I might end up
doing this, because it is simplest, but it means creating the initial
conditions twice, throwing them away the first time. Not a huge deal
because this setup is not that big (a few minutes), but it will take twice
as long.

Sturla, this is valid Fortran, but I agree it might just be a bad idea. The
Fortran 90/95 Explained book mentions this in the allocatable dummy
arguments section and has an example using an array with allocatable,
intent(out) in a subrountine. You can also see this in the PDF linked from
http://fortranwiki.org/fortran/show/Allocatable+enhancements. I have never
used array pointers in Fortran, but I might give this a shot. Are there any
problems returning pointers to arrays back to python though?

As for storing the arrays in the module data block, I would like to avoid
that approach if possible. It doesn't make sense for these to be module
level components when the size and values depend on the input to a
subroutine in the module.

Best,
Casey


On Tue, Jul 3, 2012 at 10:24 AM, Pearu Peterson <pearu.peterson at gmail.com>wrote:

>
>
> On Tue, Jul 3, 2012 at 5:20 PM, Sturla Molden <sturla at molden.no> wrote:
>
>>
>> As for f2py: Allocatable arrays are local variables for internal use,
>> and they are not a part of the subroutine's calling interface. f2py only
>> needs to know about the interface, not the local variables.
>>
>
> One can have allocatable arrays in module data block, for instance, where
> they a global. f2py supports wrapping these allocatable arrays to python.
> See, for example,
>
>
> http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#allocatable-arrays
>
> Pearu
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120703/c38555c8/attachment.html>


More information about the NumPy-Discussion mailing list