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

Compile main Python program using Cython

Contrary to what Adam Matan and others assert, you can in fact create a single executable binary file using Cython, from a pure Python (.py) file. Yes, Cython is intended to be used as stated – as a way of simplifying writing C/C++ extension modules for the CPython python runtime. But, as nudzo alludes to … Read more

How to specify Python 3 source in Cython’s setup.py?

One can pass language_level as an option to the cythonize-function in the setup.py-script: ext_modules = cythonize( extensions, compiler_directives={‘language_level’ : “3”} # or “2” or “3str” ) Another possible syntax is ext_modules = cythonize(extensions, language_level = “3”) The above might be more convenient than to add #cython: language_level=3 to every pyx-file in the project, which might … Read more

How should I structure a Python package that contains Cython code

I’ve done this myself now, in a Python package simplerandom (BitBucket repo – EDIT: now github) (I don’t expect this to be a popular package, but it was a good chance to learn Cython). This method relies on the fact that building a .pyx file with Cython.Distutils.build_ext (at least with Cython version 0.14) always seems … Read more

Cython: “fatal error: numpy/arrayobject.h: No such file or directory”

In your setup.py, the Extension should have the argument include_dirs=[numpy.get_include()]. Also, you are missing np.import_array() in your code. — Example setup.py: from distutils.core import setup, Extension from Cython.Build import cythonize import numpy setup( ext_modules=[ Extension(“my_module”, [“my_module.c”], include_dirs=[numpy.get_include()]), ], ) # Or, if you use cythonize() to make the ext_modules list, # include_dirs can be passed … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)