Find numpy.int_ in array of int_s using numba

前提是你 提交于 2019-12-11 03:56:12

问题


I am using numba (0.10.2-5-gda3e2bb-dirty) to speed up my code. Now I am trying the following:

from numba import void, int_, double, jit
import numpy as np

@jit
class bla(object)

    @void
    def my_fun
    k = np.int_(1)
    f = np.int_(np.array([1, 2 , 3, 4, 5]))
    if k in f:
        do something

However numba appears to choke on the in command. If I type something like

if k == 1:

everything is fine. However with the in command numba won't compile. Any thoughts?

Btw: I am running python 2.7 and

numpy.version

returns

numpy-1.7.1-py2.7-linux-i686.egg

Thanks in advance!

Nick


回答1:


There are a number of basic issues with your code syntax (indentation, missing parentheses, etc.), but if I re-write it as follows, I an error message that in type comparisons are not implemented yet:

NumbaError: (see below)
--------------------- Numba Encountered Errors or Warnings ---------------------
Error <class '_ast.In'> comparisons not yet implemented
--------------------------------------------------------------------------------

import numpy as np
from numba import void, int_, double, jit

@jit
class bla(object):
    @void()
    def __init__(self):
        self.x = 1

    @void()
    def my_fun(self):
        self.x = 1
        k = np.int_(1)
        f = np.int_(np.array([1, 2 , 3, 4, 5]))
        if k in f:
            print 'aaa'

I had to throw in the self.x lines because numba seems to fail on compile with unused variables, including self.



来源:https://stackoverflow.com/questions/19526791/find-numpy-int-in-array-of-int-s-using-numba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!