cython

Pass file handle to cython function

安稳与你 提交于 2019-12-19 09:02:51
问题 I want to compile a python function with cython, for reading a binary file skipping some records (without reading the whole file and then slicing, as I would run out of memory). I can come up with something like this: def FromFileSkip(fid, count=1, skip=0): if skip>=0: data = numpy.zeros(count) k = 0 while k<count: try: data[k] = numpy.fromfile(fid, count=1, dtype=dtype) fid.seek(skip, 1) k +=1 except ValueError: data = data[:k] break return data and then I can use the function like this: f =

Can cython be compiled with icc?

*爱你&永不变心* 提交于 2019-12-19 08:29:50
问题 I am trying to build cython from source with icc compiler on Ubuntu 14.04 as my python is compiled with Intel icc compiler. When I tried to install cython using pip3 install cython and then ran cython I got following error Traceback (most recent call last): File "/usr/local/bin/cython", line 9, in <module> load_entry_point('Cython==0.24', 'console_scripts', 'cython')() File "/usr/lib/python3/dist-packages/pkg_resources.py", line 351, in load_entry_point return get_distribution(dist).load

Converting malloc'ed buffers from C to Python without copy using Cython?

余生长醉 提交于 2019-12-19 08:28:24
问题 In Cython, say I have a C function that returns a large buffer allocated with malloc() and expected to be freed later with free(). Now I need to pass this buffer to Python as a (bytes) str object, which would acquire ownership of it, and call free() later when the str object goes away. Is this possible and how? 回答1: Have a look at https://gist.github.com/1249305 for a implementation using numpy. If numpy is not an option then something like this could work, using a memoryview: from libc

Cannot install Cython on win7

亡梦爱人 提交于 2019-12-19 08:13:15
问题 So I'm trying to use Cython on ta-lib, and I'm using the wrapper provided by mrjbq7 (many thanks..). So I tried to install Cython-0.19.1 on my computer and then do python setup.py install on ta-lib-master (the wrapper), and I got the following: running install running build running build_py running biuld_ext failed to import Cython: No module named 'Actions' error: Cython does not appear to be installed I tried to build Cython with python setup.py build_ext --inplace Can anyone please help me

Cannot install Cython on win7

筅森魡賤 提交于 2019-12-19 08:13:00
问题 So I'm trying to use Cython on ta-lib, and I'm using the wrapper provided by mrjbq7 (many thanks..). So I tried to install Cython-0.19.1 on my computer and then do python setup.py install on ta-lib-master (the wrapper), and I got the following: running install running build running build_py running biuld_ext failed to import Cython: No module named 'Actions' error: Cython does not appear to be installed I tried to build Cython with python setup.py build_ext --inplace Can anyone please help me

how to document cython function on readthedocs

笑着哭i 提交于 2019-12-19 05:34:10
问题 On ReadTheDocs I am not allowed to compile cython extensions, is it possible to configure sphinx in order to extract the docstrings from the cython files without actually compiling them? thanks! 回答1: I faced the same problem and found that it is possible now to compile Cython extensions on readthedocs. Short answer: Cython modules can be compiled using the virtualenv feature provided by readthedocs. For a slightly longer answer and an example project see below. What is the problem? As I have

how to document cython function on readthedocs

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 05:34:07
问题 On ReadTheDocs I am not allowed to compile cython extensions, is it possible to configure sphinx in order to extract the docstrings from the cython files without actually compiling them? thanks! 回答1: I faced the same problem and found that it is possible now to compile Cython extensions on readthedocs. Short answer: Cython modules can be compiled using the virtualenv feature provided by readthedocs. For a slightly longer answer and an example project see below. What is the problem? As I have

Cython conditional compilation based on external value given via `setuptools`

浪尽此生 提交于 2019-12-19 04:05:09
问题 I try to conditionally generate C code from a Cython pyx file. I found in the Cython documentation that I can use DEF to define a value and IF to conditionally generate code based on a defined value, but how can I set the value from the setup.py via Extension from setuptools . Thank You 回答1: Thank you for the link. The interesting flag in the setup.py is cython_compile_time_env . And to import the Extension from Cython. from setuptools import setup from Cython.Distutils.extension import

Cython buffer declarations for object members

与世无争的帅哥 提交于 2019-12-18 18:55:16
问题 I want to have a Cython "cdef" object with a NumPy member, and be able to use fast buffer access. Ideally, I would do something like: import numpy as np cimport numpy as np cdef class Model: cdef np.ndarray[np.int_t, ndim=1] A def sum(self): cdef int i, s=0, N=len(self.A) for 0 <= i < N: s += self.A[i] return s def __init__(self): self.A = np.arange(1000) Unfortunately, Cython can't compile this, with the error Buffer types only allowed as function local variables . The workaround I'm using

Change Cython's naming rules for .so files

浪尽此生 提交于 2019-12-18 15:03:34
问题 I'm using Cython to generate a shared object out of Python module. The compilation output is written to build/lib.linux-x86_64-3.5/<Package>/<module>.cpython-35m-x86_64-linux-gnu.so . Is there any option to change the naming rule? I want the file to be named <module>.so without the interpreter version or arch appendix. 回答1: Seems like setuptools provides no option to change or get rid of the suffix completely. The magic happens in distutils/command/build_ext.py : def get_ext_filename(self,