Switch to Cython memoryviews for critical parts of code