[Numpy-discussion] Array views

Dag Sverre Seljebotn d.s.seljebotn@astro.uio...
Tue Mar 29 03:03:56 CDT 2011


On 03/29/2011 09:35 AM, Pearu Peterson wrote:
>
>
> On Tue, Mar 29, 2011 at 8:13 AM, Pearu Peterson 
> <pearu.peterson@gmail.com <mailto:pearu.peterson@gmail.com>> wrote:
>
>
>
>     On Mon, Mar 28, 2011 at 10:44 PM, Sturla Molden <sturla@molden.no
>     <mailto:sturla@molden.no>> wrote:
>
>         Den 28.03.2011 19:12, skrev Pearu Peterson:
>         >
>         > FYI, f2py in numpy 1.6.x supports also assumed shape arrays.
>
>         How did you do that? Chasm-interop, C bindings from F03, or
>         marshalling
>         through explicit-shape?
>
>
>     The latter.
>      Basically, if you have
>
>     subroutine foo(a)
>     real a(:)
>     end
>
>     then f2py automatically creates a wrapper subroutine
>
>     subroutine wrapfoo(a, n)
>     real a(n)
>     integer n
>     !f2py intent(in) :: a
>     !f2py intent(hide) :: n = shape(a,0)
>     interface
>     subroutine foo(a)
>     real a(:)
>     end
>     end interface
>     call foo(a)
>     end
>
>     that can be wrapped with f2py in ordinary way.
>
>         Can f2py pass strided memory from NumPy to Fortran?
>
>
>     No. I haven't thought about it.
>
>
> Now, after little bit of thinking and testing, I think supporting 
> strided arrays in f2py
> is easily doable. For the example above, f2py just must generate the 
> following wrapper subroutine
>
> subroutine wrapfoo(a, stride, n)
> real a(n)
> integer n, stride
> !f2py intent(in) :: a
> !f2py intent(hide) :: n = shape(a,0)
> !f2py intent(hide) :: stride = getstrideof(a)
> interface
> subroutine foo(a)
> real a(:)
> end
> end interface
> call foo(a(1:stride:n))
> end

I think it should be a(1:n*stride:stride) or something.

Dag Sverre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110329/1b0a460e/attachment.html 


More information about the NumPy-Discussion mailing list