cython

Python packaging: Boost library as dependency

孤者浪人 提交于 2021-02-20 19:12:53
问题 Assume that someone wants to package a Python (Cython) library that depends on the C++ boost library. What is the best way to configure the setup.py so that the user is properly informed that it is required to install the boost library (i.e., apt-get install libboost-dev in Ubuntu, etc in other OSes)? Or is it a better practice to include the boost library in the python package distribution? 回答1: The question is better asked as What is the best way to distribute a Python extension including

Python 3D interpolation speedup

你离开我真会死。 提交于 2021-02-18 15:21:55
问题 I have following code used to interpolate 3D volume data. Y, X, Z = np.shape(volume) xs = np.arange(0, X) ys = np.arange(0, Y) zs = np.arange(0, Z) points = list(zip(np.ravel(result[:, :, :, 1]), np.ravel(result[:, :, :, 0]), np.ravel(result[:, :, :, 2]))) interp = interpolate.RegularGridInterpolator((ys, xs, zs), volume, bounds_error=False, fill_value=0, method='linear') new_volume = interp(points) new_volume = np.reshape(new_volume, (Y, X, Z)) This code takes about 37 seconds to execute on

Python 3D interpolation speedup

▼魔方 西西 提交于 2021-02-18 15:21:48
问题 I have following code used to interpolate 3D volume data. Y, X, Z = np.shape(volume) xs = np.arange(0, X) ys = np.arange(0, Y) zs = np.arange(0, Z) points = list(zip(np.ravel(result[:, :, :, 1]), np.ravel(result[:, :, :, 0]), np.ravel(result[:, :, :, 2]))) interp = interpolate.RegularGridInterpolator((ys, xs, zs), volume, bounds_error=False, fill_value=0, method='linear') new_volume = interp(points) new_volume = np.reshape(new_volume, (Y, X, Z)) This code takes about 37 seconds to execute on

convert python object to cython pointer

一个人想着一个人 提交于 2021-02-18 10:59:28
问题 I'm trying to expose c++ classes to python using cython. I wrote their definitions in *.pxd file and implemented a wrappers in *.pyx files. But I got stuck trying to pass to a function pointer to the extension type. Here is simplified example. foo.pyx from c_foo cimport cFoo cdef class Foo: cdef cFoo* _impl c_foo_holder.pxd cdef extern from "FooHolder.h": cdef cppclass cFooHolder: cFooHolder(cFoo* foo) foo_holder.pyx from c_foo_holder cimport cFooHolder from c_foo cimport cFoo cdef class

Efficient pairwise DTW calculation using numpy or cython

好久不见. 提交于 2021-02-18 10:11:33
问题 I am trying to calculate the pairwise distances between multiple time-series contained in a numpy array. Please see the code below print(type(sales)) print(sales.shape) <class 'numpy.ndarray'> (687, 157) So, sales contains 687 time series of length 157. Using pdist to calculate the DTW distances between the time series. import fastdtw import scipy.spatial.distance as sd def my_fastdtw(sales1, sales2): return fastdtw.fastdtw(sales1,sales2)[0] distance_matrix = sd.pdist(sales, my_fastdtw) --

Efficient pairwise DTW calculation using numpy or cython

断了今生、忘了曾经 提交于 2021-02-18 10:10:54
问题 I am trying to calculate the pairwise distances between multiple time-series contained in a numpy array. Please see the code below print(type(sales)) print(sales.shape) <class 'numpy.ndarray'> (687, 157) So, sales contains 687 time series of length 157. Using pdist to calculate the DTW distances between the time series. import fastdtw import scipy.spatial.distance as sd def my_fastdtw(sales1, sales2): return fastdtw.fastdtw(sales1,sales2)[0] distance_matrix = sd.pdist(sales, my_fastdtw) --

make remove .cc after building .so without control

本小妞迷上赌 提交于 2021-02-17 06:51:06
问题 Recently I encountered an extremly strange behavior of Makefile : In current dir, I have hello.pyx : #cython: language_level=3 print("Hello, world!") and in .. I have Makefile : includes=$(shell python3 -c "import sysconfig; print(sysconfig.get_path('include'))") CFLAGS=-shared -pthread -fPIC -fwrapv -Oz -flto -Wall -fno-strict-aliasing -I$(includes) LDFLAGS=-Wl,-plugin-opt=O2 %.cc: %.pyx cython --cplus $< -o $@ %.so: %.cc clang++ ${CFLAGS} ${LDFLAGS} $< -o $@ clean: rm -f *.cc *.so .PHONY:

How to share a C-singleton between multiple C-extensions

冷暖自知 提交于 2021-02-15 05:16:44
问题 I have a static library (or a bunch of c/cpp-files for that matter) which contains a singleton and is used by/linked to two different C-extensions. However, the singleton from the C-library doesn't behave like a singleton anymore: import getter import setter # set singleton: setter.set(21) # get singleton: print("singleton: ", getter.get()) #prints the old value:42 Here is a minimal example illustrating this problem using Cython for the sake of simplicity (all files are in the same folder): C

How to share a C-singleton between multiple C-extensions

我与影子孤独终老i 提交于 2021-02-15 05:16:24
问题 I have a static library (or a bunch of c/cpp-files for that matter) which contains a singleton and is used by/linked to two different C-extensions. However, the singleton from the C-library doesn't behave like a singleton anymore: import getter import setter # set singleton: setter.set(21) # get singleton: print("singleton: ", getter.get()) #prints the old value:42 Here is a minimal example illustrating this problem using Cython for the sake of simplicity (all files are in the same folder): C

How to share a C-singleton between multiple C-extensions

十年热恋 提交于 2021-02-15 05:14:48
问题 I have a static library (or a bunch of c/cpp-files for that matter) which contains a singleton and is used by/linked to two different C-extensions. However, the singleton from the C-library doesn't behave like a singleton anymore: import getter import setter # set singleton: setter.set(21) # get singleton: print("singleton: ", getter.get()) #prints the old value:42 Here is a minimal example illustrating this problem using Cython for the sake of simplicity (all files are in the same folder): C