I have a couple of modules in my project that each contain a few numba functions. I know that on first import the functions get compiled.
What I noticed only now is that even if I only import a single function out of a module, seemingly all functions get compiled as the import takes the same amount of time.
I'd like to achieve a more fine-grained approach to this, since for some applications you really only need a single function, hence compiling all is a waste of time.
For that I've split up the functions into separate modules like this:
Project/
|--src/
| |-- __init__.py
| |-- fun1.py
| |-- fun2.py
| |-- fun3.py
| |-- fun4.py
| |-- ...
with __init__.py including
from .fun1 import fun1
from .fun2 import fun2
...
so they can be imported like from src import fun1.
This seems to work alright, but there's a bit of repetition at the import level, for instance every function needs from numba import jit, a few of them need from numpy import zeros and so on.
So my question is if that's an OK way, or if there's a better approach to packaging many numba functions.
Edit:
Putting all the import statements into __init__.py apparently means also all functions get compiled once one is imported - so there's no gain at all.
I can still import the functions like
from src.fun1 import fun1
which seems to work. But the syntax is a bit clunky.