cython

Cython Precompiler decision making [closed]

自闭症网瘾萝莉.ら 提交于 2019-12-25 02:22:56
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . I am looking for a solution to add pre-compiler logic in a cython file. I have written a cython wrapper for a hardware device API that is in C++. This is a cython project that is typically compiled using MSVC for python 2.7 and 3.6. The entire package is written in cython without need for an

Usage of threadpoolexecutor in conjunction with cython's nogil

耗尽温柔 提交于 2019-12-25 01:55:11
问题 I have read this question and answer -Cython nogil with ThreadPoolExecutor not giving speedups and I have a similar problem with my Cython code not getting the speedup that is expected in spite of my system having multiple cores. I have 4 physical cores on a Ubuntu 18.04 instance and if I make the number of jobs to be 1 in the code below it runs faster than when I make it 4. Looking at the CPU usage using top I see the CPU usage go upto 300 %. I am doing the lookup of a data structure in a C+

How to work with 2D array returned from c function using Cython?

与世无争的帅哥 提交于 2019-12-25 00:36:23
问题 I have had success in sending numpy arrays to c functions with Cython. Whenever I have a function in c that takes int * and I have some variable in python, call it arr , that is 1D numpy array I just call the function with &arr[0] and it works. Now I'm interested in receiving a 2D array created with a c function. How can I do this? Below is what I've tried. // this is the c code that returns a 2D array int **make_array() { int nrows = 3; int ncols = 5; int **ret = malloc(nrows * sizeof(int *)

Removing Python overhead when wrapping C++ vectors

荒凉一梦 提交于 2019-12-24 22:12:40
问题 from libcpp.algorithm cimport sort as stdsort from libcpp.algorithm cimport unique from libcpp.vector cimport vector # from libcpp cimport bool cimport cython @cython.boundscheck(False) @cython.wraparound(False) @cython.initializedcheck(False) cdef class Vector: cdef vector[cython.int] wrapped_vector # the easiest thing to do is add short wrappers for the methods you need def push_back(self, int num): self.wrapped_vector.push_back(num) def sort(self): stdsort(self.wrapped_vector.begin(), self

Serialize a group of integers using cython

假如想象 提交于 2019-12-24 20:50:25
问题 I saw this sample code from the Pyrobuf page for serializing an integer ~3 times faster than via struct.pack : def ser2(): cdef int x = 42 return (<char *>&x)[:sizeof(int)] I was wondering how this could be done for a group of integers. I saw cython has int[:] and array.array types, but I still don't understand how do I take a list of integers for example, and get the same (but faster) result as via struct.pack('i', *num_list) . map() didn't seem work faster for me, and I'm wondering how this

ImportError in Cython

吃可爱长大的小学妹 提交于 2019-12-24 19:18:23
问题 I'm fairly new to cython, so I have a basic question. I'm trying to import a base class from one cython file into another cython file to define a derived class. I have the following code in a single directory called cythonTest/ : afile.pxd afile.pyx bfile.pxd bfile.pyx __init__.py setup.py afile.pxd: cdef class A: pass afile.pyx: cdef class A: def __init__(self): print("A__init__()") bfile.pxd: from afile cimport A cdef class B(A): pass bfile.pyx: cdef class B(A): def __init__(self): print "B

Use of cython pure python mode in C

淺唱寂寞╮ 提交于 2019-12-24 19:13:56
问题 As far as I understood the pure python mode, it seems possible to use a script python with augmenting pxd in order to use the python function directly in a C program. I am looking for a way to do so since I am stuck on the program compilation with the following errors: gcc -L/usr/local/python-gnu-2.7.8/lib -lpython2.7 -I/usr/local/python-gnu-2.7.8/include/python2.7 -I. -L. -lfoo -o main main.o main.o: In function `main': /d/sverley/Etudes/SIMELING/LivBinh052018/static_model/test_cython/main.c

Global name 'col2im_6d_cython' is not defined, CS231n

二次信任 提交于 2019-12-24 17:18:58
问题 I'm following CS231n and met a problem when doing assignment2: ConvolutionalNetworks: global name 'col2im_6d_cython' is not defined . I think the problem was due to a failure in importing functions from im2col_cython.pyx , which used cython. I've installed Xcode 7.3.1, as shown below, but the problem was still not solved. I'm running the ipynb files in Jupyter from Anaconda. There is a related discussion on reddit, but unfortunately the solution here was for Windows, not Mac OS X. Thank you

TA-Lib installation Error: Must use python with unicode enabled

旧街凉风 提交于 2019-12-24 16:29:27
问题 when I try to install ta-lib(a technical analysis library coded originally in C) for Python using a wrapper for Python and Cython, I get an error message saying "Must use python with unicode enabled". I have already tried googling to no avail. Here's the full error message: C:\Python27\Lib\site-packages\ta-lib-master>python setup.py install running install running build running build_ext skipping 'talib.c' Cython extension (up-to-date) building 'talib' extension C:\Program Files (x86)

Something wrong when I compile cython with C++

偶尔善良 提交于 2019-12-24 14:34:24
问题 I try to compile the OpenSource Cython Project(https://github.com/seanbell/intrinsic) with gcc. But something is wrong when I use the orde "python setup.py build_ext -i". I have spent several days on it, but it doesn't work and returns the following error when building. C:\intrinsic-master\bell2014\krahenbuhl2013>python setup.py build_ext -i Compiling krahenbuhl2013.pyx because it changed. Cythonizing krahenbuhl2013.pyx Error compiling Cython file: --------------------------------------------