cython

How to profile cython functions line-by-line

别等时光非礼了梦想. 提交于 2019-12-27 20:08:17
问题 I often struggle to find bottlenecks in my cython code. How can I profile cython functions line-by-line? 回答1: Robert Bradshaw helped me to get Robert Kern's line_profiler tool working for cdef functions and I thought I'd share the results on stackoverflow . In short, set up a regular .pyx file and build script and add the following before your call to cythonize . from Cython.Compiler.Options import directive_defaults directive_defaults['linetrace'] = True directive_defaults['binding'] = True

When i compile my python code i get: RecursionError: maximum recursion depth exceeded while calling a Python object

时光怂恿深爱的人放手 提交于 2019-12-25 18:43:11
问题 edit: Tried the equivalent code with pyqt5 compiled with cython. It works swimmingly so this seems to be a pyside2 bug. Latest version of cython. My app works fine when i run it with python but when i make it into a module and import the module from a simple launcher script suddenly it doesn't seem to see any data from the internet and it also gives me these: RecursionError: maximum recursion depth exceeded while calling a Python object. Nuitka has the same problem but doesn't give me these

cython memoryviews slices without GIL

こ雲淡風輕ζ 提交于 2019-12-25 12:40:09
问题 I want to release the GIL in order to parallelise loop in cython, where different slices of memoryviews are passed to a some function inside the loop. The code looks like this: cpdef void do_sth_in_parallel(bint[:,:] input, bint[:] output, int D): for d in prange(D, schedule=dynamic, nogil=True): ouput[d] = some_function_not_requiring_gil(x[d,:]) This is not possible, since selecting the slice x[d,:], seems to require GIL. Running cython -a , and using a normal for loop, I get the code posted

compiling cython modules when gcc is on the PATH in OSX

送分小仙女□ 提交于 2019-12-25 09:59:11
问题 I'm trying to use distutils to compile a cython module using Enthought Canopy's version of python; however it's clear there is a mixup between gcc and clang. Distutils is trying to compile the module using gcc and the clang option -arch x86_64 . The problem is that I have gcc installed from macports, so gcc isn't just a link to clang. I can get the module to compile using CC='clang' ./setup.py build_ext , but this feels a little hacky in terms of distributing the module. Is there something I

compiling cython modules when gcc is on the PATH in OSX

孤人 提交于 2019-12-25 09:58:29
问题 I'm trying to use distutils to compile a cython module using Enthought Canopy's version of python; however it's clear there is a mixup between gcc and clang. Distutils is trying to compile the module using gcc and the clang option -arch x86_64 . The problem is that I have gcc installed from macports, so gcc isn't just a link to clang. I can get the module to compile using CC='clang' ./setup.py build_ext , but this feels a little hacky in terms of distributing the module. Is there something I

How can I use python distutils to cross compile an extension module to a different architecture?

那年仲夏 提交于 2019-12-25 09:12:49
问题 I'm using Cython to generate compiled .so files for a couple of python modules I have. As outlined in the Cython documentation, you can create a setup.py file as follows: from distutils.core import setup from Cython.Build import cythonize setup( ext_modules = cythonize([ 'MyModule1.py', 'MyModule2.py', 'MyModule3.py' ]) ) and then build the modules using the command python3 setup.py build_ext --inplace . This works fine, however it creates binaries that match the architecture of the host

Cython actually slowing me down

早过忘川 提交于 2019-12-25 08:29:57
问题 I am trying to 'cythonize' my code however while the following code does work, it is not adding any speed to my code (in fact its a shade slower). I am wondering if anyone knows what I am doing wrong if anything at all. Note I am passing a numpy array and its data type should be float16. Never used cython before and I am using Jupyter notebook right now. In the cell above I have Cython loaded. %%cython import numpy as np cimport numpy as np DTYPE = np.float16 ctypedef np.int_t DTYPE_t def

Writing Cython extension: how to access a C struct internal data from Python?

让人想犯罪 __ 提交于 2019-12-25 08:06:04
问题 Disclaimer: I took the following example from the Python Cookbook (O'Reilly). Let's say I have the following simple struct : typedef struct { double x,y; } Point; with a function that calculates the Euclidean distance between two Point s: extern double distance(Point* p1, Point* p2); All this is part of a shared library called points : points.h - the header file points.c - the source file libpoints.so - the library file (the Cython extension links against it) I have created my wrapping Python

ld.exe: cannot find -lvcruntime140 when compiling previously working Cython module on new 3.5 install

纵饮孤独 提交于 2019-12-25 06:41:01
问题 I'm afraid I don't really know what to provide here. I'm a bit lost. Google sends me in entirely irrelevant directions. I've just upgraded to Python 3.5 and am now trying to get my current project working with it. Unfortunately, part of it is done in Cython, and I've had to spend the last three days trying to get Python to talk to MinGW. Now I've done that via this patch, but the compilation still fails. This file compiled flawlessly previously, so presumably it's something about the way

Cython - importing cython modules and merging them into single shared object

巧了我就是萌 提交于 2019-12-25 05:00:54
问题 I am trying to wrap python functions to C++ apis using Cython. I have 2 modules sam1.pyx and sam2.pyx ## - sam1.pyx import sam2 cdef public double calc(double x, double y): return sam2.calc_sub(x,y) the contents of the file sam2.py is as follows ## - sam2.py def calc_sub(x, y): return x*y with such a structure, the wrapped sam1.h along with the corresponding sam1.so are generated During the usage in Cpp application, #include<iostream> #include<Python.h> #include"sam1.h" using namespace std;