On Mon, May 24, 2010 at 10:27 AM, jah <[email protected]> wrote: > I need to write to arbitrary portions of an array. If I know they are > both one-dimensional, then I can do something like: > > cdef void func(self, double *x, double *out, Py_ssize_t i=0): > out[i] = x[i] + 1 > out[i+1] = x[i+1] + 2 > > What I'd really like to do is pointer arithmetic, > > cdef void func(self, double *x, double *out): > *out = *x + 1 > *(out+1) = *(x+1) + 2 > > Here, "out" could also be a two-dimensional array and func() is > writing only to a particular row of the matrix. Ideally, I'd like to > have one function that can handle when "x" and "out" point to data of > arbitrary dimensions as func() doesn't care about the dimension. How > can I accomplish this? Do I have to write this in C and then do a > "cdef extern from ..." or can it be done in Cython? >
Nevermind, I forgot that x was the result of PyArray_DATA(x). So I can access all the data with a single index. I just need to pass in indexes for x and out, separately. _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
