0

## weave in python

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
``````

froce iT邦大師 1 級 ‧ 2018-11-06 08:27:16 檢舉
Cython？
wendyduke iT邦新手 5 級 ‧ 2018-11-06 10:25:03 檢舉
Cpython 應該不是可以在python裡面運作的模組八~~??如果認知有錯請糾正~
froce iT邦大師 1 級 ‧ 2018-11-06 11:37:22 檢舉
wendyduke iT邦新手 5 級 ‧ 2018-11-07 17:03:28 檢舉
type_converters=weave.converters.blitz　在　cython　裡面對應的功能是什麼？？　我是這功能的新手不好意思
wendyduke iT邦新手 5 級 ‧ 2018-11-07 17:13:49 檢舉
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 = cy.inline(code, ['it','s','a','g','L','x0','x1','b'])

# 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
''''
cython assign as cy 請問該怎麼改