Компиляция JIT в библиотеке numba

Есть некоторый код, который считает число Пи.

@numba.njit(parallel=True)
def calc(iter_count):
    result = 1
    for i in numba.prange(1, iter_count):
        result += ((-1)**i)/(2*i+1)
    return result

Возможно ли вынести компиляцию, когда программа только запускается, а не во время первого вызова метода calc()?


Ответы (1 шт):

Автор решения: MaxU

Выдержка из документации:

While Numba’s main use case is Just-in-Time compilation, it also provides a facility for Ahead-of-Time compilation (AOT).

Benefits

  • AOT compilation produces a compiled extension module which does not depend on Numba: you can distribute the module on machines which do not have Numba installed (but Numpy is required).
  • There is no compilation overhead at runtime (but see the @jit cache option), nor any overhead of importing Numba.

Limitations

  1. AOT compilation only allows for regular functions, not ufuncs.
  2. You have to specify function signatures explicitly.
  3. Each exported function can have only one signature (but you can export several different signatures under different names).
  4. AOT compilation produces generic code for your CPU’s architectural family (for example “x86-64”), while JIT compilation produces code optimized for your particular CPU model.
→ Ссылка