LoginSignup
2
0

More than 5 years have passed since last update.

numbaのjitではtry-catch節がエラーになる

Posted at

この記事は要約です。詳細は以下のリンク先ブログ記事をご覧ください。

numba@jitを使って定義した関数の中ではtry-catch節を用いた例外処理が使えません。
たとえば、次のようなコードを動かすと…

from numba import jit

@jit
def function_name(input_args):
    hoge ...
    try:
        hoge1
    exception ERROR:
        hoge2

    return hoge

こんな感じのエラーが出ます。(最後の4行だけ抜粋)

    (前略)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numba\controlflow.py", line 515, in run
    assert not inst.is_jump, inst
AssertionError: Failed at object (analyzing bytecode)
SETUP_EXCEPT(arg=XXX, lineno=XXX)

※arg=とlineno=の後のXXXには本来なら数字が入ります。

今のところ回避策はないようです。
『try-catchを使いたい場合は@jitを使わない』というのが唯一の対処法っぽい。(回避策ご存知の方はコメント欄までお願いいたします。)

■参考サイト:
https://stackoverflow.com/questions/47064474/avoid-try-catch-in-numba

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0