Skip to content

Instantly share code, notes, and snippets.

@AcidLeroy
Created April 8, 2016 00:50
Show Gist options
  • Save AcidLeroy/27a1aff7c4c15652eb33e1828acef95a to your computer and use it in GitHub Desktop.
Save AcidLeroy/27a1aff7c4c15652eb33e1828acef95a to your computer and use it in GitHub Desktop.
Example of how to convert std::vector of doubles to memviews and back using Cython
from libcpp.vector cimport vector
cdef convert_memview_to_vector(double[::1] &mem):
cdef vector[double] arr
arr.reserve(mem.shape[0])
for i in mem:
arr.push_back(i)
return arr
cdef convert_vector_to_memview(vector[double] &vec):
cdef double[::1] mem = <double[:vec.size()]> &vec[0]
return mem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment