numbaのjitを用いて行列の計算を早くしたい。
pythonで関数を定義してjitを使って計算速度を早くしようとしたら次のようなエラーがでました。
このエラーはどうやったら取り除けるのでしょうか?
発生している問題・エラーメッセージ
sum.py:13: NumbaWarning: Compilation is falling back to object mode WITH looplifting enabled because Function "LOOP" failed type inference due to: Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (readonly array(float64, 2d, C), UniTuple(int64 x 2), float64) * parameterized In definition 0: All templates rejected with literals. In definition 1: All templates rejected without literals. In definition 2: All templates rejected with literals. In definition 3: All templates rejected without literals. In definition 4: All templates rejected with literals. In definition 5: All templates rejected without literals. In definition 6: All templates rejected with literals. In definition 7: All templates rejected without literals. In definition 8: TypeError: Cannot modify value of type readonly array(float64, 2d, C) raised from /usr/local/lib/python3.7/site-packages/numba/typing/arraydecl.py:179 In definition 9: TypeError: Cannot modify value of type readonly array(float64, 2d, C) raised from /usr/local/lib/python3.7/site-packages/numba/typing/arraydecl.py:179 This error is usually caused by passing an argument of a type that is unsupported by the named function. [1] During: typing of setitem at sum.py (19) File "sum.py", line 19: def LOOP(): <source elided> for l in range(D1): o[i,j] += i+j+k+l ^ @jit sum.py:13: NumbaWarning: Compilation is falling back to object mode WITHOUT looplifting enabled because Function "LOOP" failed type inference due to: cannot determine Numba type of <class 'numba.dispatcher.LiftedLoop'> File "sum.py", line 15: def LOOP(): for i in range(D1): ^ @jit /usr/local/lib/python3.7/site-packages/numba/object_mode_passes.py:178: NumbaWarning: Function "LOOP" was compiled in object mode without forceobj=True, but has lifted loops. File "sum.py", line 15: def LOOP(): for i in range(D1): ^ state.func_ir.loc)) /usr/local/lib/python3.7/site-packages/numba/object_mode_passes.py:188: NumbaDeprecationWarning: Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour. For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit File "sum.py", line 15: def LOOP(): for i in range(D1): ^ state.func_ir.loc)) sum.py:13: NumbaWarning: Compilation is falling back to object mode WITHOUT looplifting enabled because Function "LOOP" failed type inference due to: Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (readonly array(float64, 2d, C), UniTuple(int64 x 2), float64) * parameterized In definition 0: All templates rejected with literals. In definition 1: All templates rejected without literals. In definition 2: All templates rejected with literals. In definition 3: All templates rejected without literals. In definition 4: All templates rejected with literals. In definition 5: All templates rejected without literals. In definition 6: All templates rejected with literals. In definition 7: All templates rejected without literals. In definition 8: TypeError: Cannot modify value of type readonly array(float64, 2d, C) raised from /usr/local/lib/python3.7/site-packages/numba/typing/arraydecl.py:179 In definition 9: TypeError: Cannot modify value of type readonly array(float64, 2d, C) raised from /usr/local/lib/python3.7/site-packages/numba/typing/arraydecl.py:179 This error is usually caused by passing an argument of a type that is unsupported by the named function. [1] During: typing of setitem at sum.py (19) File "sum.py", line 19: def LOOP(): <source elided> for l in range(D1): o[i,j] += i+j+k+l ^ @jit /usr/local/lib/python3.7/site-packages/numba/object_mode_passes.py:178: NumbaWarning: Function "LOOP" was compiled in object mode without forceobj=True. File "sum.py", line 15: def LOOP(): for i in range(D1): ^ state.func_ir.loc)) /usr/local/lib/python3.7/site-packages/numba/object_mode_passes.py:188: NumbaDeprecationWarning: Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour. For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit File "sum.py", line 15: def LOOP(): for i in range(D1): ^ state.func_ir.loc))
該当のソースコード
python
1#coding:utf-8 2from numba import jit 3import math 4import numpy as np 5import matplotlib.pyplot as plt 6import datetime 7import time 8now = datetime.datetime.now() 9start = time.time() 10 11 12D1 = 50 13@jit 14def LOOP(): 15 for i in range(D1): 16 for j in range(D1): 17 for k in range(D1): 18 for l in range(D1): 19 o[i,j] += i+j+k+l 20 return o 21 22o= np.zeros((D1,D1)) 23A = list() 24for p in range(3): 25 if p<2: 26 B = list(o) 27 A.append(np.trace(LOOP())) 28 o= np.zeros((D1,D1)) 29 else: 30 B = list(o) 31 A.append(np.trace(LOOP())) 32 o= np.zeros((D1,D1)) 33 34print(A) 35 36elapsed_time = time.time() - start 37print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/23 11:24