Specifically:
- How to provide
numpy.ndarrayas a function output data type and - How to use
cimport numpyinstead ofimport numpyto create an array without Python overhead?
The code below works if numpy.ndarray is removed from the line cdef numpy.ndarray array(int start, int end):. According to the annotation it still has a lot of Python overhead (excluding the range(start, end) initialisation of the C++ vector).
%%cython -a
# distutils: language = c++
import numpy
from libcpp.vector cimport vector
cdef numpy.ndarray array(int start, int end):
cdef vector[int] vect = range(start, end)
return numpy.array(vect)
print(array(1,15))