Re: [Numpy-discussion] a simple question about f2py

Lisandro Dalcin <dalcinl@gmail.com> kirjoitti:
Im trying to use f2py to wrap some fortran functions wich receive as argument PETSc objects. The usual way to implement this with PETSc+fortran is to do something like this
soubrutine matvec(A,x,y) Mat A Vec x Vec y end soubrutine
The 'Mat' and 'Vec' types are actually integers of appropriate kind, PETSc uses a #define to define them. I there any way I can teach/hack f2py to translate Mat/Vec/etc. to a normal fortran type?
You can tell f2py to use a different type for the argument as follows: subroutine foo(a) !f2py integer, dimension(10), intent(inout) :: a Mat a end subroutine foo This way, f2py will treat the parameter as a chunk of memory of size 10*sizeof(integer), and disregard any following definitions for it. Using a hack like this, it's also possible to pass derived type object pointers, "type(Typename), pointer", from the Python side to the Fortran side, as opaque handles. -- Pauli Virtanen

Using a hack like this, it's also possible to pass derived type object >pointers, "type(Typename), pointer", from the Python side to
On 10/24/07, Pauli Virtanen <ptvirtan@elisanet.fi> wrote: the >Fortran side, as opaque handles. Could you please send/point me an example of how I can actually pass Fortran pointers between Python and Fortran? I cannot get that working... I'm trying to allocate arrays in Fortran, get a opaque handle to it in Python, and finally pass-back the pointer to Fortran for deallocation... Is this possible? -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594

Using a hack like this, it's also possible to pass derived type object >pointers, "type(Typename), pointer", from the Python side to
Pauli, I finally understood your idea!!!! What a good hack!!! You have to pass an integer array with enough space in order Fortran con store there some extra metadata, no just the buffer pointer, but also dimensions and some other runtime stuff. Many, many, many thanks.... On 10/24/07, Pauli Virtanen <ptvirtan@elisanet.fi> wrote: the >Fortran side, as opaque handles. -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594
participants (2)
-
Lisandro Dalcin
-
Pauli Virtanen