[f2py] Example of use of f2py
Simon Lacoste-Julien
simonlacoste@videotron.ca
Wed, 30 Oct 2002 17:51:53 -0500
<snip>
> 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
I agree with your arguments about performance, and also about Python style
of
programming, in favour of intent(in,out) vs. intent(inout). But besides the
'advantage' that you mentionned just above for intent(inout), let
me mention another advantage, which was the one which made me
choose intent(inout) instead of intent(in,out) for the extension of Python
with DASSL. It is the 'reusing of the interface already there'
advantage...
In my case, I wanted to test if I could use DASSL from Python, and
that's it. I didn't want to design a new (better) interface to use it from
Python, since I didn't know yet how I wanted to use it from Python
in my simulator [since the simulator will be redesigned completely
in the future]. The consequence of using intent(in,out) is that
the interface is changed in a way, since now you have to
read a tuple which gets returned... This is nice in the Python-way
of programming, but forces you to make some design decision
about which argument will be returned, in which order, etc.,
which is not necessarily useful if you had already 13 arguments
in the function (ddassl) and a well-documented interface
(in the Fortran code). So I had simply postponed those
decisions later in my code development process, and I just
*reused* the Fortran interface which was already there.
I was planning to build a cleaner interface in Python later.
This is less efficient, as you said, but it permits to be more
transparent about what is happening with the data translation
phase (assuming we are not too sure about what was happening
inside f2py interface - as I was) since you then code it in Python.
And it permits to have some type checking done manually,
with some meaningful error messages... But I guess you'll say
that one of the points of f2py is to have this done automatically,
and you're right. But since there is not yet a detailed
documentation about f2py available easily, well, ;-),
the 'safer' way that I saw was chosen...
And so that's why I used intent(inout).
sincerely,
Simon