[Numpy-discussion] Getting Callbacks with arrays to work

Jon Moore jonboym2@yahoo.co...
Tue Jan 12 07:11:02 CST 2010


Hi,

I'm trying to build a differential equation integrator and later a stochastic differential equation integrator.

I'm having trouble getting f2py to work where the callback itself receives an array from the Fortran routine does some work on it and then passes an array back.  

For the stoachastic integrator I'll need 2 callbacks both dealing with arrays.

The idea is the code that never changes (ie the integrator) will be in Fortran and the code that changes (ie the callbacks defining differential equations) will be different for each problem.

To test the idea I've written basic code which should pass an array back and forth between Python and Fortran if it works right.

Here is some code which doesn't work properly:-

SUBROUTINE CallbackTest(dv,v0,Vout,N)
    !IMPLICIT NONE
        
cF2PY     intent( hide ):: N
    INTEGER:: N, ic
                
    EXTERNAL:: dv        

    DOUBLE PRECISION, DIMENSION( N ), INTENT(IN):: v0        
    DOUBLE PRECISION, DIMENSION( N ), INTENT(OUT):: Vout
            
    DOUBLE PRECISION, DIMENSION( N ):: Vnow
    DOUBLE PRECISION, DIMENSION( N )::  temp
        
    Vnow = v0
        

    temp = dv(Vnow, N)

    DO ic = 1, N
        Vout( ic ) = temp(ic)
    END DO    
        
END SUBROUTINE CallbackTest



When I test it with this python code I find the code just replicates the first term of the array!




from numpy import *
import callback as c

def dV(v):
    print 'in Python dV: V is: ',v
    return v.copy()    

arr = array([2.0, 4.0, 6.0, 8.0])

print 'Arr is: ', arr

output = c.CallbackTest(dV, arr)

print 'Out is: ', output




Arr is:  [ 2.  4.  6.  8.]

in Python dV: V is:  [ 2.  4.  6.  8.]

Out is:  [ 2.  2.  2.  2.]



Any ideas how I should do this, and also how do I get the code to work with implicit none not commented out?

Thanks

Jon


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100112/064c03d5/attachment-0001.html 


More information about the NumPy-Discussion mailing list