Numba错误:“降低错误:在nopython失败(nopython模式后端)”

时间:2018-04-13 20:02:13

标签: python numpy numba

我正在尝试使用numba类装饰器优化Python类。我阅读了numba @jitclass guide的在线说明。我需要帮助弄清楚我做错了什么。

该类初始化一个在numpy数组中实例化的NxN Rubik多维数据集。台阶方法将底部立方体面顺时针旋转90度。这个类在没有装饰器的情况下运行良好,但是失败了。感谢。

from numba import jitclass
from numba import int32, int16, float32
import numpy as np

spec = [
    ('value', int16[:, :, ::1]),
    ('cube_dim', int16),
    ('c', int16[:, :, ::1]),
    ('slice1d', int16[::1]),
    ('slice2d', int16[:, ::1]),
    ('slice3d', int16[:, :, ::1])
]


@jitclass(spec)
class ncube:
    def __init__(self, cube_dim):
        self.cube_dim = cube_dim
        c = np.zeros(self.cube_dim * self.cube_dim, dtype=np.int16).reshape(self.cube_dim, self.cube_dim)
        c = np.concatenate((c, c + 1, c + 2, c + 3, c + 4, c + 5), axis=0).reshape(6, self.cube_dim, self.cube_dim)
        self.value = c

    def step(self, move):
        if move == 'D':
            # rotate F,B,L,R
            slice1d = self.value[[0, 1, 4, 5], self.cube_dim - 1, :].reshape(4 * self.cube_dim)
            slice2d = np.roll(slice1d, self.cube_dim).reshape(4, self.cube_dim)
            self.value[[0, 1, 4, 5], self.cube_dim - 1, :] = slice2d
            # rot D 90 degrees
            slice2d = self.value[3, :, :]
            np.rot90(slice2d, 1)
            self.value[3, :, :] = slice2d

    def __repr__(self):
        return str(self.value)


c1 = ncube(3)
c1.step('D')
print(c1)

错误结束回溯:

numba.errors.LoweringError: Failed at nopython (nopython mode backend)

File "test1.py", line 21
[1] During: lowering "(self).value = c.1" at /Users/ericadar/test1.py (21)
[2] During: resolving callee type: jitclass.ncube#7fc6c59146b8<value:array(int16, 3d, C),cube_dim:int16,c:array(int16, 3d, C),slice1d:array(int16, 1d, C),slice2d:array(int16, 2d, C),slice3d:array(int16, 3d, C)>
[3] During: typing of call at <string> (3)
--%<-----------------------------------------------------------------

File "<string>", line 3
>>> 

0 个答案:

没有答案