Python weave.inline()和#x27;s支持代码参数?还有其他选择吗?

Python weave.inline()和#x27;s支持代码参数?还有其他选择吗?,python,arrays,numpy,scipy,inline,Python,Arrays,Numpy,Scipy,Inline,我想使用support\u code来定义与nd numpy数组交互的函数。在code参数中,FOO3(i,j,k)符号有效,但仅在support\u code中有效。类似于: import scipy import scipy.weave code = '''return_val = f(1);''' support_code = '''int f(int i) { return FOO3(i, i, i); }'''' foo = scipy.arange(3**3).reshape

我想使用
support\u code
来定义与nd numpy数组交互的函数。在
code
参数中,
FOO3(i,j,k)
符号有效,但仅在
support\u code
中有效。类似于:

import scipy
import scipy.weave
code = '''return_val = f(1);'''
support_code = '''int f(int i) {
    return FOO3(i, i, i);
}''''
foo = scipy.arange(3**3).reshape(3,3,3)
print(scipy.weave.inline(code, ['foo'], support_code=support_code))
import scipy
import scipy.weave

def foofunc(i):
    foo = scipy.arange(3**3).reshape(3,3,3)
    code = '''#do something lengthy with foo and maybe i'''
    scipy.weave.inline(code, ['foo', 'i']))
    return foo[i,i,i]

支持代码的概念主要是做一些包含。在您的情况下,我想函数应该是这样的:

import scipy
import scipy.weave
code = '''return_val = f(1);'''
support_code = '''int f(int i) {
    return FOO3(i, i, i);
}''''
foo = scipy.arange(3**3).reshape(3,3,3)
print(scipy.weave.inline(code, ['foo'], support_code=support_code))
import scipy
import scipy.weave

def foofunc(i):
    foo = scipy.arange(3**3).reshape(3,3,3)
    code = '''#do something lengthy with foo and maybe i'''
    scipy.weave.inline(code, ['foo', 'i']))
    return foo[i,i,i]
您根本不需要支持代码,因为您正在尝试做什么。您也没有任何速度提升,当您尝试用C语言而不是python语言执行函数返回时,与函数调用的成本相比,数组访问也是可以忽略的。为了更好地了解weave何时以及如何帮助您,为了加快代码的速度,请看一看