Cython: copy memoryview without gil

Viewed 137

I have the following code section (appropriately simplified)

cpdef double func(double[:] x, double[:] y) nogil:
    cdef:
        double[:] _y
    _y = y # Here's my trouble
    _y[2] = 2. - y[1]
    _y[1] = 1.
    return func2(x, _y)

I'm trying to create a copy of y that I can manipulate in the function. The problem is, any changes made to _y get passed back to y. I don't want to make changes to y, just to this temporary copy of it.

The function is nogil, so I can't use _y = y.copy(). (already tried). I also tried _y[:] = y, based on the cython guidance pages, but I apparently can't do that if _y hasn't been initialized yet.

So... how do I make a copy of a 1d vector without invoking the gil?

0 Answers
Related