matheus__serpa

Untitled

Feb 7th, 2021
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import numpy as np
  2. import numba
  3. from numba import cuda
  4.  
  5. @numba.jit(nopython=True)
  6. def compute_bin(x, n, xmin, xmax):
  7.     if x == xmax:
  8.         return n - 1
  9.  
  10.     bin = n * (x - xmin) / (xmax - xmin)
  11.  
  12.     if bin < 0 or bin >= n:
  13.         return None
  14.     else:
  15.         return bin
  16.  
  17. @cuda.jit
  18. def histogram(x, xmin, xmax, saida_hist):
  19.     nbins = saida_hist.shape[0]
  20.     largura_bin = (xmax - xmin) / nbins
  21.  
  22.     inicio = cuda.grid(1)
  23.     salto = cuda.gridsize(1)
  24.  
  25.     for i in range(inicio, x.shape[0], salto):
  26.         numero_bin = compute_bin(x[i], nbins, xmin, xmax)
  27.  
  28.         if numero_bin >= 0 and numero_bin < saida_hist.shape[0]:
  29.             cuda.atomic.add(saida_hist, numero_bin, 1)
Advertisement
Add Comment
Please, Sign In to add comment