cython

How to grant read-only (non-copy) access to an object in another process in Cython?

馋奶兔 提交于 2019-12-23 04:44:32
问题 How to grant read-only (non-copy) access to an object in one process to another process? For example, in the diagram below, how to grant Process 2 and Process 3 access to the class Tasks which is in Process 1 ? Process 1 is the only process which will write to the class Tasks and it is not important to maintain any state about which tasks have been processed etc. Process 2 Process 1 Process 3 +-------------------+ +-------------------+ +-------------------+ | | | | | | | Perform job A for | <

Same memory address for different strings in cython

六月ゝ 毕业季﹏ 提交于 2019-12-23 03:16:11
问题 I wrote a tree object in cython that has many nodes, each containing a single unicode character. I wanted to test whether the character gets interned if I use Py_UNICODE or str as the variable type. I'm trying to test this by creating multiple instances of the node class and getting the memory address of the character for each, but somehow I end up with the same memory address, even if the different instances contain different characters. Here is my code: from libc.stdint cimport uintptr_t

Error building cython with python3 error: 'PyString_AsString' was not declared in this scope

筅森魡賤 提交于 2019-12-23 02:55:17
问题 I am having trouble compiling a c extension using cython in python 3. It compiles and works fine with python 2.7, but in python 3.4.3 I get the following error when building with 3.4 (anaconda distribution): python setup.py build_ext --inplace running build_ext building 'module' extension gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Iincludes -I/home/user/anaconda/include/python3.4m -c module.cpp -o build/temp.linux-x86_64-3.4/module.o cc1plus: warning: command line

Why is pandas.grouby.mean so much faster than paralleled implementation

亡梦爱人 提交于 2019-12-22 18:45:13
问题 I was using the pandas grouby mean function like the following on a very large dataset: import pandas as pd df=pd.read_csv("large_dataset.csv") df.groupby(['variable']).mean() It looks like the function is not using multi-processing, and therefore, I implemented a paralleled version: import pandas as pd from multiprocessing import Pool, cpu_count def meanFunc(tmp_name, df_input): df_res=df_input.mean().to_frame().transpose() return df_res def applyParallel(dfGrouped, func): num_process=int

How to link custom C (which itself needs special linking options to compile) with Cython?

我的梦境 提交于 2019-12-22 17:58:37
问题 so I'm trying to create a Cython module which uses a .c file that I've written. That .c file needs a special linking option (to compile it, I need gcc -o mycode mycode.c -lfftw3f ). I could potentially just rewrite my .c file in Cython, but I want to know how to do this. I am using fftw3, and when compiling, you need to use the -lfftw3f option IN ADDITION to #include <fftw3.h> in the .c file if you want to use the float version, which I do. My setup.py looks like the following: from distutils

Extending Numpy with C function

依然范特西╮ 提交于 2019-12-22 17:54:51
问题 I am trying to speed up my Numpy code and decided that I wanted to implement one particular function where my code spent most of the time in C. I'm actually a rookie in C, but I managed to write the function which normalizes every row in a matrix to sum to 1. I can compile it and I tested it with some data (in C) and it does what I want. At that point I was very proud of myself. Now I'm trying to call my glorious function from Python where it should accept a 2d-Numpy array. The various things

Extending Numpy with C function

别说谁变了你拦得住时间么 提交于 2019-12-22 17:53:31
问题 I am trying to speed up my Numpy code and decided that I wanted to implement one particular function where my code spent most of the time in C. I'm actually a rookie in C, but I managed to write the function which normalizes every row in a matrix to sum to 1. I can compile it and I tested it with some data (in C) and it does what I want. At that point I was very proud of myself. Now I'm trying to call my glorious function from Python where it should accept a 2d-Numpy array. The various things

Passing numpy integer array to c code

纵饮孤独 提交于 2019-12-22 13:57:33
问题 I'm trying to write Cython code to dump a dense feature matrix, target vector pair to libsvm format faster than sklearn's built in code. I get a compilation error complaining about a type issue with passing the target vector (a numpy array of ints) to the relevant c function. Here's the code: import numpy as np cimport numpy as np cimport cython cdef extern from "cdump.h": int filedump( double features[], int numexemplars, int numfeats, int target[], char* outfname) @cython.boundscheck(False)

How to interrupt native extension code without killing the interpreter?

天大地大妈咪最大 提交于 2019-12-22 12:57:27
问题 I am working on a project which combines high-performance algorithms written in C++ with a Python interface. C++ classes and functions are wrapped and exposed to Python via the Cython compiler. Suppose I call a long running native function from the Python interpreter (my preferred one is IPython). Is it somehow possible to interrupt or abort the execution of that code without killing the interpreter? 回答1: Here is a possible implementation using multiprocessing as suggested by Ricardo C.,

High performance variable blurring in very big images using Python

我与影子孤独终老i 提交于 2019-12-22 10:33:03
问题 I have a large collection of large images (ex. 15000x15000 pixels) that I would like to blur. I need to blur the images using a distance function, so the further away I move from some areas in the image the more heavier the blurring should be. I have a distance map describing how far a given pixel is from the areas. Due to the large amount of images I have to consider performance. I have looked at NumPY/SciPY, they have some great functions but they seem to use a fixed kernel size and I need