With the help of some generous folks, I obtained a ridiculous gain in speed using cython memory views: Bakeoff Part 1 Python vs Cython vs Cython Typed memory views: LDA by Gibbs Sampling
But: I cant seem to do simple things like add a value to an array of values stored in a memory view. I completely get it that that is not what a typed memoryview is supposed to do. But converting the memory view back to an np.array is slower than tortoises herding cats.
When i try to write a cdef function like:
cdef double[::1] _add(self,double[::1] arr,double val):
cdef double[::1] newarr
cdef int i, n
#n = sizeof(arr)/sizeof(arr[0])
newarr = np.empty(5)
for i in xrange(n):
newarr[i] = arr[i] + val
return newarr
I get errors that say that the memoryviews are not contiguous."ValueError: Buffer and memoryview are not contiguous in the same dimension." Edit This actually does work if the memory view passed is not one thats has been sliced. But it adds 10 seconds to the process! 0.025 to 10+seconds....arrgh. And i may need three of these!
I am new to this stuff, but hoping there is some easy way to address this. otherwise, I have speedily reached the cells I want, but cant seem to do much with them :-).
I will be happy to include any methods to see how the calculation runs in terms of speed.