#NEWLINE# def _compute_hist( tensor , hist , nbins = 64 , offset = ( - 48 ) ) : #NEWLINE# #INDENT# '\n    Helper function to compute the histogram of a tensor.\n\n    Arguments:\n        tensor (GPUTensor): the tensor to compute the histogram over\n        hist (gpu pointer): the gpu memory region to store the 64 bin hist in.\n        nbins (int, optional): number of histogram bins, each representing a power of 2\n                               (default 64)\n        offset (int, optional): offset the value of a bin from its idx as a power of two\n                                (default offset=-48 means bin 0 represents 2**-48)\n    ' #NEWLINE# threads = 128 #NEWLINE# assert ( ( nbins < threads ) and ( nbins > 0 ) ) #NEWLINE# size = tensor . size #NEWLINE# strides = ( np . floor ( ( np . sqrt ( size ) / threads ) ) * threads ) #NEWLINE# if ( strides < threads ) : #NEWLINE# #INDENT# strides = max ( ( ( size / threads ) * threads ) , threads ) #NEWLINE# #UNINDENT# blocks = max ( 1 , ( int ( strides ) // threads ) ) #NEWLINE# kernel_args = [ hist , tensor . gpudata , strides , size ] #NEWLINE# hist_kern = _get_hist_kernel ( tensor . dtype . str , nbins , offset ) #NEWLINE# hist_kern . prepared_call ( ( blocks , 1 , 1 ) , ( threads , 1 , 1 ) , * kernel_args )