I have a config variable, which is a Numba Boolean Literal. I want to type switch based on the value of the variable. In post 2619, one of the comments suggested using overload, which worked. But here is the issue: my program looks like
@numba.njit
def aNumbaFunc(configFlag1):
if configFlag1:
do something_1 # Initialize a variable to int
else:
do something_1 else #Initialize a variable to string
some operations in between
if configFlag1:
do something_2
else:
do something_2 else
some operations in between
And the above goes on for more if and else statements.
The above can’t be compiled in Numba if I used the typical if-else statements.
Using overload, the program will look like
def do_something_1(configFlag1):
pass
@numba.extending.overload(do_something_1)
def ol_do_something_1(configFlag1):
if configFlag1.literal_value:
def do_something(configFlag1):
do_something_1
return something
return do_something
else:
def do_something_else(configFlag1):
do_something_1_else
return something_else
return do_something_else
@numba.njit
def aNumbaFunc(configFlag1):
variable1 = do_something_1(configFlag1)
some operations in between
I have to create one overload function for every if statement of a config variable. There are multiple config variables with various if statements; this could potentially become very large.
This should be a standard issue that Python users might face since Python can have multiple types for the same variable. Do you have any suggestions on what I should do in this case? Is there any feature of Numba that can tackle this that I might not be aware of?