Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Numba错误:“;LoweringError:在nopython(nopython模式后端)失败;_Python_Numpy_Numba - Fatal编程技术网

Numba错误:“;LoweringError:在nopython(nopython模式后端)失败;

Numba错误:“;LoweringError:在nopython(nopython模式后端)失败;,python,numpy,numba,Python,Numpy,Numba,我正在尝试使用numba类装饰器优化Python类。我阅读了numba@jitclass的在线说明。我需要帮助找出我做错了什么 该类初始化在numpy数组中实例化的NxN Rubik立方体。阶梯法将底部立方体面顺时针扭曲90度。这个类在没有decorator的情况下运行良好,但是没有decorator就失败了。谢谢 from numba import jitclass from numba import int32, int16, float32 import numpy as np spec

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

该类初始化在numpy数组中实例化的NxN Rubik立方体。阶梯法将底部立方体面顺时针扭曲90度。这个类在没有decorator的情况下运行良好,但是没有decorator就失败了。谢谢

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
>>> 
numba.errors.LoweringError:在nopython(nopython模式后端)失败
文件“test1.py”,第21行
[1] 期间:在/Users/ericadar/test1.py(21)处降低“(self).value=c.1”
[2] 期间:解析被调用方类型:jitclass.ncube#7fc6c59146b8
[3] 期间:在(3)处键入呼叫
--%>> 

我认为这与step函数中的索引有关。来自Numba docs:“数组支持正常迭代。支持完整的基本索引和切片。还支持高级索引的子集:只允许一个高级索引,它必须是一维数组(也可以与任意数量的基本索引组合)。”注释掉step方法没有帮助-我得到了相同的错误。跟踪似乎指向
self.value=c
作为问题行,但此作业没有索引或子集设置。我只是简单地将c复制到self.value中,并且在规范中以相同的方式定义了这两个值。我通过删除您的np.concatenate()来编译它。。。。谢谢,我试试看。奇怪的是,它看起来像
np.concatenate
由numba支持: