numbaを使い以下のclassを高速化したいです。
import numpy as np class test(object): def __init__(self): self.turn = 0 self.array = np.zeros((10,10), dtype=np.int32) self.flag = True self.point = []
ただし、pointは((0,0),[(0,0),(0,1),...,(3,4)])が要素になった配列として使います。(値は適当です)
これを、numbaを使って型を指定すると、
import numpy as np from numba import jitclass, float32, int32, boolean, typeof from numba.types import Tuple, List spec = [('turn', int32), ('array', int32[:,:]), ('flag', boolean), ('point', typeof([((0,0),[(0,0)])])) ] @jitclass(spec) class test(object): def __init__(self): self.turn = 0 self.array = np.zeros((10,10), dtype=np.int32) self.flag = True self.point = []
であっていると思うのですがうまく行きません。
このようなエラー文(一部をコピペ)が出力されます。
[1] During: lowering "$0.17 = build_list(items=[Var($0.16, test_numba3.py (12))])" at test_numba3.py (12) Failed at nopython (nopython mode backend) list(((int64 x 2), list((int64 x 2)))): unsupported nested memory-managed object File "test_numba3.py", line 12 [1] During: lowering "$0.17 = build_list(items=[Var($0.16, test_numba3.py (12))])" at test_numba3.py (12) [2] During: resolving callee type: jitclass.test#1e0c210<turn:int32,array:array(int32, 2d, A),flag:bool,point:reflected list(((int64 x 2), reflected list((int64 x 2))))> [3] During: typing of call at <string> (3)
また、この時
self.point = [((0,0),[(0,0)])]
と書いても、同じエラーが返ります。
もし解決法をご存知の方がございましたら、お教えいただけると大変うれしいです。
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。