<div dir="ltr">Yes, f2py is probably copying the arrays; you can check this by appending<div> -DF2PY_REPORT_ON_ARRAY_COPY=1 to your call to f2py.<br></div><div><br></div><div>I normally prefer to keep the numpy arrays C-order (most efficient for numpy) and simply pass the array transpose to the f2py-ized fortran routine.</div><div>This means that the fortran array indices are reversed, but this is the most natural  way in any case.</div><div><br></div><div>--George Nurser</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 April 2016 at 11:53, Sebastian Berg <span dir="ltr"><<a href="mailto:sebastian@sipsolutions.net" target="_blank">sebastian@sipsolutions.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On So, 2016-04-10 at 12:04 +0200, Vasco Gervasi wrote:<br>
> Hi all,<br>
> I am trying to write some code to do calculation onto an array: for<br>
> each row I need to do some computation and have a number as return.<br>
> To speed up the process I wrote a fortran subroutine that is called<br>
> from python [using f2py] for each row of the array, so the input of<br>
> this subroutine is a row and the output is a number.<br>
> This method works but I saw some speed advantage if I pass the entire<br>
> array to fortran and then, inside fortran, call the subroutine that<br>
> does the math; so in this case I pass an array and return a vector.<br>
> But I noticed that when python pass the array to fortran, the array<br>
> is copied and the RAM usage double.<br>
<br>
</span>I expect that the fortran code needs your arrays to be fortran<br>
contiguous, so the wrappers need to copy them.<br>
<br>
The easiest solution may be to create your array in python with the<br>
`order="F"` flag. NumPy will have a tendency to prefer C-order and uses<br>
it as default though when doing something with an "F" ordered array.<br>
<br>
That said, I have never used f2py, so these are just well founded<br>
guesses.<br>
<br>
- Sebastian<br>
<span class=""><br>
<br>
<br>
> Is there a way to "move" the array to fortran, I don't care if the<br>
> array is lost after the call to fortran.<br>
> The pyd module is generated using: python f2py.py -c --opt="-ffree<br>
> -form -Ofast" -m F2PYMOD F2PYMOD.f90<br>
><br>
> Thanks<br>
> Vasco<br>
</span>> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> <a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div>