import numpy as np import numba from numba import cuda @numba.jit(nopython=True) def compute_bin(x, n, xmin, xmax): if x == xmax: return n - 1 bin = n * (x - xmin) / (xmax - xmin) if bin < 0 or bin >= n: return None else: return bin @cuda.jit def histogram(x, xmin, xmax, saida_hist): nbins = saida_hist.shape[0] largura_bin = (xmax - xmin) / nbins inicio = cuda.grid(1) salto = cuda.gridsize(1) for i in range(inicio, x.shape[0], salto): numero_bin = compute_bin(x[i], nbins, xmin, xmax) if numero_bin >= 0 and numero_bin < saida_hist.shape[0]: cuda.atomic.add(saida_hist, numero_bin, 1)
Comments