我已经安装了Theano库来提高计算速度,这样我就可以使用GPU的强大功能.
但是,在计算的内部循环内,基于循环索引和一对数组的对应值计算新索引.
然后,该计算的索引用于访问另一个数组的元素,该元素又用于另一个计算.
这太复杂了,不能指望Theano有任何显着的加速吗?
所以,让我重新解释我的问题,反过来说.以下是GPU代码段的示例.由于简洁起见,省略了一些初始化.我可以将其转换为Python/Theano而不会显着增加计算时间吗?
__global__ void SomeKernel(const cuComplex* __restrict__ data,
float* __restrict__ voxels)
Run Code Online (Sandbox Code Playgroud)
{
unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int idy = blockIdx.y * blockDim.y + threadIdx.y;
unsigned int pos = (idy * NX + idx);
unsigned int ind1 = pos * 3;
float x = voxels[ind1];
float y = voxels[ind1 + 1];
float z = voxels[ind1 + 2];
int m;
for (m = 0; m < M; ++m)
{
unsigned int ind2 = …Run Code Online (Sandbox Code Playgroud) 我可以通过在扩展sys.path以包含zip文件之后从Python解释器调用"import some_module"从zip文件加载Python模块(.py,.pyc,.pyd)并且仅在我运行之后
import zipextimporter
zipextimporter.install()
Run Code Online (Sandbox Code Playgroud)
后者是.pyd模块所必需的.
我还可以从嵌入在C++中的Python加载Python .py和.pyc模块.但是,为了从嵌入式Python中加载.pyd模块,我添加了
PyRun_SimpleString("import zipextimporter");
Run Code Online (Sandbox Code Playgroud)
C++ exe超出此行而没有错误.但是下一个命令
PyRun_SimpleString("zipextimporter.install()");
Run Code Online (Sandbox Code Playgroud)
给我这个错误:

嵌入Python时为什么zipextimporter.install()会崩溃?
我怎么解决这个问题?
它可能与编译C++代码的方式有关吗?我用g ++:
g++ embed-simple.cpp -IE:\Python27\include -LE:\Python27\libs -lpython27 -o embed-simple
我看到一个链接 如何链接msvcr90.dll与mingw gcc?
这能提供解决方案吗?如果是的话,我应该如何调整它,gcc - > g ++,因为我正在运行C++代码,而不是C.
我在WinXP上运行Python 2.7.2.
在干净安装Python 2.7.2后,我没有得到运行时错误,只是这样:
导入错误:没有名为....的模块
嵌入C++脚本的编译方式是否重要?我用过g ++.我也用英特尔编译器编译,但是给出了相同的运行时错误.也许我应该尝试MS Visual C++.
或者使用ctypes导入pyd?
我的IDE是Win XP上的pydev/eclipse.
我喜欢在IDE中编译cython模块的想法,但我只能让它在Linux机器上工作.
右键单击项目 - >属性 - >构建器 - >新建 - >程序
我尝试过最简单的setup.py和helloworld.pyx,如下所示:
http://docs.cython.org/src/userguide/tutorial.html
这是我在Linux上的屏幕

它以通常的方式编译helloworld.pyx,如
python setup.py build_ext --inplace
但是,在WinXP上,使用相同的设置,再次单击后
项目 - >构建项目
我明白了

即"不是有效的Win32应用程序".
任何线索为什么这对WinXP不起作用?
更新:Fabio解决了问题.这有效:

我正在尝试使用 PyFFTW 进行线程卷积,以便同时计算大量的 2D 卷积。(不需要单独的进程,因为 GIL 是为 Numpy 操作而释放的)。现在这是这样做的规范模型: http ://code.activestate.com/recipes/577187-python-thread-pool/
(Py)FFTW 之所以如此快,是因为它重用了计划。必须为每个线程单独设置这些以避免访问冲突错误,如下所示:
class Worker(Thread):
"""Thread executing tasks from a given tasks queue"""
def __init__(self, tasks):
Thread.__init__(self)
self.tasks = tasks
self.daemon = True
# Make separate fftw plans for each thread.
flag_for_fftw='patient'
self.inputa = np.zeros(someshape, dtype='float32')
self.outputa = np.zeros(someshape_semi, dtype='complex64')
# create a forward plan.
self.fft = fftw3.Plan(self.inputa,self.outputa, direction='forward', flags=[flag_for_fftw],nthreads=1)
# Initialize the arrays for the inverse fft.
self.inputb = np.zeros(someshape_semi, dtype='complex64')
self.outputb = np.zeros(someshape, dtype='float32')
# Create the backward …Run Code Online (Sandbox Code Playgroud)