cython

Read in large file and make dictionary

我的梦境 提交于 2020-01-01 09:22:21
问题 I have a large file which I need to read in and make a dictionary from. I would like this to be as fast as possible. However my code in python is too slow. Here is a minimal example that shows the problem. First make some fake data paste <(seq 20000000) <(seq 2 20000001) > largefile.txt Now here is a minimal piece of python code to read it in and make a dictionary. import sys from collections import defaultdict fin = open(sys.argv[1]) dict = defaultdict(list) for line in fin: parts = line

Cython and c++ class constructors

守給你的承諾、 提交于 2020-01-01 06:07:29
问题 Can someone suggest a way to manipulate c++ objects with Cython, when the c++ instance of one class is expected to feed the constructor of another wrapped class as described below? Please look at the note on the pyx file for the class PySession, which takes a python PyConfigParams object as argument and then needs to extract values from it in order to construct a c++ ConfigParams object. the ConfigParams object is then used to feed the constructor of Session. It would be ideal to have a

Cython and c++ class constructors

痴心易碎 提交于 2020-01-01 06:07:08
问题 Can someone suggest a way to manipulate c++ objects with Cython, when the c++ instance of one class is expected to feed the constructor of another wrapped class as described below? Please look at the note on the pyx file for the class PySession, which takes a python PyConfigParams object as argument and then needs to extract values from it in order to construct a c++ ConfigParams object. the ConfigParams object is then used to feed the constructor of Session. It would be ideal to have a

python np.round() with decimal option larger than 2

一世执手 提交于 2020-01-01 05:11:06
问题 Python has default round() function, but I was programming with cython and want to replace pythonic code with numpy function. However, I got the following results when experimenting it in terminal. >>> np.around(1.23456789) 1.0 >>> np.around(1.23456789, decimals=0) 1.0 >>> np.around(1.23456789, decimals=1) 1.2 >>> np.around(1.23456789, decimals=2) 1.23 >>> np.around(1.23456789, decimals=3) 1.2350000000000001 >>> np.around(1.23456789, decimals=4) 1.2345999999999999 Which is kind of strange,

Eclipse pydev warning - “Debugger speedups using cython not found.”

左心房为你撑大大i 提交于 2020-01-01 04:25:07
问题 I get this warning while running a python program (some basic web automation using selenium): warning: Debugger speedups using cython not found. Run '"/usr/bin/python3.5" "/root/.p2/pool/plugins/org.python.pydev_4.5.5.201603221110/pysrc/setup_cython.py" build_ext --inplace' to build. pydev debugger: starting (pid: 3502) How can I address this issue? 回答1: This is as expected. Run "/usr/bin/python3.5" "/root/.p2/pool/plugins/org.python.pydev_4.5.5.201603221110/pysrc/setup_cython.py" build_ext -

What is this import_umath function?

我是研究僧i 提交于 2020-01-01 04:04:09
问题 When compiling a bunch of Cython-generated C files that interface with Numpy, I get the warning: /usr/lib/pymodules/python2.7/numpy/core/include/numpy/__ufunc_api.h:226:1: warning: ‘_import_umath’ defined but not used [-Wunused-function] I can't seem to get rid of that. Figuring this might be similar to np.import_array() , which gets rid of a related warning (and is actually required for using the Numpy C API), I tried np.import_umath() at top level, but the warning persists. How do I get rid

Passing numpy arrays in Cython to a C function that requires dynamically allocated arrays

最后都变了- 提交于 2020-01-01 03:12:08
问题 I have some C code that has the following declaration: int myfunc(int m, int n, const double **a, double **b, double *c); So a is a constant 2D array, b is a 2D array, and c is a 1D array, all dynamically allocated. b and c do not need to be anything specifically before they are passed to myfunc , and should be understood as output information. For the purposes of this question, I'm not allowed to change the declaration of myfunc . Question 1: How do I convert a given numpy array a_np into an

'easy_install -U cython' fails complaining about vcvarsall.bat and -mno-cygwin

假装没事ソ 提交于 2019-12-31 22:36:12
问题 Under Windows, it seems that easy_install with a C dependency isn't very easy. Attempt 1 - vcvarsall.bat errors I am installing cython under Windows7, with MinGw ; I modified Windows7's PATH to include C:\MinGw\bin . At this point, I tried to easy_install -U cython , and got... C:\Users\mike_pennington\Desktop\TestDrive>easy_install -U cython Searching for cython Reading http://pypi.python.org/simple/cython/ Reading http://www.cython.org Reading http://cython.org Best match: Cython 0.15.1

Tutorials on optimizing non-trivial Python applications with C extensions or Cython

微笑、不失礼 提交于 2019-12-31 08:59:47
问题 The Python community has published helpful reference material showing how to profile Python code, and the technical details of Python extensions in C or in Cython. I am still searching for tutorials which show, however, for non-trivial Python programs, the following: How to identify the hotspots which will benefit from optimization by conversion to a C extension Just as importantly, how to identify the hotspots which will not benefit from conversion to a C extension Finally, how to make the

Does effective Cython cProfiling imply writing many sub functions?

与世无争的帅哥 提交于 2019-12-31 06:01:39
问题 I am trying to optimize some code with Cython, but cProfile is not providing enough information. To do a good job at profiling, should I create many sub-routines func2, func3,... , func40 ? Note below that i have a function func1 in mycython.pyx , but it has many for loops and internal manipulations. But cProfile does not tell me stats for those loops . 2009 function calls in 81.254 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000