Reputation: 63
I have a Python project with the following document structure:
/scripts
main.py
/classes
myclass.py
...
The class defined in myclass.py
has a method which I aim to accelerate. I have achieved this by jitting parts of them into functions so that myclass.py
looks like this:
def myclass:
def method1:
...
def method2:
...
out1 = function1(inputs)
out2 = function2(out1,other_inputs)
...
@njit()
def function1(inputs)
...
@njit()
def function2(inputs)
...
When I call the jitted functions twice without leaving myclass.py, they run faster during the second call. This is an expected result because of the compilation during the first call. But when I call the class method from outside myclass.py a second time (in my case from main.py), the jitted functions are compiled once again, and I cannot benefit from the acceleration at all. For this use case ahead of time (AoT) compilation looks like a solution, but the necessity to explicitly define the function signatures currently blocks me from using it. Therefore I wonder if there is a way to keep the accelerated versions of my function across different files without using AoT compilation. Thanks for the answers.
Upvotes: 0
Views: 599