cython

How to correct bugs in this Damerau-Levenshtein implementation?

送分小仙女□ 提交于 2019-12-30 05:14:10
问题 I'm back with another longish question. Having experimented with a number of Python-based Damerau-Levenshtein edit distance implementations, I finally found the one listed below as editdistance_reference() . It seems to deliver correct results and appears to have an efficient implementation. So I set down to convert the code to Cython. on my test data, the reference method manages to deliver results for 11,000 comparisons (for pairs of words aound 12 letters long), while the Cythonized method

Building minimal cython file with python 3.3 (Anaconda) under windows 7

≯℡__Kan透↙ 提交于 2019-12-30 04:37:05
问题 When I try to build a minimal Cython file test.pyx with Python 3.3 (Anaconda 3) under windows 7, I obtain a strange error: C:\Users\myname\Test_cython>python setup.py build running build running build_ext error: [WinError 2] The system cannot find the file specified Of course test.pyx is in the working directory. It works fine under windows with Python 2.7 (Anaconda) and under Linux with Python 2 and 3. What could be the problem here with Python 3.3 (Anaconda 3)? Thanks The file setup.py:

Building Cython-compiled python code with PyInstaller

一笑奈何 提交于 2019-12-29 14:22:52
问题 I am trying to build a Python multi-file code with PyInstaller . For that I have compiled the code with Cython , and am using .so files generated in place of .py files. Assuming the 1st file is main.py and the imported ones are file_a.py and file_b.py , I get file_a.so and file_b.so after Cython compilation. When I put main.py , file_a.so and file_b.so in a folder and run it by "python main.py" , it works. But when I build it with PyInstaller and try to run the executable generated, it throws

How should I structure a Python package that contains Cython code

耗尽温柔 提交于 2019-12-29 10:03:25
问题 I'd like to make a Python package containing some Cython code. I've got the the Cython code working nicely. However, now I want to know how best to package it. For most people who just want to install the package, I'd like to include the .c file that Cython creates, and arrange for setup.py to compile that to produce the module. Then the user doesn't need Cython installed in order to install the package. But for people who may want to modify the package, I'd also like to provide the Cython

Cython “Not allowed in a constant expression”, boundscheck False doesn't work

不羁的心 提交于 2019-12-29 06:28:31
问题 I am relatively new to Cython and have encountered an error that my research has failed me on (I am using Python3 in spyder and my Sython version is 0.26) I tried this: import cython @cython.boundscheck(False) def boundtest(): cdef int r=4 cdef double l[3] and it works fine. But then I tried this: import cython @cython.boundscheck(False) def boundtest(): cdef int r=4 cdef double l[r] and I receive the error [1/1] Cythonizing test.pyx Error compiling Cython file: ------------------------------

Calling a cython library with multiple pyx files through c++

血红的双手。 提交于 2019-12-29 01:44:10
问题 I have a python project that I want to call from a c++ application. I would like to bundle all python sources together in a single shared library and link the c++ application to that library. Right now my cython setup.py creates one *.so per python source, which is very inconvenient. Here is the setup.py file: from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize sourcefiles = ['project_interface.pyx', 'impl_file1.pyx'] setup( ext

Cython package with __init__.pyx: Possible?

我怕爱的太早我们不能终老 提交于 2019-12-28 12:18:15
问题 Is it possible to create a Python 2.7 package using __init__.pyx (compiled to __init__.so )? If so how? I haven't had any luck getting it to work. Here is what I have tried: setup.py : #!/usr/bin/env python from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext foo = Extension(name='foo.__init__', sources=['foo/__init__.pyx']) bar = Extension(name='foo.bar', sources=['foo/bar.pyx']) setup(name='foo', packages = ['foo'], cmdclass={

Cython package with __init__.pyx: Possible?

我怕爱的太早我们不能终老 提交于 2019-12-28 12:18:09
问题 Is it possible to create a Python 2.7 package using __init__.pyx (compiled to __init__.so )? If so how? I haven't had any luck getting it to work. Here is what I have tried: setup.py : #!/usr/bin/env python from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext foo = Extension(name='foo.__init__', sources=['foo/__init__.pyx']) bar = Extension(name='foo.bar', sources=['foo/bar.pyx']) setup(name='foo', packages = ['foo'], cmdclass={

Why does numpy.zeros takes up little space

你。 提交于 2019-12-28 02:12:07
问题 I am wondering why numpy.zeros takes up such little space? x = numpy.zeros(200000000) This takes up no memory while, x = numpy.repeat(0,200000000) takes up around 1.5GB. Does numpy.zeros create an array of empty pointers? If so, is there a way to set the pointer back to empty in the array after changing it in cython? If I use: x = numpy.zeros(200000000) x[0:200000000] = 0.0 The memory usage goes way up. Is there a way to change a value, and then change it back to the format numpy.zeros

How to profile cython functions line-by-line

折月煮酒 提交于 2019-12-27 20:10:01
问题 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