numba

Custom reduction on GPU vs CPU yield different result

ε祈祈猫儿з 提交于 2021-02-20 03:43:34
问题 Why am I seeing different result on GPU compare to sequential CPU? import numpy from numba import cuda from functools import reduce A = (numpy.arange(100, dtype=numpy.float64)) + 1 cuda.reduce(lambda a, b: a + b * 20)(A) # result 12952749821.0 reduce(lambda a, b: a + b * 20, A) # result 100981.0 import numba numba.__version__ # '0.34.0+5.g1762237' Similar behavior happens when using Java Stream API to parallelize reduction on CPU: int n = 10; float inputArray[] = new float[n]; ArrayList<Float

Custom reduction on GPU vs CPU yield different result

送分小仙女□ 提交于 2021-02-20 03:42:07
问题 Why am I seeing different result on GPU compare to sequential CPU? import numpy from numba import cuda from functools import reduce A = (numpy.arange(100, dtype=numpy.float64)) + 1 cuda.reduce(lambda a, b: a + b * 20)(A) # result 12952749821.0 reduce(lambda a, b: a + b * 20, A) # result 100981.0 import numba numba.__version__ # '0.34.0+5.g1762237' Similar behavior happens when using Java Stream API to parallelize reduction on CPU: int n = 10; float inputArray[] = new float[n]; ArrayList<Float

llvmlite / numba compile: g++: error: unrecognized command line option ‘-Wcovered-switch-default’

家住魔仙堡 提交于 2021-02-19 06:22:05
问题 Trying to compile llvmlite or numba from https://github.com/numba I am getting g++: error: unrecognized command line option ‘-Wcovered-switch-default’ any help on how to fix this would be most appreciated. - mark 回答1: See https://github.com/numba/numba/wiki/Build-0.33-on-ubuntu-16.04 for a solution: basically make sure to the use the llvm that comes with the distribution: apt-get install llvm-3.9 export LLVM_CONFIG=$(which llvm-config-3.9) => will work ok Why? its beause the llvm that you can

numba cuda does not produce correct result with += (gpu reduction needed?)

白昼怎懂夜的黑 提交于 2021-02-18 19:38:17
问题 I am using numba cuda to calculate a function. The code is simply to add up all the values into one result, but numba cuda gives me a different result from numpy. numba code import math def numba_example(number_of_maximum_loop,gs,ts,bs): from numba import cuda result = cuda.device_array([3,]) @cuda.jit(device=True) def BesselJ0(x): return math.sqrt(2/math.pi/x) @cuda.jit def cuda_kernel(number_of_maximum_loop,result,gs,ts,bs): i = cuda.grid(1) if i < number_of_maximum_loop: result[0] +=

numba cuda does not produce correct result with += (gpu reduction needed?)

喜你入骨 提交于 2021-02-18 19:36:40
问题 I am using numba cuda to calculate a function. The code is simply to add up all the values into one result, but numba cuda gives me a different result from numpy. numba code import math def numba_example(number_of_maximum_loop,gs,ts,bs): from numba import cuda result = cuda.device_array([3,]) @cuda.jit(device=True) def BesselJ0(x): return math.sqrt(2/math.pi/x) @cuda.jit def cuda_kernel(number_of_maximum_loop,result,gs,ts,bs): i = cuda.grid(1) if i < number_of_maximum_loop: result[0] +=

使用requests爬取拉勾网python职位数据

痴心易碎 提交于 2021-02-14 08:00:34
爬虫目的 本文想通过爬取 拉勾网 Python相关岗位数据,简单梳理 Requests 和 xpath 的使用方法。 代码部分并没有做封装,数据请求也比较简单,所以该项目只是为了熟悉requests爬虫的基本原理,无法用于稳定的爬虫项目。 爬虫工具 这次使用 Requests 库发送http请求,然后用 lxml.etree 解析HTML文档对象,并使用 xpath 提取职位信息。 Requests简介 Requests是一款目前非常流行的http请求库,使用python编写,能非常方便的对网页Requests进行爬取。 官网里介绍说:Requests is an elegant and simple HTTP library for Python, built for human beings. Requests优雅、简易,专为人类打造! 总而言之,Requests用起来简单顺手。 Requests库可以使用 pip 或者 conda 安装,本文python环境为py3.6。 试试对百度首页进行数据请求: # 导入requests模块 import requests<br> # 发出http请求 re = requests.get( "https://www.baidu.com/" ) # 查看响应状态 print(re.status_code) # 查看url print(re

subtract 1 from next cumsum if current cumsum more than a particular value - pandas or numpy

给你一囗甜甜゛ 提交于 2021-02-11 05:07:38
问题 I have a data frame as shown below B_ID Session no_show cumulative_no_show 1 s1 0.4 0.4 2 s1 0.6 1.0 3 s1 0.2 1.2 4 s1 0.1 1.3 5 s1 0.4 1.7 6 s1 0.2 1.9 7 s1 0.3 2.2 10 s2 0.3 0.3 11 s2 0.4 0.7 12 s2 0.3 1.0 13 s2 0.6 1.6 14 s2 0.2 1.8 15 s2 0.5 2.3 where cumulative_no_show is the cumulative sum of no_show. From the above I would like to create a new column called u_no_show based on below condition. Whenever cumulative_no_show >= 0.8, then subtract 1 from next cumulative_no_show. and so on.

subtract 1 from next cumsum if current cumsum more than a particular value - pandas or numpy

梦想的初衷 提交于 2021-02-11 05:07:18
问题 I have a data frame as shown below B_ID Session no_show cumulative_no_show 1 s1 0.4 0.4 2 s1 0.6 1.0 3 s1 0.2 1.2 4 s1 0.1 1.3 5 s1 0.4 1.7 6 s1 0.2 1.9 7 s1 0.3 2.2 10 s2 0.3 0.3 11 s2 0.4 0.7 12 s2 0.3 1.0 13 s2 0.6 1.6 14 s2 0.2 1.8 15 s2 0.5 2.3 where cumulative_no_show is the cumulative sum of no_show. From the above I would like to create a new column called u_no_show based on below condition. Whenever cumulative_no_show >= 0.8, then subtract 1 from next cumulative_no_show. and so on.

How to speed up the following code using numba?

随声附和 提交于 2021-02-10 23:38:52
问题 I am doing a molecular dynamics simulation. It consists of numerical integration, many for loops, manipulating large NumPy arrays. I have tried to use NumPy function and arrays wherever possible. But the code is still too slow. I thought of using numba jit as a speedup. But it always throws an error message. Here is the code. # -*- coding: utf-8 -*- """ Created on Sat Mar 28 12:10:42 2020 @author: Sandipan """ import numpy as np import matplotlib.pyplot as plt from numba import jit import os

How call a `@guvectorize` inside a `@guvectorize` in numba?

人走茶凉 提交于 2021-02-10 12:58:32
问题 I'm trying to call a @guvectorize inside a @guvectorize but I have an error saying : Untyped global name 'regNL_nb': cannot determine Numba type of <class 'numpy.ufunc'> File "di.py", line 12: def H2Delay_nb(S1, S2, R2): H1 = regNL_nb(S1, S2) ^ here is an MRE: import numpy as np from numba import guvectorize, float64, int64, njit, cuda, jit @guvectorize(["float64[:], float64[:], float64[:]"], '(n),(n)->(n)') def regNL_nb(S1, S2, h2): for i in range(len(S1)): h2[i] = S1[i] + S2[i] @guvectorize