Oooo. This looks slow. Not for this PR, but have you investigated the possibility of implementing Cython kernels?