TypeError:定义函数时所需的整数

时间:2014-02-24 10:45:09

标签: python python-2.7 cython

我已经编写了一个cython文件来为我做一些耗时的操作。但是,如果我尝试调用此函数,我会得到一个TypeError: an integer is required。我正在使用python 2.7计算机上的Win7VisualStudio2008

我的cython代码存储为.pyx文件,如下所示:

def Forward(char sequence1, char sequence2, list Trans, list Emission, 
            list gapX, list gapY, list Alphabet):

    '''
    Declare variables
    '''
    cdef list seq1
    cdef list seq2
    cdef list ForwardTrellis = []
    cdef list singlesymbols1 = []
    cdef list singlesymbols2 = []
    cdef list states = []

    cdef int i,j,k
    cdef double epsilon, delta, lambd, tauM, tauXY, 
    cdef list EP
    cdef list gEX
    cdef list gEY
    cdef list A

    '''
    Do some computations here
    '''
    some_result = 5
    return some_result

此功能按以下方式加载:

import pyximport; pyximport.install()
import SomeFunctions as SFunct

class someclass:
    def __init__(self, Alphabet, Trans, gapEmissionX, gapEmissionY, EmissionMat):
    '''
    Constructor
    '''
    self.Trans = Trans
    self.Alphabet = Alphabet
    self.gapX = gapEmissionX
    self.gapY = gapEmissionY
    self.Emat = EmissionMat


def Forward(self, sequence1, sequence2):

    trel = SFunct.Forward(sequence1, sequence2, self.Trans, self.Emat, self.gapX,
                          self.gapY, self.Alphabet)
    return trel

在下一步中,我尝试调用这些函数。

if __name__ == "__main__"

    mod = someclass(["a","b","c"],[0.3,0.3,0.3,0.1,0.1],[0.3,0.3,0.3],[0.3,0.3,0.3],
                  [[0.1,0.1,0.1],[0.1,0.1,0.1],[0.1,0.1,0.1]])

    print mod.Forward("ab", "ab")

0 个答案:

没有答案