numba

Python numba / llvmlite on Debian 8 - i can't build llvmlite

允我心安 提交于 2020-01-14 22:48:18
问题 Im trying to install numba on a Debian 8 system as described here: http://llvmlite.pydata.org/en/latest/install/index.html (secion 2.2.3). I have installed LLVM 3.5 and it seems to find it but i keep getting errors when building llvmlite with setup.py: # python setup.py build Here is the complete output: running build got version from VCS {'version': '0.9.0.dev+7.gf5a7007.dirty', 'full': 'f5a70072ce0e7f5e432d6645056a60b00f957c66.dirty'} running build_ext /usr/bin/python ffi/build.py LLVM

numpy faster than numba and cython , how to improve numba code

我是研究僧i 提交于 2020-01-14 10:06:02
问题 I have a simple example here to help me understand using numba and cython. I am `new to both numba and cython. I've tried my best with to incorporate all the tricks to make numba fast and to some extent, the same for cython but my numpy code is almost 2x faster than numba (for float64), more than 2x faster if using float32. Not sure what I am missing here. I was thinking perhaps the problem isn't coding anymore but more about compiler and such which I'm not very familiar with. I've gone thru

numpy faster than numba and cython , how to improve numba code

China☆狼群 提交于 2020-01-14 10:03:27
问题 I have a simple example here to help me understand using numba and cython. I am `new to both numba and cython. I've tried my best with to incorporate all the tricks to make numba fast and to some extent, the same for cython but my numpy code is almost 2x faster than numba (for float64), more than 2x faster if using float32. Not sure what I am missing here. I was thinking perhaps the problem isn't coding anymore but more about compiler and such which I'm not very familiar with. I've gone thru

numba 6.@jitclass

ⅰ亾dé卋堺 提交于 2020-01-13 21:00:10
-------------------------------------------------------------------------------------------------------------- @jitclass #编译Python类,为类生成代码,并指定每个字段的类型. -------------------------------------------------------------------------------------------------------------- @jitclass #编译Python类,为类生成代码,并指定每个字段的类型. from numba import jitclass from numba import int32, float32 spec = [ ('value', int32), ('array', float32[:]), ] @jitclass(spec) class Bag(object): def __init__(self, value): #必须定义,否则包含垃圾数据 self.value = value self.array = np.zeros(value, dtype=np.float32) @property def size(self): #可定义方法和属性

numba 6.@jitclass

随声附和 提交于 2020-01-13 20:46:14
-------------------------------------------------------------------------------------------------------------- @jitclass #编译Python类,为类生成代码,并指定每个字段的类型. -------------------------------------------------------------------------------------------------------------- @jitclass #编译Python类,为类生成代码,并指定每个字段的类型. from numba import jitclass from numba import int32, float32 spec = [ ('value', int32), ('array', float32[:]), ] @jitclass(spec) class Bag(object): def __init__(self, value): #必须定义,否则包含垃圾数据 self.value = value self.array = np.zeros(value, dtype=np.float32) @property def size(self): #可定义方法和属性

numba 5.1.@cfunc

被刻印的时光 ゝ 提交于 2020-01-13 20:06:11
5.1.@cfunc # 创建C/C++回调函数;还公开了ctypes指向该回调的回调对象 5.1.@cfunc # 创建C/C++回调函数;还公开了ctypes指向该回调的回调对象 -------------------------------------------------------------------------------------------------------------- #实例1.1: from numba import cfunc @cfunc("float64(float64, float64)") def add(x, y): return x + y print(add.ctypes(4.0, 5.0)) # prints "9.0" -------------------------------------------------------------------------------------------------------------- #实例1.2: import numpy as np from numba import cfunc def fun(t): # 纯Python函数 return np.exp(-t) / t**2 nb_fun = cfunc("float64(float64)")(fun)#

How to determine if numba's prange actually works correctly?

て烟熏妆下的殇ゞ 提交于 2020-01-13 09:49:14
问题 In another Q+A (Can I perform dynamic cumsum of rows in pandas?) I made a comment regarding the correctness of using prange about this code (of this answer): from numba import njit, prange @njit def dynamic_cumsum(seq, index, max_value): cumsum = [] running = 0 for i in prange(len(seq)): if running > max_value: cumsum.append([index[i], running]) running = 0 running += seq[i] cumsum.append([index[-1], running]) return cumsum The comment was: I wouldn't recommend parallelizing a loop that isn't

Filtering a NumPy Array: what is the best approach?

拜拜、爱过 提交于 2020-01-13 05:19:05
问题 Suppose I have a NumPy array arr that I want to element-wise filter, e.g. I want to get only values below a certain threshold value k . There are a couple of methods, e.g.: Using generators: np.fromiter((x for x in arr if x < k), dtype=arr.dtype) Using boolean mask slicing: arr[arr < k] Using np.where() : arr[np.where(arr < k)] Using np.nonzero() : arr[np.nonzero(arr < k)] Using a Cython-based custom implementation(s) Using a Numba-based custom implementation(s) Which is the fastest? What

Improve performance of a for loop in Python (possibly with numpy or numba)

浪尽此生 提交于 2020-01-13 04:49:07
问题 I want to improve the performance of the for loop in this function. import numpy as np import random def play_game(row, n=1000000): """Play the game! This game is a kind of random walk. Arguments: row (int[]): row index to use in the p matrix for each step in the walk. Then length of this array is the same as n. n (int): number of steps in the random walk """ p = np.array([[ 0.499, 0.499, 0.499], [ 0.099, 0.749, 0.749]]) X0 = 100 Y0 = X0 % 3 X = np.zeros(n) tempX = X0 Y = Y0 for j in range(n)

Numba jit with scipy

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 03:22:08
问题 So I wanted to speed up a program I wrote with the help of numba jit . However jit seems to be not compatible with many scipy functions because they use try ... except ... structures that jit cannot handle (Am I right with this point?) A relatively simple solution I came up with is to copy the scipy source code I need and delete the try except parts (I already know that it will not run into errors so the try part will always work anyways) However I do not like this solution and I am not sure