【问题标题】:Using numpy functions which numba doesn't support使用 numba 不支持的 numpy 函数
【发布时间】:2019-06-22 14:00:04
【问题描述】:

我目前正在使用一个函数来使用numpy.histogram()numpy.histogram2d() 创建直方图。为了加快使用numba 的过程,我尝试使用@jit 装饰器在nonpython 模式下进行解释,但是numba 报告了一个错误,说numpy.histogram() 是一个不受支持的功能。我的函数看起来像,

def make_histograms(X, neurons, bins = 5):
    xy = np.histogram2d(X, neurons, bins)[0]
    x = np.histogram(X, bins)[0]
    y = np.histogram(neurons, bins)[0]

在我的情况下,还有其他解决方法可以使用 numba 吗?任何帮助将非常感激。在此先感谢:)

【问题讨论】:

  • 如果你真的想这样做,看看sourcehistogram。您几乎可以肯定地使用它使其与numba 兼容,尽管它比您现在尝试的要冗长得多

标签: python performance numpy numba


【解决方案1】:

Numba 文档本身提供了一个将Numba 用于直方图的示例。这看起来很方便;然而,实现 2d 直方图看起来相当深奥且涉及。幸运的是,我发现了这个很棒的 repo,它实现了 fast_histogram 计算,性能提升等于或有时超过 Numba。另外,这个page 比较了他们的表现。 我自己把这个答案留在这里,希望它对某人有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    相关资源
    最近更新 更多