[Numpy-discussion] Getting Callbacks with arrays to work
jonboym2 at yahoo.co.uk
Tue Jan 12 08:11:02 EST 2010
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:-
cF2PY intent( hide ):: N
INTEGER:: N, ic
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 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
print 'in Python dV: V is: ',v
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion