Numba 与 numpy.random.binomial 的兼容性

问题描述

我试图使用 numba 来加速我的代码的一部分,该部分根据成功概率数组生成伯努利随机变量数组。大致如下:

import numpy as np
from numba import njit

@njit
def Bernoulli(a,b,c):
    prob = np.array from some calculation to a,b and c
    accepted = np.random.binomial(1,prob)
    return accepted

Bernoulli(a,c)

但是,出现这个错误代码

There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'Numpy_negative_binomial.generic': File: numba\core\typing\randomdecl.py: Line 171.
    With argument(s): '(int64,array(float64,1d,C))':
   No match for registered cases:
    * (int64,float64) -> int64

我理解这是因为当前的 numba 实现不支持成功概率数组作为 np.random.binomial 的参数。这样对吗?
如果是这样,此实现是否是解决问题的有效方法

@njit(parallel = True)
def Bernoulli(a,b and c
    accepted = np.zeros(N)
    for i in prange(N):
        accepted[i] = np.random.binomial(1,prob[i])
    return accepted

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)