因為weave在python3裡不能呼叫了 那如果我想在python裡面使用C語言還有其他辦法嗎??
以下是我擷取程式的一部分
import os, time
from pylab import *
from scipy import *
from scipy import weave
import scipy
scipy.pkgload('lib') # To use blas functions directly
def AcceptMoveCPP(it, g, a, x0, x1, vn, accepted):
# Optimized using weave
vn[it] *= -1 # perform spin-flip
L = len(vn)
b = 0.0
for s in range(2): # both members of pair need to be updated
code="""
using namespace std;
b = a(s)/(1+a(s)*(1-g(s,it,it))); // prefactor b = a/(1+a(1-g_pp))
for (int l=0; l<L; l++){
x0(l) = g(s,l,it);
x1(l) = g(s,it,l);
}
x0(it) -= 1.;
return_val = b;
"""
b = weave.inline(code, ['it','s','a','g','L','x0','x1','b'],
type_converters=weave.converters.blitz, compiler = 'gcc')
# Here we calculate b*(g-1) x g , where x is tensor product
g[s]=lib.blas.fblas.dger(b,x0,x1,a=g[s],overwrite_a=1)
return accepted+1