-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Generic jitclass #3
base: main
Are you sure you want to change the base?
[WIP] Generic jitclass #3
Conversation
hi @AlexanderKalistratov , as I said in the call, this is a great idea, I'm very happy that someone is doing this. Thanks a lot! I've done some work with jitclass syntax before and I have a (private and ugly) jitclass implementation based on named tuples. I hope I can provide some useful feedback based on my experience. I will do it in stages, so I'll write what I see now and I will add more comments later. The first thing that comes to mind is that I wouldn't make automatic translations of python types into numba types. I think this will lead to user confusion. I also think this will lead to mypy errors. For example: @numba.experimental.jitclass({'capacity': ListType(float64)})
class Foo(object):
def __init__(self):
self.bar = TList.empty_list(float64)
cap: List = Foo().bar This does not fail today, because TypedList has not been annotated, so mypy reads it as @numba.experimental.jitclass
class Foo(object):
bar: List[float]
def __init__(self):
self.bar = TList.empty_list(float64)
cap: List = Foo().bar |
Since this new jitclass will probably have to co-exist with the existing jitclass for a while, I recommend that the name is changed to something else (jitclass2? newjitclass?) for now. Once it's deemed ready to replace the jitclass, then the name can be switched. |
I tried using the same example in numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x7fe797e0be20>.
Failed in nopython mode pipeline (step: nopython mode backend)
Can't pickle <class 'numba_extras.jitclass.main.Test'>: attribute lookup Test on numba_extras.jitclass.main failed
During: resolving callee type: type(CPUDispatcher(<function ctor at 0x7fe797e5f940>))
During: typing of call at /home/.../mypyprojects/numba-extras/numba_extras/jitclass/tests.py (62) |
On the topic of My understanding of class Foo():
pass
a: Annotated[float, Foo] = Foo() # error: Incompatible types in assignment (expression has type "Foo", variable has type "float")
reveal_type(a) # note: Revealed type is 'builtins.float'
a: Annotated[Foo, float] = Foo() # no error
reveal_type(a) # note: Revealed type is 'scratch_1.Foo'
b: float = a # error: Incompatible types in assignment (expression has type "Foo", variable has type "float")
a: Annotated[Foo, "types.float64[:]"] = Foo()
reveal_type(a) # note: Revealed type is 'scratch_1.Foo' |
@luk-f-a Oh, I see. It seems I've misunderstand you on dev meeting. Yes, your proposal looks very interesting |
@luk-f-a but it is not generic. Need to see if we can overcome it somehow |
I see your point. There's a class |
btw, there's a new version of mypy with a useful improvement: python/mypy#9625 |
This is WIP PR for generic jitclasses.
At the moment everything is in a single file, but is going to be split and tests to be added.