- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在寻找一种将 JIT 用于 python 类构造函数的方法,如下所示:
import numpy as np
from numbapro import jit, autojit
from time import time
class Test(object):
@jit((float, float, float), target="cpu")
def __init__(self, x, y, z):
self._x = x
self._y = y
self._z = z
@autojit
def runTest(self):
N = 1000000
self._z = 0
for i in xrange(N):
self._z = self._z + np.sin(i)
return self._z
if __name__ == '__main__':
a = Test(4,5,6)
start_time = time()
z = a.runTest()
end_time = time() # Get the CPU end time
print("Math Time: {0} s".format(end_time - start_time))
print z
但是,好像我必须给self
一个类型,我不知道如何实现。
也许有人知道如何解决这个问题?
提前致谢
安迪
最佳答案
numba 从 0.12 版开始不再支持“jitting”类:here is the Github issue .曾经有 support for classes in Numba ,称为 'extension types' ,但现在所有相关示例都不起作用,给出: TypeError: 'NotImplementedType' object is not callable
如果使用当前版本 (0.17) 执行。
因此,我强烈建议您将 runTest
功能移动到它自己的函数中,并且您使用 a tuple或 a numpy array将数据传递给该函数,因为支持这些机制。否则,您将不得不使用旧版本的 numba。
class Test(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
@jit(float(float))
def runTest(z):
N = 1000000
z = 0
for i in xrange(N):
z = z + np.sin(i)
return z
if __name__ == '__main__':
a = Test(4,5,6)
start_time = time()
z = runTest(a.z)
end_time = time() # Get the CPU end time
print("Math Time: {0} s".format(end_time - start_time))
print z
关于python - NumbaPro JIT 类构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29080082/
我正在比较几个 Python 模块/扩展或方法来实现以下目标: import numpy as np def fdtd(input_grid, steps): grid = input_gri
我正在寻找一种将 JIT 用于 python 类构造函数的方法,如下所示: import numpy as np from numbapro import jit, autojit from time
import numpy import numpy as np from numbapro import cuda @cuda.autojit def foo(aryA, aryB,out):
谁能向我解释一下为什么每次我运行这段代码时我的电脑都会死机? from numbapro import cuda import numpy as np from timeit import defau
我正在尝试运行以下程序: import numpy as np from timeit import default_timer as timer from numbapro import vecto
我正在尝试使用作业设置 3D 循环 C(i,j,k) = A(i,j,k) + B(i,j,k) 在我的 GPU 上使用 Python。这是我的 GPU: http://www.geforce.co
我正在尝试使用 NumbaPro 的 cuda 扩展来乘以大型数组矩阵。最后我想要的是将大小为 NxN 的矩阵乘以一个对角矩阵,该矩阵将作为一维矩阵输入(因此,我发现 a.dot(numpy.diag
总体目标是使用NumbaPro在 GPU 上运行某些功能(在 OSX 10.8.3 上)。 在开始之前,我只是想把一切都设置好。根据this page我安装了 CUDA,注册为 CUDA 开发人员,下
我正在使用 Python/NumbaPro 在 Windows 机器上使用我的 CUDA 兼容 GPU。我使用 Cygwin 作为 shell,并且在 cygwin 控制台中可以毫无问题地找到我的 C
我是 CUDA 的新手,我想知道是否 PyCUDA (free)或 NumbaPro CUDA Python (不是免费的)对我来说更好(假设图书馆费用不是问题)。 两者似乎都要求您使用各自的 Pyt
我想使用 Numbapro API 在 python 中执行 CUDA 内核。我有这段代码: import math import numpy from numbapro import jit, cu
我是一名优秀的程序员,十分优秀!