Domanda

I am using Numba with Anaconda and wondering why

@jit(argtypes=[int16[:], int16[:]])
def index(ic, nc):
    return ic[0] + nc[0] * (ic[1] + nc[1] * ic[2])

does not work:

TypeError: 'type' object has no attribute '__getitem__'

But if I use @autojit instead of @jit(..) everything is fine.

È stato utile?

Soluzione

This is slightly confusing from reading the Numba examples, but you actually need to import int16 from the numba namespace.

The error you are seeing is consistent with importing int16 from NumPy. So if at the top of your file, your code looks like:

from numba import *
from numpy import *

Then you'll accidentally override int16 with the NumPy definition of it. There are two fixes. First, you could just swap the order of your imports:

from numpy import *
from numba import *

Or, more correctly, you could import the namespaces without the * and refer explicitly to what you need:

import numba as nb

@nb.jit(argtypes=[nb.int16[:], nb.int16[:]])
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top