Use `guvectorize` on `jitclass` method?

Is it possible to @guvectorize decorate a method of a @jitclass-decorated class?

A simple example

@jitclass
class Foo:
    
    @guvectorize([f8(f8[:], f8[:])], '(n), (n) -> (n)')
    def bar(self, a, b):
        result = a+b
        return result

raises

TypeError: Failed in object mode pipeline (step: fix up args)
Signature mismatch: 2 argument types given, but function takes 3 arguments

If this is possible, how should (can) I make the call signatures and layouts of my guvectorize decorator accept the self argument?

If not yet possible, I think this would be a really valuable feature.

I personally wouldn’t do it, but instead wrap any such function within a thin method (where needed). I doubt it’s possible as you intend to, maybe it could work if you turn it into a @staticmethod first if that would be supported by jitclass (but that also defeats the purpose probably).

Can you compile your method as just a function right now? That already shouldn’t work. A guvectorize function takes the return value as an input, and assigns it instead of returning it. So it should look more as something like this:

from numba import guvectorize

@guvectorize(["void(f8[:], f8[:], f8[:])"], '(n),(n)->(n)')
def bar(a, b, result):
    result[:] = a+b

The specific error you’re seeing is because the self argument is not accounted for in the signature. But adding it probably won’t work due to the type being a jitclass.

It’s currently also not possible to call a guvectorize function from another njit function, it always has the be on the “outside”, at the interface with Python itself.