numba nopython mode 不支持numpy.int类型

一则小记,numba库并不支持NumPy的int类型,需要指定整型的位宽,使用int32int64都没有问题。测试代码如下

本机系统Ubuntu 18.04, Python 3.6.8, numba 0.46.0, NumPy 1.16.4

import numba
import numpy as np
import sys

@numba.jit(nopython=True)
def test_zeros(H, W):
    # array = np.zeros((H, W, 3), dtype=np.int) # Will cause jit error.
    array = np.zeros((H, W, 3), dtype=np.int64) # OK.
    array = np.zeros((H, W, 3), dtype=np.int32) # OK.

def main():
    test_zeros(100, 200)
    return 0

if __name__ == "__main__":
    sys.exit(main())

上述代码报出的错误如下

numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function zeros>) with argument(s) of type(s): ((int64, int64, Literal[int](3)), dtype=Function(<class 'int'>))
 * parameterized
In definition 0:
    All templates rejected with literals.
In definition 1:
    All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<built-in function zeros>)
[2] During: typing of call at TestNumba.py (8)


File "TestNumba.py", line 8:
def test_zeros(H, W):
    array = np.zeros((H, W, 3), dtype=np.int) # Will cause jit error.
展开阅读全文
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值