Getitem error number with numba function

Hi Everyone,

I am receiving a getitem Typing error and I am having trouble deciphering it. Does anyone have any suggestions for what I can change? I’m wondering if its the concatenate or argsort but it could be something else.

@numba.jit(nopython=True, parallel=True)
def QuadDs(y):
#output = np.zeros_like(result)
for m in numba.prange(y.shape[2]):
for j in numba.prange(y.shape[0]):
set1 = np.zeros(((y.shape[1]),3))
q = y[j,:,m]
for i in numba.prange(len(q)):
set1[i,0] = q[i]

        for i in numba.prange(set1.shape[0]):
            if (set1[i,0] == -1): ### Losers
                set1[i,2] = i
            if (set1[i,0] == 1):  ### Winners
                set1[i,1] = i
        
        setUp = set1[:,[0,1]][set1[:,1] != 0]
        setDown = set1[:,[0,2]][set1[:,2] != 0]           
        x = np.concatenate((setUp,setDown))            
        x2 = x[x[:,1].argsort()]                    
        x3 = np.zeros((len(x2),1))
        x4 = np.append(x2, x3, 1)
        c2 = x4
        u = 0
        d = 0
        for i in numba.prange(c2.shape[0]):
            if (i == 0):
                if (c2[i,0] == 1):
                    c2[i,2] = 1
                    u = 1
                if (c2[i,0] == -1):
                    c2[i,2] = -1       
                    d = 1
            if (i!=0):        
                if ((c2[i,0] == 1) and (u != 0)):
                    d = 0
                    u += 1
                    if (c2[i,1]-c2[i-1,1] != 1):
                        c2[i-1,2] = u-1
                        u = 1               
                if ((c2[i,0] == 1) and (d != 0)):
                    c2[i-1,2] = -d
                    u = 1
                    d = 0
                if ((c2[i,0] == -1) and (d != 0)):
                    u = 0
                    d += 1
                    if (c2[i,1]-c2[i-1,1] != 1):
                        c2[i-1,2] = -d+1
                        d = 1               
                if ((c2[i,0] == -1) and (u != 0)):
                    c2[i-1,2] = u
                    u = 0
                    d = 1
            if (i == 1):
                if (c2[i-1,0] == c2[i,0]):
                    c2[0,2] = 0
            if (i == c2.shape[0]-1):
                c2[i,2] = u - d                   
        u = 0
        d = 0

QuadDs(result2) #result two is a 3d numpy array

getitem(array(float64, 2d, C), Tuple(slice<a:b>, list(int64)<iv=[0, 1]>))

There are 22 candidate implementations:
- Of which 20 did not match due to:
Overload of function ‘getitem’: File: : Line N/A.
With argument(s): ‘(array(float64, 2d, C), Tuple(slice<a:b>, list(int64)<iv=None>))’:
No match.
- Of which 1 did not match due to:
Overload in function ‘GetItemBuffer.generic’: File: numba/core/typing/arraydecl.py: Line 209.
With argument(s): ‘(array(float64, 2d, C), Tuple(slice<a:b>, list(int64)<iv=None>))’:
Rejected as the implementation raised a specific error:
NumbaTypeError: Unsupported array index type list(int64)<iv=None> in Tuple(slice<a:b>, list(int64)<iv=None>)
raised from /home/calc1/anaconda3/envs/python38/lib/python3.8/site-packages/numba/core/typing/arraydecl.py:102
- Of which 1 did not match due to:
Overload in function ‘GetItemBuffer.generic’: File: numba/core/typing/arraydecl.py: Line 209.
With argument(s): ‘(array(float64, 2d, C), Tuple(slice<a:b>, list(int64)<iv=[0, 1]>))’:
Rejected as the implementation raised a specific error:
NumbaTypeError: Unsupported array index type list(int64)<iv=[0, 1]> in Tuple(slice<a:b>, list(int64)<iv=[0, 1]>)
raised from /home/calc1/anaconda3/envs/python38/lib/python3.8/site-packages/numba/core/typing/arraydecl.py:102

During: typing of intrinsic-call at /tmp/ipykernel_12611/2696172255.py (18)
During: typing of static-get-item at /tmp/ipykernel_12611/2696172255.py (18)

Thanks

Can you supply a complete runnable example that demonstrates the problem?

If you add the following before the numba loop then feed inputA into the function it will generate the error. Thanks

import numba
import numpy as np
inputA = np.random.randn(8,10000,9)

import numba
import numpy as np
inputA = np.random.randn(8,10000,9)

@numba.jit(nopython=True, parallel=True)
def QuadDs(y): 
    for m in numba.prange(y.shape[2]):    
        for j in numba.prange(y.shape[0]):
            set1 = np.zeros(((y.shape[1]),3))     
            q = y[j,:,m]
            for i in numba.prange(len(q)):
                set1[i,0] = q[i]
           
            for i in numba.prange(set1.shape[0]):
                if (set1[i,0] == -1): 
                    set1[i,2] = i
                if (set1[i,0] == 1):  
                    set1[i,1] = i
            
            setUp = set1[:,[0,1]][set1[:,1] != 0]
            setDown = set1[:,[0,2]][set1[:,2] != 0]           
            x = np.concatenate((setUp,setDown))            
            x2 = x[x[:,1].argsort()]                    
            x3 = np.zeros((len(x2),1))
            x4 = np.append(x2, x3, 1)
            c2 = x4
            u = 0
            d = 0
            #c2.shape
            for i in numba.prange(c2.shape[0]):
                if (i == 0):
                    if (c2[i,0] == 1):
                        c2[i,2] = 1
                        u = 1
                    if (c2[i,0] == -1):
                        c2[i,2] = -1       
                        d = 1
                if (i!=0):        
                    if ((c2[i,0] == 1) and (u != 0)):
                        d = 0
                        u += 1
                        if (c2[i,1]-c2[i-1,1] != 1):
                            c2[i-1,2] = u-1
                            u = 1               
                    if ((c2[i,0] == 1) and (d != 0)):
                        c2[i-1,2] = -d
                        u = 1
                        d = 0
                    if ((c2[i,0] == -1) and (d != 0)):
                        u = 0
                        d += 1
                        if (c2[i,1]-c2[i-1,1] != 1):
                            c2[i-1,2] = -d+1
                            d = 1               
                    if ((c2[i,0] == -1) and (u != 0)):
                        c2[i-1,2] = u
                        u = 0
                        d = 1
                if (i == 1):
                    if (c2[i-1,0] == c2[i,0]):
                        c2[0,2] = 0
                if (i == c2.shape[0]-1):
                    c2[i,2] = u - d                   
            u = 0
            d = 0
        
if __name__ == '__main__':
       QuadDs(inputA)

The error is talking about slicing, and the numba-supported numpy page suggests using an array to index. I added array declarations outside the function, like

setUpIndex = np.asarray([0, 1], dtype=np.int64)
setDownIndex = np.asarray([0, 2], dtype=np.int64)

and adjusted accordingly inside the function

setUp = set1[:, setUpIndex][set1[:, 1] != 0]
setDown = set1[:, setDownIndex][set1[:,2] != 0]

And the program ran through. I did not check whether or not the result matched the non-jitted form.

1 Like

Thank you for your functional solution.