python - Cython memoryviews error: Invalid index for memoryview specified -
i'm trying implement standard quicksort in cython using memoryviews. here code:
def quicksort_cython(double[:] l): _quicksort(l, 0, len(l) - 1) cdef void _quicksort(double[:] l, double start, double stop): cdef double pivot, left, right, tmp if stop - start > 0: pivot = l[start] left = start right = stop while left <= right: while l[left] < pivot: left += 1 while l[right] > pivot: right -= 1 if left <= right: tmp = l[left] l[left] = l[right] l[right] = tmp left += 1 right -= 1 _quicksort(l, start, right) _quicksort(l, left, stop)
however, during compilation standard setup.py
file , python setup.py build_ext --inplace
command multiple errors regarding memoryview access:
error compiling cython file: ------------------------------------------------------------ ... cdef void _quicksort(double[:] l, double start, double stop): cdef double pivot, left, right, tmp if stop - start > 0: pivot = l[start] ^ ------------------------------------------------------------ quicksort_cython_opt3.pyx:9:23: invalid index memoryview specified
can tell me doing wrong? performance improving tips appreciated i'm new cython.. thanks!
typically doubles can't indices (should ints). assume that's problem...although i'm admittedly not familiar cython memoryviews.
Comments
Post a Comment