[f2py] Example of use of f2py
Pearu Peterson
pearu@cens.ioc.ee
Wed, 30 Oct 2002 13:42:32 +0200 (EET)
On Tue, 29 Oct 2002, Simon Lacoste-Julien wrote:
> Hello Pearu,
>
> As I had promised [but with only a 2 months delay ;-) ], I have
> documented my work with f2py and DDASSL in a report available on my
> web site:
Thanks for the feedback!
Few notes:
I don't completely agree with your arguments in favor of using
intent(inout), in particular, about the performance implications on the
automatic copying by the f2py generated interface. Let me note again,
f2py generated interface makes copies *only* when it is really necessary.
If the input data is already properly aligned, then no copies are made,
even when returning arrays.
Using either intent(inout) or intent(in,out) is more a matter of
programming style. With intent(inout) one is forced to use very strict
conditions on the input data, f2py will just give an exception if those
conditions are not satisfied. However, the corresponding Python code
becomes less readable as one has to use lots of hooks to ensure that
users input data satisfies the required conditions.
With intent(in,out) one can write much more concise and readable Python
code as f2py generated interface takes care of the required conversations
automatically but at the same time is equally efficient with the case of
using intent(inout)-style *provided* that the input data already satisfies
the conditions.
In fact, since the automatic conversations are done in C level, an
intent(in,out)-style code is more efficient than the equivalent
intent(inout)-style code where the conversations ought to be done in
Python level, when the input data does not satisfy the conditions.
The only advantage of using intent(inout)-style code can be that it forces
users to use only proper input data. But it has a disadvantage of
putting additional details for users to deal with. My experience is that
it slows down both the code development and its usage; and there is
no real performance gain to make learning (and explaining) the
details of using intent(inout)-style worth. Instead, it is more worth
learning how to code efficiently using intent(in,out)-style as the
resulting code will be more readable for ordinary Python users, and let me
repeat again, its equally or even more efficient than using
intent(inout)-style.
Thanks,
Pearu