Can Cython compile to an EXE?

Here’s the wiki page on embedding cython Assuming you installed python to C:\Python31 and you want to use Microsoft Compiler. smalltest1.py – is the file you want to compile. test.exe – name of the executable. You need to set the environmental variables for cl. C:\Python31\python.exe C:\Python31\Scripts\cython.py smalltest1.py –embed cl.exe /nologo /Ox /MD /W3 /GS- /DNDEBUG … Read more

Force NumPy ndarray to take ownership of its memory in Cython

You just have some minor errors in the interface definition. The following worked for me: from libc.stdlib cimport malloc import numpy as np cimport numpy as np np.import_array() ctypedef np.int32_t DTYPE_t cdef extern from “numpy/arrayobject.h”: void PyArray_ENABLEFLAGS(np.ndarray arr, int flags) cdef data_to_numpy_array_with_spec(void * ptr, np.npy_intp N, int t): cdef np.ndarray[DTYPE_t, ndim=1] arr = np.PyArray_SimpleNewFromData(1, &N, … Read more

What is the recommended way of allocating memory for a typed memory view?

Look here for an answer. The basic idea is that you want cpython.array.array and cpython.array.clone (not cython.array.*): from cpython.array cimport array, clone # This type is what you want and can be cast to things of # the “double[:]” syntax, so no problems there cdef array[double] armv, templatemv templatemv = array(‘d’) # This is fast … Read more