However, I’m having trouble converting an int value into the corresponding enum in a jit func. The below works fine without jitting
from enum import IntEnum
from numba import njit
class Bool(IntEnum):
FALSE = 1
TRUE = 2
# @njit()
def func(val):
return Bool(val)
print(func(1))
but fails with this error when jitted.
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of IntEnum class(Bool) with parameters (int64)
No type info available for IntEnum class(Bool) as a callable.
During: resolving callee type: IntEnum class(Bool)
I’m sure I’m doing something silly, but I didn’t find an example that did this in either the tests or generally poking about on the net.
@esc For me the latest version on master is not working. Did you maybe forget to uncomment the njit decorator when testing?
I have been working on improving Enum support but ran into a bit of a dead end. I will try to make a PR this weekend to show what I got so far, maybe someone can help me to finish things up or tell me it’s hopeless
It should be said that the Enums in CPython are a bit weird if you look into the details of how they are implemented.
IntEnums are even weirder because their members are more like monkey-patched integers. (similar for StrEnums etc.)
One of the issues here might be that numba does not lower all the information about an Enum, only the value field iirc. So that might be part of why it cannot be reconstructed.
I managed to make a PR for what I had been working on. At this point I don’t really think it should get merged given the increase in complexity for little gain. But maybe there is something that can sow inspiration