2013-01-06 40 views
6

我想將一些python代碼移植到cython中,並遇到一些小問題。numpy數組與cython

下面您會看到一段代碼的代碼片段(簡單示例)。

cimport numpy as np 
cimport cython 
@cython.boundscheck(False) # turn of bounds-checking for entire function 
@cython.wraparound(False) 
@cython.nonecheck(False) 
def Interpolation(cells, int nmbcellsx): 
    cdef np.ndarray[float,ndim=1] celle 
    cdef int cellnonzero 
    cdef int i,l 
    for i in range(nmbcellsx): 
      celle = cells[i].e 
      cellnonzero = cells[i].nonzero 
      for l in range(cellnonzero): 
       celle[l] = celle[l] * celle[l] 

我不明白爲什麼最內層的環沒有完全轉化爲C代碼(即最後一行,策勒[1] = ...),看到cython -a feedback輸出:

enter image description here

我在這裏錯過了什麼?

非常感謝。

+1

該圖像有點難以閱讀 - 複製和粘貼相關位會更容易... –

+0

你有什麼c編譯器? 'celle [l] * = celle [l]'是一樣的嗎? – denis

回答

1

我終於意識到,在函數的最後一個簡單的「返回0」解決了這個問題。但是,這種行爲對我來說似乎很陌生。這實際上是一個錯誤?