numba debug记录

项目场景:

使用numba加速自定义函数

问题描述:

@numba.jit(nopython=True)
def meshgrid(vessel):
	'''	...	'''
	faces = np.zeros([len(face), 3], dtype=int)
	''' ... '''

遇到faces = np.zeros([len(face), 3], dtype=int)这句时报了两个错,错误如下

No implementation of function Function(<built-in function zeros>) found for signature:
 
 >>> zeros(list(int64)<iv=None>, dtype=Function(<class 'int'>))
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload of function 'zeros': File: numba\core\typing\npydecl.py: Line 507.
    With argument(s): '(list(int64)<iv=None>, dtype=Function(<class 'int'>))':
   No match.

During: resolving callee type: Function(<built-in function zeros>)
During: typing of call at <ipython-input-6-f8e133d7960d> (3)

原因分析:

参考NumPy zeros in Numba function is not working when multi-dimensional shape is a list可知:

  • 尽管平时在使用numpy时大家都习惯用类似[shape1,shape2]这样的方法来写,但是正规的numpy写法应该使用tuple而不是list
  • 在装饰器中使用了nopython=True,那么dtype就不能是python内置的数据类型,要改为numba中的数据类型。

解决方案:

faces = np.zeros((len(face),3),dtype=numba.int64)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值