结构的Cython类型内存视图

时间:2016-08-30 20:18:05

标签: python cython

我有这段代码

import random
from random import randint
from cython cimport boundscheck, wraparound


cdef char * flip(float p):
    cdef:
        char* head = 'h'
        char* tail = 't'
    return head if random.random() < p else tail

cdef struct v_bag:
       float v1
       float v_rand
       float v_min

cdef v_bag[:] flip(float num_flips,float num_coins_flipped,float      num_experiments):

    cdef:
       float[:] head_count_coins
       v_bag[:] results
       int N,M,i,j,l
       v_bag vs

    N=num_experiments.shape[0]; M=num_coins_flipped.shape[0]

    with boundscheck(False), wraparound(False):
        for i in range(N):
            for j in range(M):
                flips = [flip(0.5) for k in xrange(num_flips)]
                count = float(flips.count('h'))/num_flips
                head_count_coins[j]=count

            l = randint(0, 999)
            results[i]= v_bag(v1=head_count_coins[0],
                              v_rand=head_count_coins[l],
                              v_min=float(min(head_count_coins)))
    return results

我一直收到这个错误:'函数签名与之前的声明不匹配'

我似乎无法弄清楚如何让cython用类型化的内存视图来编译它,任何帮助或建议都会非常感激,问题似乎是结构的内存视图。

0 个答案:

没有答案