Re: [f2py] "natural" Fortran calling conventions?

Thomas Breuel <[email protected]>
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
> 1. Use default python arrays (c-order) and make your subroutine
> arguments intent(c).

I don't want my Fortran subroutine to have intent(c); if I did that,
I'd have to write an intent(c) wrapper for every Fortran routine I
want to call, which defeats the purpose.  Or if I write Fortran code
optimized for intent(c), it won't be idiomatic Fortran and hard to
maintain.

> 2. Use the default intent(f) for your subroutine arguments and use
> fortran-order arrays in python (as created by asfortranarray()).

I don't want to use Fortran arrays in Python.  Among other things,
Python (and C) code isn't tuned for Fortran index order.

What I would like is for C/Python-style arrays to turn into the
obvious corresponding Fortran style arrays.  That means that the index
order gets reversed, and the index values are treated with different
offsets.  And I'd like that with an error message if it can't be done
efficiently (e.g., if I accidentally pass an asfortranarray() to
Fortran) or if the indexes are wrong.

Again, I think a primary use case for f2py is to speed up really
compute intensive algorithms.  For those, the fastest varying index
drives the loop order, and that drives the rest of the data layout.
That means that when I implement the same algorithm in Fortran and C,
I will will end up with the same data layout in memory and the same
inner loops, they just use different notation to access the data.
Right now, I can't hook up an efficiently written Fortran library to
an efficiently written C library because f2py forces either the
Fortran side or the C side to use an unnatural array layout for the
same data.

I'm not saying the other facilities should be dropped, I'm just saying
that intent(natural) would be nice to have.  Furthermore,
intent(natural) should probably complain if it needs to copy.

Tom
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.