Numpy attributes not recognized in Numba

0 views
Skip to first unread message

Kien

unread,
May 2, 2018, 8:57:03 AM5/2/18
to Numba Public Discussion - Public
Hi all,

I am trying to implement numba for GPU computing and have encountered error with using numpy within a vectorize function definition (Code is attached below). There are two numpy functions: where() and shape() - both of those return error like: "Unknown attribute ' where/shape' of type Module(<module 'numpy' from 'C:\\Users\\Kien\\AppData\\Local\\conda\\conda\\envs\\mypy35\\lib\\site-packages\\numpy\\__init__.py'>)

I can run np.where() outside of the def without errors.

numba ver is 0.38.0
numpy ver is 1.14.2

Apparently, np.where() is supported by numba 0.38.0 so it is really confused. I have searched the whole Internet but could find any solution, hence this post.

Really appreciate any help!

Original code:
import numpy as np
import numba
from numba import vectorize, float64, int16

@vectorize(["int16(float64[:,:],float64[:,:],int16)"], target = 'cuda')
def expand_masking(c_Tb,c_flag,Tb_thres):
    idx
= np.where(c_flag==1)
    stop_flag
= 1

   
for i in range(0,np.shape(idx)[1]-1):
        idx_y
= idx[0][i]
        idx_x
= idx[1][i]
        c_flag
[idx_y,idx_x] = 2
       
for jy in range (0,5):
           
for jx in range (0,5):
                idx_yj
= idx_y + jy
                idx_xj
= idx_x + jx
               
if (idx_yj>=250 and idx_yj<851 and idx_xj>=250 and idx_xj<=851 and (c_Tb[idx_yj,idx_xj]<=Tb_thres) and c_flag[idx_yj,idx_xj]==0):
                        c_flag
[idx_yj,idx_xj]=1
                        stop_flag
= 0  
                idx_yj
= idx_y + jy
                idx_xj
= idx_x - jx
               
if (idx_yj>=250 and idx_yj<851 and idx_xj>=250 and idx_xj<=851 and (c_Tb[idx_yj,idx_xj]<=Tb_thres) and c_flag[idx_yj,idx_xj]==0):
                        c_flag
[idx_yj,idx_xj]=1
                        stop_flag
= 0
                idx_yj
= idx_y - jy
                idx_xj
= idx_x + jx
               
if (idx_yj>=250 and idx_yj<851 and idx_xj>=250 and idx_xj<=851 and (c_Tb[idx_yj,idx_xj]<=Tb_thres) and c_flag[idx_yj,idx_xj]==0):
                        c_flag
[idx_yj,idx_xj]=1
                        stop_flag
= 0  
                idx_yj
= idx_y - jy
                idx_xj
= idx_x - jx
               
if (idx_yj>=250 and idx_yj<851 and idx_xj>=250 and idx_xj<=851 and (c_Tb[idx_yj,idx_xj]<=Tb_thres) and c_flag[idx_yj,idx_xj]==0):
                        c_flag
[idx_yj,idx_xj]=1
                        stop_flag
= 0
   
return stop_flag

Siu Kwan Lam

unread,
May 2, 2018, 11:33:09 AM5/2/18
to numba...@continuum.io
The `@vectorize` can only handle scalar inputs.  Your function requires array inputs.  You have to use `@guvectorize`.  As for `np.where`, it is not supported on the CUDA target because it requires dynamic memory allocation as such it is not efficient on the GPU.  

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/1718639d-cbaf-408c-bddd-6249ab19ae5f%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
--
Siu Kwan Lam
Software Engineer
Anaconda, Inc
Reply all
Reply to author
Forward
0 new messages