matheus__serpa icon

Untitled

matheus__serpa | PRO | 02/08/21 12:08:22 AM UTC | 0 ⭐ | 1070 👁️ | Never ⏰ | []
Python |

690 B

|

None

|

0 👍

/

0 👎

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