Question

I want to learn to use numba. Unfortunatly I am finding it a bit difficult to learn numba from the documentation. So I have to try to ask you guys. I want to pass a function f as an argument to a constructor. However I try, I get all sorts of errors. What should I do?

Here's my code:

def f(x):
    # return some mathematical expression

f_numba = jit(double(double))(f)

@autojit
class name:
    def __init__(self, f)
        self.f = f

    @double(double)
    def __call__(self, x)
        return self.f(x)

funct = name(f_numba)
a = funct(5)

Here are some of the error I am getting ( I am sorry that the indentation and line breaks are not preserved. I tried a few different things, but in all cases the formating is lost). I am posting this because I was asked to in the comments. But the kind of errors I am getting varies with the exact implementation:

Traceback (most recent call last): File "/home/marius/dev/python/inf1100/test_ODE.py", line 7, in from DE import * File "/home/marius/dev/python/inf1100/DE.py", line 3, in @autojit File "/home/marius/anaconda/lib/python2.7/site-packages/numba/decorators.py", line 183, in autojit nopython=nopython, locals=locals, **kwargs)(func) File "/home/marius/anaconda/lib/python2.7/site-packages/numba/decorators.py", line 165, in _autojit_decorator numba_func = wrapper(f, compilerimpl, cache) File "/home/marius/anaconda/lib/python2.7/site-packages/numba/exttypes/autojitclass.py", line 360, in autojit_class_wrapper py_class = autojitmeta.create_unspecialized_cls(py_class, class_specializer) File "/home/marius/anaconda/lib/python2.7/site-packages/numba/exttypes/autojitmeta.py", line 22, in create_unspecialized_cls class AutojitMeta(type(py_class)): TypeError: Error when calling the metaclass bases type 'classobj' is not an acceptable base type

Was it helpful?

Solution

Sounds like you should be using a new-style class instead.

@autojit
class name(object):
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top