iT邦幫忙

0

weave in python

  • 分享至 

  • xImage

因為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
看更多先前的討論...收起先前的討論...
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 檢舉
https://medium.com/pyladies-taiwan/%E5%A6%82py%E4%BC%BCc-python-%E8%88%87-c-%E7%9A%84%E5%85%B1%E7%94%9F%E6%B3%95%E5%89%87-568add0ba5b8
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 請問該怎麼改
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答