How to Solve Numba Lowering error?

后端 未结 2 1871
轻奢々
轻奢々 2021-01-21 06:30

I have a function, which I am trying to speed up using the @jit decorator from Numba module. For me it is essential to speed this up as much as possible, because my main code ca

2条回答
  •  旧时难觅i
    2021-01-21 06:42

    There may be other issues, but one is that referencing an array in a module namespace seems to currently be unsupported (simple repro below). Try importing omega as a name.

    In [14]: %%file Sweep.py
        ...: import numpy as np
        ...: constant_val = 0.5
        ...: constant_arr = np.array([0, 1.5, 2.])
    Overwriting Sweep.py
    
    In [15]: Sweep.constant_val
    Out[15]: 0.5
    
    In [16]: Sweep.constant_arr
    Out[16]: array([ 0. ,  1.5,  2. ])
    
    In [17]: @njit
        ...: def f(value):
        ...:     return value + Sweep.constant_val
        ...: 
    
    In [18]: f(100)
    Out[18]: 100.5
    
    In [19]: @njit
        ...: def f(value):
        ...:     return value + Sweep.constant_arr[0]
    
    In [20]: f(100)
    LoweringError: Failed at nopython (nopython mode backend)
    'NoneType' object has no attribute 'module'
    File "", line 3
    [1] During: lowering "$0.3 = getattr(value=$0.2, attr=constant_arr)" at  (3)
    

提交回复
热议问题