On Thu, 3 Apr 2008 23:19:21 -0400
Gabriel Gellner <[EMAIL PROTECTED]> wrote:
> Sorry for the simple question, but I couldn't figure out how to do this
> myself...
>
> I am wrapping a C-code ode solver that uses a callback after each time step.
> So to save the output I need to append these values to a global array.
>
> Roughly I want to have a calling function that creates a numpy array that the
> callback will write to. The problem is I don't know how to make this kind of
> global variable in cython.
>
> The skeleton that I would like to be able to do (given that I have removed all
> the real logic):
>
> # This is the solution callback (not the model definition for those who use
> # ode solvers) that is the ode solver is returning the *y values after each
> # step.
> cdef void solout(int nr, double *x, double *y):
> # I will have a loop in the future, but as long as I can
> # save a single value to the array I can solve this myself.
> output.data[0][0] = y[0]
>
> # This the python driver
> def ode(t):
global output
> dim = 4 # hard set to make the code short . . .
>
> # Allocate my array
> output = numpy.zeros((4, len(t)))
>
> # set solver values
> y0 = <some kind of array, not important>
> # Call the solver, (I assume func, the model, is defined elsewhere . . .)
> odesolve(func, y0, t)
>
> # now at this point I would want output to have its first row set
>
> I hope this is clear, if my simplification has made it worse I can give a full
> example of what the code would look like (that is I can get everything to work
> with print statements, I just am not able to save the output . . .)
>
> Any help would be greatly appreciated!
>
> Gabriel
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev