结构化数组分配失败

时间:2019-03-04 22:21:21

标签: python numba structured-array

在“纯”的Numpy下,可以使用元组完成对结构化数组的数据分配:

from numpy import array

def f(t,x):
    t[0]=x

wedges = array([(3.14, 1), (2.71, 4)], dtype='float32,int32')
wedge=(0.47, 42)
f(wedges, wedge)
print(wedges)

不幸的是,在Numba下,代码无法在nopython模式下编译:

from numpy import array
from numba import jit

@jit(nopython=True)
def f(t,x):
    t[0]=x

wedges = array([(3.14, 1), (2.71, 4)], dtype='float32,int32')
wedge=(0.47, 42)
f(wedges, wedge)
print(wedges)

筹款:

numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot resolve setitem: unaligned array(Record([('f0', '<f4'), ('f1', '<i4')]), 1d, C)[0] = (float64, int64)

相比之下,分配给常规Numpy数组的工作原理是

from numpy import array
from numba import jit

@jit(nopython=True)
def f(t,x):
    t[0]=x

w = array([3.14, 2.71], dtype='float32')
ww= 0.47
f(w, ww)
print(w)

输出:

[0.47 2.71]

Numba版本:0.42.1

0 个答案:

没有答案