[f2py] A mostly working example

Pearu Peterson pearu@cens.ioc.ee
Fri, 22 Mar 2002 21:00:04 +0200 (EET)


On 22 Mar 2002, James Amundson wrote:

> Hi,
> 
> I just started working with f2py. It looks like it does exactly what I
> need. I was just about to give up on it because the documentation is so
> misleading when I found the messages on the mailing list in the thread
> "trouble with simple example." Unfortunately, the instructions given
> there don't work with the snapshot I just downloaded (2.13.175-1233),
> either. After some hacking, I finally got the simple example to mostly
> work. I have appended the mostly working example to the end of this
> message.

Thanks for keeping trying. I'll try to find some time to rewrite the docs
really soon...

> I keep saying "mostly working" because I don't understand this behavior:
> 
> 
> >>> x = 1 
> >>> print x,foobar.foo(x),x
> 1 None 1
> >>> from Numeric import *
> >>> a = array(1)
> >>> print a,foobar.foo(a),a
> 1 None 6
> >>>
> 
> Why does the argument to foo only get modified if it is a Numeric array?
> Is that the desired behavior?

Yes, and it is the only possible behaviour because Python integers are
immutable and they cannot modified in situ. Numeric array is mutable and
it can be modified in situ.

However note that using intent(inout) variables are depreciated exactly
due to this issue. Using intent(in,out) is recommended for
variables that are both input and output.

Regards,
	Pearu