def hist_comp(arry, hist, result, index):
# We have N threads per block
# And We have one block only
x = cuda.grid(1)
R = cuda.shared.array(9, dtype=float64)
# No of featureVectors
# array.shape[0] == 9*34
A = cuda.shared.array(shape=(9,34), dtype=float64)
# Vecture To Compair
# hist.shape[0] == BIN_COUNT == 34 ?
B = cuda.shared.array(34, dtype=float64)
for i in range(BIN_COUNT):
B[i] = hist[i]
A[x] = arry[x]
cuda.syncthreads()
# Do Actual Calculations.
# i.e: kullback_leibler_divergence
Sum = 0.00
for i in range(BIN_COUNT):
a = B[i]
b = A[x][i]
Sum += (a * (math.log(a/b) / math.log(2.0)))
# R Contains the KL-Divergences
R[x] = Sum
cuda.syncthreads()
# These Should be Shared Variables.
Min = cuda.shared.array(1,dtype=float32)
mIndex = cuda.shared.array(1,dtype=int8)
Min = 0.0000000000
mIndex = 0
if x == 0:
Min = R[x]
mIndex = x
cuda.syncthreads()
if R[x] <= Min:
Min = R[x]
mIndex = x
cuda.syncthreads()
if x == mIndex :
index=mIndex
评论列表
文章目录