本文介绍了使用numba在int_s数组中找到numpy.int_的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用numba(0.10.2-5-gda3e2bb-dirty)来加快我的代码的速度.现在,我尝试以下操作:

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

但是,numba似乎在in命令中令人窒息.如果我输入类似

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

if k == 1:

一切都很好.但是,使用in命令时,numba无法编译.有什么想法吗?

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

顺便说一句:我正在运行python 2.7和

Btw: I am running python 2.7 and

numpy.version

返回

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

提前谢谢!

尼克

推荐答案

您的代码语法有很多基本问题(缩进,缺少括号等),但是如果我按如下方式重写它, in类型比较尚未实现的错误消息:

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'

我不得不抛出self.x行,因为numba似乎无法使用未使用的变量(包括self)进行编译.

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

这篇关于使用numba在int_s数组中找到numpy.int_的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 07:29