[f2py] intent(inout) scalar arguments
pearu.peterson at gmail.com
Thu Apr 28 08:08:31 EEST 2011
On Thu, Apr 28, 2011 at 7:02 AM, Ben Forbes <bdforbes at gmail.com> wrote:
> I've read section 4.1 "Scalar arguments" in the documentation, but I
> still don't understand why rank-0 arrays must be used. If I have a
> subroutine foo(b)
> end subroutine foo
> and I call from Python using
> Won't a pointer to b get passed through to the C-wrapper and then to
> Fortran? Why wouldn't b be incremented?
Short answer: Python scalars are immutable objects, hence they cannot be
To extend this, if f2py generated module or any extension module would
change Python int object in situ, then there will be global consequences.
Namely, in Python small integer objects are cached and let's say that
scalar.foo would increment `b` in-situ, then the following will happen:
b = 5
--> 15 # this looks ok, but
--> 15 # because the integer object corresponding to `5` contains C int
I hope this example will satisfy your curiosity. If something is still
unclear, then you have to learn the implementation details of Python
objects. The best way to learn that is to go to Python source and read it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the f2py-users