Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jitclass: support for __call__ etc #1606

Open
oyamad opened this issue Jan 7, 2016 · 17 comments · Fixed by #5877
Open

Jitclass: support for __call__ etc #1606

oyamad opened this issue Jan 7, 2016 · 17 comments · Fixed by #5877

Comments

@oyamad
Copy link

oyamad commented Jan 7, 2016

Despite #1571 (comment), would it be possible for jitclass to support special methods such as

  1. __call__
  2. __getitem__, __setitem__
  3. __repr__, __str__
  4. __iter__

and others?

__call__ would be especially useful since it will allow the instance to look like a jitted function that can be passed to another jitted function as an argument. See also https://groups.google.com/a/continuum.io/forum/#!topic/numba-users/YE12tE2dIwY.

@datnamer
Copy link

Also multiple inheritance would be great. @sklam that probably deserves its own issue?

@moble
Copy link

moble commented Feb 8, 2016

@datnamer Multiple inheritance seems to work, at least from my simple first test. The only wrinkle is that I calling the super __init__ functions is a bit tricky, even for single inheritance (see #1694), but it seems to work. Is there a different problem that simple tests don't turn up?

@moble
Copy link

moble commented Feb 12, 2016

I would also add the operators __add__, __radd__, __mul__, etc.

@datnamer
Copy link

datnamer commented Mar 3, 2016

@moble ok thanks.

I was also thinking of ways for easy code reuse and lightweight abstractions- how about abstract base classes and or user defined protocols/magic methods? (similar to traits).

@j-towns
Copy link

j-towns commented Feb 24, 2017

I want to re-iterate that overloading of math operators like __add__, __mul__ etc is essential for Autograd to be compatible with Numba (which would be awesome).

How difficult would this be to implement? I'm happy to help if I can.

@sklam
Copy link
Member

sklam commented Mar 3, 2017

It gets really tricky to match the exact python semantic due to the __radd__ and reflection.

@AriKatz
Copy link

AriKatz commented Mar 5, 2017

Does that mean JIT class support will stay as is? If not, what are the long term plans?

@sklam
Copy link
Member

sklam commented Mar 6, 2017

I have plans to expand the JIT class support. Few months ago, I was working on various jitclass features but I was slowed down by many tricky details. Some of these details, like the operating overloading, can be implemented but with great cost in code complexity. I think it is partially due to the technical debts in the internals of numba. So, I am taking a pause in pushing new features for jitclasses and trying to clean things up a bit.

@moble
Copy link

moble commented Sep 26, 2017

Is this closed by #1851, as suggested by one of the improvements listed in the release notes for version 0.26.0?

@moble
Copy link

moble commented Sep 26, 2017

I guess not, as my tests all fail. #1865 implies that special cases are needed, and that was closed in favor of (the still-open) #2187.

@seibert seibert added this to the Numba 1.0 milestone Nov 2, 2017
@aldanor
Copy link

aldanor commented May 5, 2018

Wondering if there's any plans on reviving this?

There's a few tricky magic methods, but would be very nice to at least have the 'easy' ones like __str__ / __repr__.

@andreapiso
Copy link

Another nice one to have would be len. Great to see getitem and setitem work tho!

@justinblaber
Copy link

justinblaber commented Jan 31, 2021

__repr__ would be very nice...

@alexpyattaev
Copy link

alexpyattaev commented May 21, 2021

__iadd__ and __imul__ at the very least should be fairly straightforward as they do not need any memory manipulation whatsoever...

@alexpyattaev
Copy link

One other super-annoying thing is copy and deepcopy. Since jitclasses are nearly always leaf nodes in deepcopy, would it not make it possible to define copy and deepcopy methods to make it possible to deepcopy lists with numba objects in them?

@luk-f-a
Copy link
Contributor

luk-f-a commented Jun 22, 2022

does #5877 implement __call__? I can't find it in the documentation (https://github.com/numba/numba/pull/5877/files#diff-6880417d39388a0df2223969338766f4482ef800575fec37101fcb0db6b55725)

@gmarkall
Copy link
Member

Whoops, it does not. I'll reopen this to keep track of that.

@gmarkall gmarkall reopened this Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.