Problem with reflected list signature in numba

Viewed 1333

I'm trying to use Ahead-of-Time compilation on one of my functions and because of that I need to provide the signatures for the function. When I use numba.typeof() I get back reflected list(array(float64, 2d, A)) for one of my variables. I've looked at this thread Basic trouble with Python lists in Numba; what's going on? to try and figure out the signature, but I've been running into errors.

Before trying to get AOT compilation to work I'm just trying to get @njit to work with signatures.

I've tried:

@njit(float64[:,:,:](int32, list(float64), float64[:,:,:]), reflected=True)

How can I fix my signature so it works? Thanks

1 Answers

You need to specify the signature of your list correctly. This means solving a few issues in your code:

  • reflected=True must be an argument of your call of the List type class
  • I don't know how and where you import list. If you did not import it, it is not a numba type. If you did import something as list, you overwrote the python builtins module list. You should NEVER do this. So instead of list I'd write nb.types.List(...), supposing that you import numba with import numba as nb. If you imported numba with from numba import *: This is another thing you should avoid at all costs.
  • the float64 type which is stored in your list needs to be specified more precisely. You have an array of type array(float64, 2d, A) in your reflected list. This means your list signature needs to contain exactly this array type. In this case this will look like: nb.float64[:, :]. For other memory layouts like C- or F-, take a look at this post.

So your resulting signature will look like this:

@nb.njit(nb.float64[:, :, :](nb.int32, nb.types.List(nb.float64[:, :], reflected=True), nb.float64[:, :, :]))

Again assuming that you import numba with import numba as nb and that your array is of the type array(float64, 2d, A).

Related